sudo: required

language: generic

cache:
  directories:
  - $HOME/.ghc
  - $HOME/.cabal
  - $HOME/.stack
  - $TRAVIS_BUILD_DIR/.stack-work

matrix:
  include:
  # Build only on macOS
  - env: BUILD=stack
    compiler: ": #stack default osx"
    os: osx

# Build only master and release tags
branches:
  only:
  - master
  - /^\d+\.\d+\.\d+(\.\d+)?$/


before_install:
  # Using compiler above sets CC to an invalid value, so unset it
  - unset CC
  - CABALARGS=""
  - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$HOME/.local/bin:/opt/alex/$ALEXVER/bin:/opt/happy/$HAPPYVER/bin:$HOME/.cabal/bin:$PATH
  - | # Install stack
    mkdir -p ~/.local/bin
    travis_retry curl -L https://get.haskellstack.org/stable/osx-x86_64.tar.gz | tar xz --strip-components=1 --include '*/stack' -C ~/.local/bin
    # Use the more reliable S3 mirror of Hackage
    mkdir -p $HOME/.cabal
    echo 'remote-repo: hackage.haskell.org:http://hackage.fpcomplete.com/' > $HOME/.cabal/config
    echo 'remote-repo-cache: $HOME/.cabal/packages' >> $HOME/.cabal/config


install:
  - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
  - SAVED_OPTIONS=$(set +o)
  - set -ex
  - stack --no-terminal --install-ghc build --only-dependencies
  - eval "$SAVED_OPTIONS"


script:
  - export PATH="${PATH}:$(pwd)/bin"
  - stack build --copy-bins --local-bin-path ./bin
  - source .travis-functions.sh
  - tar -jcvf $(mk_release_name dhall) bin/dhall
  - tar -jcvf $(mk_release_name dhall-json) bin/dhall-to-json bin/dhall-to-yaml bin/json-to-dhall
  - tar -jcvf $(mk_release_name dhall-bash) bin/dhall-to-bash
  - tar -jcvf $(mk_release_name dhall-lsp-server) bin/dhall-lsp-server
  - tar -jcvf $(mk_release_name dhall-nix) bin/dhall-to-nix
  - tar -jcvf $(mk_release_name dhall-yaml) bin/dhall-to-yaml-ng bin/yaml-to-dhall
  - mkdir -p uploads
  - mv *.tar.bz2 uploads/


deploy:
  - provider: releases
    api_key: $GITHUB_OAUTH_TOKEN
    file_glob: true
    file: uploads/*
    skip_cleanup: true
    on:
      tags: true
    script:
      - echo 'done'
