image: oarteam/batsim_ci:latest

variables:
  GIT_SUBMODULE_STRATEGY: none

stages:
  - big_stage

###############################################################################
# Build and test
###############################################################################
build_and_test:
  stage: big_stage
  script:
    # Build Batsim
    - export NIX_ARGS="--arg doUnitTests true --arg doCoverage true --arg debug true --arg werror true --arg coverageCoveralls true --argstr testVersion $(date +%s)"
    - nix-shell --pure -A batsim ${NIX_ARGS} --command ${CI_PROJECT_DIR}/ci/list-store-paths-for-cachix.bash | cachix push batsim
    - nix-build -A batsim ${NIX_ARGS}
    # Build doxygen documentation
    - nix-shell --pure -A doxydoc --command ${CI_PROJECT_DIR}/ci/list-store-paths-for-cachix.bash | cachix push batsim
    - nix-build -A doxydoc && cp -rL result ./doxydoc_html
    # Run integration tests
    - nix-shell --pure -A integration_tests ${NIX_ARGS} --command ${CI_PROJECT_DIR}/ci/list-store-paths-for-cachix.bash | cachix push batsim
    - nix-build -A integration_tests ${NIX_ARGS} && cp -rL result ./integration_tests
    - if [[ "$(cat ./integration_tests/pytest_returncode)" -ne 0 ]] ; then echo "pytest returned non-zero, aborting" ; exit 1 ; fi
    # Generate a coverage report
    - nix-shell --pure -A coverage-report ${NIX_ARGS} --command ${CI_PROJECT_DIR}/ci/list-store-paths-for-cachix.bash | cachix push batsim
    - nix-build -A coverage-report ${NIX_ARGS} && cp -rL result ./coverage_report
    # Send coverage results to codecov.io
    - nix-shell -A codecov_push_shell --command 'codecov -f ./coverage_report/coveralls.json'
  artifacts:
    when: always
    expire_in: 8 hours
    paths:
      - /builds/batsim/batsim/doxydoc_html
      - /builds/batsim/batsim/integration_tests
      - /builds/batsim/batsim/coverage_report

###############################################################################
# Tutorials
###############################################################################
tuto_first_simulation-stable:
  stage: big_stage
  only:
    - schedules
  script:
    - cd docs/tuto-first-simulation
    - nix-shell --pure ./tuto-env.nix --command ${CI_PROJECT_DIR}/ci/list-store-paths-for-cachix.bash | cachix push batsim
    - nix-shell ./tuto-env.nix --command './run_simulation_manually.bash'
    - nix-shell ./tuto-env.nix --command './run_simulation_robin.bash'

tuto_first_simulation-pinned:
  stage: big_stage
  only:
    - schedules
  script:
    - cd docs/tuto-first-simulation
    - nix-shell --pure ./tuto-env-pinned.nix --command ${CI_PROJECT_DIR}/ci/list-store-paths-for-cachix.bash | cachix push batsim
    - nix-shell ./tuto-env-pinned.nix --command './run_simulation_manually.bash'
    - nix-shell ./tuto-env-pinned.nix --command './run_simulation_robin.bash'

tuto_first_simulation:
  stage: big_stage
  only:
    - schedules
  script:
    - cd docs/tuto-first-simulation
    - nix-shell --pure ./tuto-env-master.nix --command ${CI_PROJECT_DIR}/ci/list-store-paths-for-cachix.bash | cachix push batsim
    - DO_NOT_CHECK_VERSION=1 nix-shell ./tuto-env-master.nix --command './run_simulation_manually.bash'
    - DO_NOT_CHECK_VERSION=1 nix-shell ./tuto-env-master.nix --command './run_simulation_robin.bash'
