language: nix

script:
- nix-build --argstr coq-version-or-url "$COQ" --extra-substituters https://coq.cachix.org --trusted-public-keys "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= coq.cachix.org-1:5QW/wwEnD+l2jvN6QRbRRsa4hBHG3QiQQ26cxu1F5tI="

matrix:
  include:

  # Test supported versions of Coq
  - env: COQ=https://github.com/coq/coq/tarball/master
  - env: COQ=8.9
  - env: COQ=8.8
  - env: COQ=8.7

  # Test opam package
  - language: minimal
    sudo: required
    services: docker
    env:
    - COQ_IMAGE=coqorg/coq:dev
    - CONTRIB_NAME=qarith-stern-brocot
    - NJOBS=2
    install: |
      # Prepare the COQ container
      docker pull ${COQ_IMAGE}
      docker run -d -i --init --name=COQ -v ${TRAVIS_BUILD_DIR}:/home/coq/${CONTRIB_NAME} -w /home/coq/${CONTRIB_NAME} ${COQ_IMAGE}
      docker exec COQ /bin/bash --login -c "
        # This bash script is double-quoted to interpolate Travis CI env vars:
        echo \"Build triggered by ${TRAVIS_EVENT_TYPE}\"
        export PS4='+ \e[33;1m(\$0 @ line \$LINENO) \$\e[0m '
        set -ex  # -e = exit on failure; -x = trace for debug
        opam update -y
        opam install -y -j ${NJOBS} --deps-only .
        opam config list
        opam repo list
        opam list
        "
    script:
    - echo -e "${ANSI_YELLOW}Building ${CONTRIB_NAME}...${ANSI_RESET}" && echo -en 'travis_fold:start:script\\r'
    - |
      docker exec COQ /bin/bash --login -c "
        export PS4='+ \e[33;1m(\$0 @ line \$LINENO) \$\e[0m '
        set -ex
        sudo chown -R coq:coq /home/coq/${CONTRIB_NAME}
        opam install -y -j ${NJOBS} .
        "
    - docker stop COQ  # optional
    - echo -en 'travis_fold:end:script\\r'
