version: 1.0.{build}

branches:
  only:
  - master
  - /\d*\.\d*\.\d*/
  # For testing:
  - /.*appveyor-build-branch.*/

environment:
  STACK_ROOT: C:\sr
  STACK_VERSION: 1.9.3
  # Override the temp directory to avoid sed escaping issues
  # See https://github.com/haskell/cabal/issues/5386
  TMP: c:\tmp
  LANG: en_US.UTF-8

  matrix:
    - STACK_YAML: stack.yaml
    - STACK_YAML: stack-lts-6.yaml

install:
  # http://help.appveyor.com/discussions/problems/6312-curl-command-not-found
  - set PATH=C:\Program Files\Git\mingw64\bin;%PATH%

  - curl --silent --show-error --output stack.zip --location "https://github.com/commercialhaskell/stack/releases/download/v%STACK_VERSION%/stack-%STACK_VERSION%-windows-x86_64.zip"
  - 7z x stack.zip stack.exe
  - stack setup > nul
  - git submodule update --init --recursive

cache:
  - '%STACK_ROOT% -> %STACK_YAML%, appveyor.yml'
  - '.stack-work -> %STACK_YAML%, appveyor.yml'
  - 'dhall/.stack-work -> %STACK_YAML%, appveyor.yml'
  - 'dhall-bash/.stack-work -> %STACK_YAML%, appveyor.yml'

for:
-
  matrix:
    except:
      - STACK_YAML: stack-lts-6.yaml

  build_script:
    - stack build
    - stack install --local-bin-path bin
    - if /I "%APPVEYOR_REPO_TAG%" EQU "true" (set DEPLOY_TAG=%APPVEYOR_REPO_TAG_NAME%-x86_64-windows.zip)
    - set DEPLOY_DIR=%APPVEYOR_BUILD_FOLDER%\bin
    - if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall.exe")
    - if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-json-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-to-json.exe")
    - if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-json-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-to-yaml.exe")
    - if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-json-%DEPLOY_TAG%" "%DEPLOY_DIR%\json-to-dhall.exe")
    - if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-bash-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-to-bash.exe")
    - if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-lsp-server-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-lsp-server.exe")
    - if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-yaml-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-to-yaml-ng.exe")
    - if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-yaml-%DEPLOY_TAG%" "%DEPLOY_DIR%\yaml-to-dhall.exe")

  test_script:
    # chcp 65001 (utf-8) needed to make doctest work
    - chcp 65001 && stack test dhall
    - stack test dhall-json
    - stack test dhall-yaml
    - stack test dhall-bash
    - stack test dhall-lsp-server
    - stack bench dhall --benchmark-arguments "--quick --min-duration=0 --include-first-iter"
    
-
  matrix:
    only:
      - STACK_YAML: stack-lts-6.yaml

  build_script:
    - stack build
    - stack install --local-bin-path bin

  test_script:
    # chcp 65001 (utf-8) needed to make doctest work
    - chcp 65001 && stack test dhall

artifacts:
  - path: bin\dhall-%DEPLOY_TAG%
    name: dhall
  - path: bin\dhall-json-%DEPLOY_TAG%
    name: dhall-json
  - path: bin\dhall-yaml-%DEPLOY_TAG%
    name: dhall-yaml
  - path: bin\dhall-bash-%DEPLOY_TAG%
    name: dhall-bash
  - path: bin\dhall-lsp-server-%DEPLOY_TAG%
    name: dhall-lsp-server

deploy:
  - provider: GitHub
    auth_token:
      secure: Gs/tiz6Jtg/Zjd4zGHDhuSv4Y9a+zJ574LWwzOe2bvZNGX/M8XupkxdGmBpDlnOf
    artifact: dhall, dhall-json, dhall-yaml, dhall-bash, dhall-lsp-server
    on:
      APPVEYOR_REPO_TAG: true
      STACK_YAML: stack.yaml
