image: ralfjung/opam-ci:latest

stages:
  - build
  - deploy
  - build_more

variables:
  CPU_CORES: "9"

.template: &template
  stage: build
  tags:
  - fp-timing
  script:
  # prepare
  - . build/opam-ci.sh $OPAM_PINS
  - env | egrep '^(CI_BUILD_REF|CI_RUNNER)' > build-env.txt
  # build
  - 'time make -k -j$CPU_CORES TIMED=y 2>&1 | tee build-log.txt'
  - 'if fgrep Axiom build-log.txt >/dev/null; then exit 1; fi'
  - 'cat build-log.txt | egrep "[a-zA-Z0-9_/-]+ \((real|user): [0-9]" | tee build-time.txt'
  cache:
    key: "$CI_JOB_NAME"
    paths:
    - opamroot/
  only:
  - master
  - /^ci/

opam:
  stage: deploy
  script:
  # Send a trigger to the repository doing the work
  - curl --fail -X POST -F "token=$OPAM_UPDATE_SECRET" -F "ref=master" -F "variables[REPO]=$CI_PROJECT_URL.git" -F "variables[REF]=$CI_COMMIT_REF_NAME" -F "variables[SHA]=$CI_COMMIT_SHA" -F "variables[NAME]=$OPAM_PKG" https://gitlab.mpi-sws.org/api/v4/projects/581/trigger/pipeline
  variables:
    OPAM_PKG: "coq-stdpp"
  only:
  - master
  except:
  - triggers

build-coq.8.7.dev:
  <<: *template
  stage: build_more
  variables:
    OPAM_PINS: "coq version 8.7.dev"
  except:
  - triggers

build-coq.8.7.1:
  <<: *template
  variables:
    OPAM_PINS: "coq version 8.7.1"
  except:
  - triggers

build-coq.8.7.0:
  <<: *template
  stage: build_more
  variables:
    OPAM_PINS: "coq version 8.7.0"
  except:
  - triggers

build-coq.8.6.1:
  <<: *template
  variables:
    OPAM_PINS: "coq version 8.6.1"
  artifacts:
    paths:
    - build-time.txt
    - build-env.txt
  except:
  - triggers

build-coq.8.6:
  <<: *template
  stage: build_more
  variables:
    OPAM_PINS: "coq version 8.6"
  except:
  - triggers
