variables:
  GIT_SSL_NO_VERIFY: "1"
  ## Runtime options for sanitizers
  # (detect_leaks=0 because leak detection doesn't work in CI, but you can
  # try to test with leak detection locally by using detect_leaks=1)
  UBSAN_OPTIONS: "print_stacktrace=1"
  LSAN_OPTIONS: "log_threads=1"
  ASAN_OPTIONS: "detect_leaks=0:detect_stack_use_after_return=1"

# normal multi-step pipeline for each commit
stages:
  - config
  - build
  - test
  - release
  - optional

# job/stage to just prepare cmake
config-u-18_04:
  image: corsika/devel:u-18.04
  stage: config
  tags:
    - corsika
  script:
    - mkdir build
    - cd build
    - cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_PYTHIA=ON
  artifacts:
    expire_in: 1 day
    paths:
       - build

# job/stage to just prepare cmake
config-clang-8:
  image: corsika/devel:clang-8
  stage: config
  tags:
    - corsika
  script:
    - mkdir build
    - cd build
    - cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_PYTHIA=ON
  artifacts:
    expire_in: 1 day
    paths:
       - build

# normal pipeline for each commit
build-u-18_04: 
  image: corsika/devel:u-18.04
  dependencies:
    - config-u-18_04
  stage: build
  tags:
    - corsika
  script:
    - cd build
    - cmake --build . -- -j4
  artifacts:
    expire_in: 1 day
    paths:
       - build

# normal pipeline for each commit
build-clang-8: 
  image: corsika/devel:clang-8
  dependencies:
    - config-clang-8
  stage: build
  tags:
    - corsika
  script:
    - cd build
    - cmake --build . -- -j4
  artifacts:
    expire_in: 1 day
    paths:
       - build

test-u-18_04: 
  image: corsika/devel:u-18.04
  dependencies:
    - build-u-18_04
  stage: test
  tags:
    - corsika
  script:
    - set -o pipefail
    - cd build
    - ctest -VV | gzip -v -9 > test.log.gz 
  artifacts:
    expire_in: 3 months
    reports:
      junit:
        - build/test_outputs/junit*.xml
    paths:
      - build/test.log.gz

test-clang-8: 
  image: corsika/devel:clang-8
  dependencies:
    - build-clang-8
  stage: test
  tags:
    - corsika
  script:
    - set -o pipefail
    - cd build
    - ctest -VV | gzip -v -9 > test.log.gz 
  artifacts:
    expire_in: 3 months
    reports:
      junit:
        - build/test_outputs/junit*.xml
    paths:
      - build/test.log.gz

# normal pipeline for each commit
release-u-18_04: 
  image: corsika/devel:u-18.04
  dependencies:
    - config-u-18_04
  stage: optional
  tags:
    - corsika
  script:
    - cd build
    - cmake .. -DCMAKE_BUILD_TYPE=Release
    - cmake --build . -- -j4
    - ctest -j4 
  when: manual    

# normal pipeline for each commit
release-clang-8: 
  image: corsika/devel:clang-8
  dependencies:
    - config-clang-8
  stage: optional
  tags:
    - corsika
  script:
    - cd build
    - cmake .. -DCMAKE_BUILD_TYPE=Release
    - cmake --build . -- -j4
    - ctest -j4 
  when: manual    

# the coverage generation should either run when manually requested, OR for all changes on the master
.coverage_job: &coverage_job
  image: corsika/devel:u-18.04
  dependencies:
    - config-u-18_04
  stage: optional
  tags:
    - corsika
  script:
    - cd build
    - cmake .. -DCMAKE_BUILD_TYPE=Coverage
    - cmake --build . -- -j4
    - ctest -j4 -V > test.log 
    - cmake --build . --target coverage
    - tar czf coverage-report.tar.gz coverage-report
  coverage: '/^.*functions\.+:\s(.*\%)\s/'
  artifacts:
    expire_in: 1 year
    paths:
      - build/coverage-report.tar.gz

coverage: # special manual job to run after normal pipeline on branch finished 
  <<: *coverage_job
  when: manual    
  except:
    refs:
      - master

coverage_master: # special job to run on master banch changes
  <<: *coverage_job
  only:
    refs:
      - master

documentation:
  image: corsika/devel:u-18.04
  dependencies:
    - build-u-18_04
  stage: optional
  tags:
    - corsika
  script:
    - cd build
    - cmake --build . --target doxygen -- -j4
    - mkdir .public
    - cp -r Documentation/Doxygen/html .public/
    - mv .public ../public
  artifacts:
    expire_in: 3 months
    paths:
      - public
  when: manual
  allow_failure: true

sanity:
  image: corsika/devel:u-18.04
  dependencies:
    - config-u-18_04
  stage: optional
  tags:
    - corsika
  script:
    - cd build
    - cmake .. -DWITH_CORSIKA_SANITIZERS_ENABLED=ON
    - cmake --build . -- -j4
  when: manual
  allow_failure: true

