environment:
  matrix:
  - MSYSTEM: MINGW64
    PATH: C:\Python36;C:\Python36\Scripts;C:\msys64\usr\bin;C:\msys64\mingw64\bin;C:\Windows\System32;C:\Windows;%PATH%
  - MSYSTEM: MINGW32
    PATH: C:\Python36;C:\Python36\Scripts;C:\msys64\usr\bin;C:\msys64\mingw32\bin;C:\Windows\System32;C:\Windows;%PATH%

clone_script:
  - bash -lc "git clone -q --branch=${APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH:-$APPVEYOR_REPO_BRANCH} https://github.com/${APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME:-$APPVEYOR_REPO_NAME}.git $APPVEYOR_BUILD_FOLDER"
  - bash -lc "cd $APPVEYOR_BUILD_FOLDER && git checkout -qf ${APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH:APPVEYOR_REPO_BRANCH}"
  - bash -lc "cd $APPVEYOR_BUILD_FOLDER && git submodule update --init --recursive"

install:
  # update msys2
  - C:\msys64\usr\bin\bash -lc "curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
  - C:\msys64\usr\bin\bash -lc "curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig"
  - C:\msys64\usr\bin\bash -lc "curl -O http://repo.msys2.org/msys/x86_64/bison-3.5.4-1-x86_64.pkg.tar.xz"
  - C:\msys64\usr\bin\bash -lc "curl -O http://repo.msys2.org/msys/x86_64/bison-3.5.4-1-x86_64.pkg.tar.xz.sig"
  - C:\msys64\usr\bin\bash -lc "curl -O http://repo.msys2.org/msys/x86_64/flex-2.6.4-1-x86_64.pkg.tar.xz"
  - C:\msys64\usr\bin\bash -lc "curl -O http://repo.msys2.org/msys/x86_64/flex-2.6.4-1-x86_64.pkg.tar.xz.sig"
  #- C:\msys64\usr\bin\bash -lc "curl -O http://repo.msys2.org/msys/x86_64/git-2.33.1-1-x86_64.pkg.tar.zst"
  - C:\msys64\usr\bin\bash -lc "pacman-key --verify msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig"
  - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
  - C:\msys64\usr\bin\bash -lc "pacman-key --verify bison-3.5.4-1-x86_64.pkg.tar.xz.sig"
  - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm bison-3.5.4-1-x86_64.pkg.tar.xz"
  - C:\msys64\usr\bin\bash -lc "pacman-key --verify flex-2.6.4-1-x86_64.pkg.tar.xz.sig"
  - C:\msys64\usr\bin\bash -lc "pacman -U --noconfirm flex-2.6.4-1-x86_64.pkg.tar.xz"
  - ps: Get-Process | Where-Object {$_.path -like 'C:\msys64*'} | Stop-Process
  #- C:\msys64\usr\bin\bash -lc "pacman --needed --noconfirm -Sy pacman-mirrors"
  #- C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Su"
  #- C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S autoconf automake bison flex git"
  - C:\msys64\usr\bin\bash -lc "pip3 install --upgrade pipenv"
  - C:\msys64\usr\bin\bash -lc "cd $APPVEYOR_BUILD_FOLDER/docs && pipenv sync"

build_script:
  - bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && autoreconf -i"
  - bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && ./configure --with-oniguruma=builtin --disable-shared --enable-static --enable-all-static"
  - bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && make"
  - bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && cat jq.1  | groff -mandoc -Thtml > jq.html"
  - 7z a jq-package.zip jq.1 jq.html jq.exe
  - bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && pwd && ls -la"
  - file jq.exe
  
test_script:
  # tests/optionaltest and tests/shtest fail on Windows; run them
  # anyways but ignore their failures.  Also, trace shtest.
  - bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && make -j3 SUBDIRS= 'TESTS=tests/mantest tests/jqtest tests/onigtest tests/base64test' check"
  - bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && make SUBDIRS= TESTS=tests/optionaltest check || true"
  - bash -lc "exec 0</dev/null && cd $APPVEYOR_BUILD_FOLDER && make SUBDIRS= TRACE_TESTS=1 TESTS=tests/shtest check || true"
      
artifacts:
  - path: jq-package.zip
    name: jq-package
    
  - path: jq.exe
    name: jq-exe
    
  - path: test-suite.log
    name: logs
    

on_failure:
  - cat config.log
  - cat test-suite.log
  - appveyor PushArtifact test-suite.log
  # also push the jq.exe so that someone can download it anyways...
  - appveyor PushArtifact jq-package.zip
    
