IAP GITLAB

Skip to content
Snippets Groups Projects
.gitlab-ci.yml 13.3 KiB
Newer Older
ralfulrich's avatar
ralfulrich committed
variables:
  GIT_STRATEGY: $CORSIKA8_GIT_STRATEGY # clone: fresh clone, fetch: update
ralfulrich's avatar
ralfulrich committed
  GIT_SSL_NO_VERIFY: "1"
  # to re-use clones also in different forks
  GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_CONCURRENT_ID/$CI_PROJECT_NAME
  ## 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"
  # location of AirShowerPhysics/corsika-data
ralfulrich's avatar
ralfulrich committed
  CORSIKA_DATA: "${CI_PROJECT_DIR}/modules/data" # the git submodule
ralfulrich's avatar
ralfulrich committed
  corsika_DIR: "${CI_PROJECT_DIR}/build/install" # for cmake to find corsikaConfig.cmake
  # _alternatively_ corsika-data can be downloaded as submodule:
  GIT_SUBMODULE_STRATEGY: normal # none: we get the submodules in before_script,
                                 # normal: get submodules automatically
  CTEST_OUTPUT_ON_FAILURE: 1


#
# multi-step pipeline for each commit
#
ralfulrich's avatar
ralfulrich committed
# Mote: "Draft:" merge request, non-Draft merge requests and "Ready for Code Review" MR are all
#       handled explicitly
#
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
stages:
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  - quality
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  - build
  - test
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  - example
  - build_test_example
Remy Prechelt's avatar
Remy Prechelt committed
  - python
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
  - optional


####### CODE QUALITY CHECK ##############
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed

##########################################################
Ralf M Ulrich's avatar
Ralf M Ulrich committed
check-copyrights:
  image: corsika/devel:u-18.04
  stage: quality
  tags:
    - corsika
  script:
    - ./do-copyright.py
  rules:
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH
  allow_failure: true
Ralf M Ulrich's avatar
Ralf M Ulrich committed

##########################################################
Ralf M Ulrich's avatar
Ralf M Ulrich committed
check-clang-format:
  image: corsika/devel:clang-8
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  stage: quality
  tags:
    - corsika
  script:
    - ./do-clang-format.py --all
  rules:
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH
  allow_failure: true
Ralf M Ulrich's avatar
Ralf M Ulrich committed

ralfulrich's avatar
ralfulrich committed
### CodeQuality tool ####
ralfulrich's avatar
ralfulrich committed
#include:
#  - template: Code-Quality.gitlab-ci.yml
#
#code_quality:
#  stage: quality
#  rules:
#    - if: '$CODE_QUALITY_DISABLED'
#      when: never
#    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' # Run code quality job in merge request pipelines
#    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'      # Run code quality job in pipelines on the master branch (but not in other branch pipelines)
#    - if: '$CI_COMMIT_TAG'                               # Run code quality job in pipelines for tags
####### CONFIG ##############

##########################################################
# the generic config template job
# job/stage to just prepare cmake
.config:
  stage: config
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
  tags:
    - corsika
ralfulrich's avatar
ralfulrich committed
  script:
Ralf Ulrich's avatar
Ralf Ulrich committed
    - mkdir -p build
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
    - cd build
    - cmake .. -DCMAKE_INSTALL_PREFIX=$PWD/install -DCMAKE_BUILD_TYPE=Debug -DUSE_Pythia8_C8=C8
  rules:
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH
ralfulrich's avatar
ralfulrich committed
  artifacts:
    when: on_failure
    expire_in: 3 days
    paths:
      - ${CI_PROJECT_DIR}/build/CMakeFiles/CMakeOutput.log
Ralf M Ulrich's avatar
Ralf M Ulrich committed
    paths:
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/
ralfulrich's avatar
ralfulrich committed
    policy: pull-push    
# config for gcc
config-u-18_04:
  extends: .config
  image: corsika/devel:u-18.04
  cache:
    key: "${CI_COMMIT_REF_SLUG}-gcc"

# config for clang
config-clang-8:
  extends: .config
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  image: corsika/devel:clang-8
  cache:
    key: "${CI_COMMIT_REF_SLUG}-clang"




####### BUILD (only manual) ##############

##########################################################
# the generic build template job
# normal pipeline for each commit
.build:
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  stage: build
  tags:
    - corsika
  script:
    - cd build
    - cmake --build . -- -j4
  rules:
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH
      when: manual
  allow_failure: true
Ralf M Ulrich's avatar
Ralf M Ulrich committed
    paths:
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/
    policy: pull-push
# build for gcc
build-u-18_04:
  extends: .build
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  image: corsika/devel:u-18.04
  dependencies:
    - config-u-18_04
  cache:
    key: "${CI_COMMIT_REF_SLUG}-gcc"
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed

# build for clang
  extends: .build
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
  image: corsika/devel:clang-8
  dependencies:
    - config-clang-8
  cache:
    key: "${CI_COMMIT_REF_SLUG}-clang"




####### TEST (only manual)  ##############

##########################################################
# generic test template job
# normal pipeline for each commit
.test:
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  stage: test
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
  tags:
    - corsika
  script:
    - cd build
ralfulrich's avatar
ralfulrich committed
    - ctest -j4 
  rules:
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH
      when: manual
  allow_failure: true
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
  artifacts:
    expire_in: 3 days
Ralf Ulrich's avatar
Ralf Ulrich committed
        - ${CI_PROJECT_DIR}/build/test_outputs/junit*.xml
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/
    untracked: true
    policy: pull-push
# test for gcc
test-u-18_04:
  extends: .test
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  image: corsika/devel:u-18.04
  dependencies:
    - build-u-18_04
  cache:
    key: "${CI_COMMIT_REF_SLUG}-gcc"

# test for clang
test-clang-8:
  extends: .test
  image: corsika/devel:clang-8
  dependencies:
    - build-clang-8
  cache:
    key: "${CI_COMMIT_REF_SLUG}-clang"



ralfulrich's avatar
ralfulrich committed
####### BUILD-TEST (all builds <= Draft, default) ##############

##########################################################
# the generic build_test template job
# normal pipeline for each commit
.build_test:
  stage: build_test
  tags:
    - corsika
  script:
    - cd build
ralfulrich's avatar
ralfulrich committed
    - cmake --build . -- -j4
    - set -o pipefail
ralfulrich's avatar
ralfulrich committed
    - ctest -j4 
ralfulrich's avatar
ralfulrich committed
    - if: '$CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_TITLE =~ /^Draft:/'
Ralf M Ulrich's avatar
Ralf M Ulrich committed
      allow_failure: false
    - if: $CI_MERGE_REQUEST_ID
      when: manual
      allow_failure: true
  allow_failure: true
  artifacts:
    when: always
    expire_in: 3 days
ralfulrich's avatar
ralfulrich committed
    paths:
      - ${CI_PROJECT_DIR}/build/test_outputs/junit*.xml
Ralf Ulrich's avatar
Ralf Ulrich committed
        - ${CI_PROJECT_DIR}/build/test_outputs/junit*.xml
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/
    untracked: true
    policy: pull-push

# build_test for gcc
build_test-u-18_04:
  extends: .build_test
  image: corsika/devel:u-18.04
  dependencies:
    - config-u-18_04
  cache:
    key: "${CI_COMMIT_REF_SLUG}-gcc"

# build_test for clang
  extends: .build_test
  image: corsika/devel:clang-8
  dependencies:
    - config-clang-8
  cache:
    key: "${CI_COMMIT_REF_SLUG}-clang"



ralfulrich's avatar
ralfulrich committed
####### BUILD-TEST-EXAMPLE (only non-Draft)  ##############

##########################################################
# generic example template job
# normal pipeline for each commit
.build_test_example:
  stage: build_test_example
  tags:
    - corsika
  script:
    - cd build
ralfulrich's avatar
ralfulrich committed
    - cmake --build . -- -j4
    - set -o pipefail
    - ctest -j4
    - make install
    - mkdir -p build_examples
    - cd build_examples
    - cmake ../install/share/corsika/examples
    - make -j4 run_examples | gzip -v -9 > examples.log.gz
  rules:
ralfulrich's avatar
ralfulrich committed
    - if: '$CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_TITLE =~ /^Draft:/'
      when: manual
      allow_failure: true
    - if: $CI_COMMIT_BRANCH
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_TAG
      when: manual
      allow_failure: true
ralfulrich's avatar
ralfulrich committed
  allow_failure: true
  artifacts:
    when: always
    expire_in: 3 days
    reports:
      junit:
Ralf Ulrich's avatar
Ralf Ulrich committed
        - ${CI_PROJECT_DIR}/build/test_outputs/junit*.xml
      - ${CI_PROJECT_DIR}/build/build_examples/examples.log.gz
ralfulrich's avatar
ralfulrich committed
      - ${CI_PROJECT_DIR}/build/test_outputs/junit*.xml
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/
    untracked: true
    policy: pull

# build_test_example for gcc
  extends: .build_test_example
  image: corsika/devel:u-18.04
  dependencies:
    - config-u-18_04
  cache:
    key: "${CI_COMMIT_REF_SLUG}-gcc"

# build_test_example for clang
build_test_example-clang-8:
  extends: .build_test_example
  image: corsika/devel:clang-8
  dependencies:
    - config-clang-8
  cache:
    key: "${CI_COMMIT_REF_SLUG}-clang"




####### INSTALL  ##############

##########################################################
# generic install template job
# make install
.install:
  stage: install
Ralf M Ulrich's avatar
Ralf M Ulrich committed
  tags:
    - corsika
  script:
    - cd build
    - set -o pipefail
Ralf Ulrich's avatar
Ralf Ulrich committed
    - make -j2 install
Ralf Ulrich's avatar
Ralf Ulrich committed
    - if: $CI_MERGE_REQUEST_ID
    - if: $CI_COMMIT_TAG
ralfulrich's avatar
ralfulrich committed
      when: manual
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_COMMIT_BRANCH
      when: manual
  allow_failure: true
Ralf M Ulrich's avatar
Ralf M Ulrich committed
    paths:
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/
    policy: pull
# install for gcc
  extends: .install
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
  image: corsika/devel:u-18.04
  dependencies:
    - build-u-18_04
  cache:
    key: "${CI_COMMIT_REF_SLUG}-gcc"

# install for clang
install-clang-8:
  extends: .install
  image: corsika/devel:clang-8
  dependencies:
    - build-clang-8
  cache:
    key: "${CI_COMMIT_REF_SLUG}-clang"



####### OPTIONAL ##############

##########################################################
# generic release template job
# optional release pipeline for each commit
.release:
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
  stage: optional
  tags:
    - corsika
  script:
    - cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_Pythia8_C8=C8
    - cmake --build . -- -j4
    - set -o pipefail
    - ctest -j4
    - make install
    - mkdir -p build_examples
    - cd build_examples
    - cmake ../install/share/corsika/examples
Ralf Ulrich's avatar
Ralf Ulrich committed
    - make -j4 run_examples | gzip -v -9 > examples.log.gz
  rules:
    - if: '$CI_MERGE_REQUEST_LABELS =~ /Ready for code review/' # run on merge requests, if label 'Ready for code review' is set
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual
      allow_failure: true
    - if: $CI_MERGE_REQUEST_ID
      when: manual
      allow_failure: true
    - if: $CI_COMMIT_TAG
      when: manual
      allow_failure: true
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/
    policy: pull
    expire_in: 3 days
Ralf Ulrich's avatar
Ralf Ulrich committed
        - ${CI_PROJECT_DIR}/build/test_outputs/junit*.xml
      - ${CI_PROJECT_DIR}/build/build_examples/examples.log.gz
ralfulrich's avatar
ralfulrich committed
      - ${CI_PROJECT_DIR}/build/test_outputs/junit*.xml
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed

# release for gcc
release-full-u-18_04:
  extends: .release
  image: corsika/devel:u-18.04
  dependencies:
    - config-u-18_04
  cache:
    key: "${CI_COMMIT_REF_SLUG}-gcc"

# release for clang
  extends: .release
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
  image: corsika/devel:clang-8
  dependencies:
    - config-clang-8
  cache:
    key: "${CI_COMMIT_REF_SLUG}-clang"

Ralf Ulrich's avatar
CI  
Ralf Ulrich committed

##########################################################
# the coverage generation should either run when manually requested, OR always on the master
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
  image: corsika/devel:u-18.04
  dependencies:
    - config-u-18_04
  stage: optional
  tags:
    - corsika
  script:
    - cd build
    - cmake .. -DCMAKE_BUILD_TYPE=Coverage -DUSE_Pythia8_C8=C8
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
    - cmake --build . -- -j4
ralfulrich's avatar
ralfulrich committed
    - ctest -j4 
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
    - cmake --build . --target coverage
    - tar czf coverage-report.tar.gz coverage-report
  coverage: '/^.*lines\.+:\s(.*\%)\s/'
  rules:
    - if: '$CI_MERGE_REQUEST_LABELS =~ /Ready for code review/' # run on merge requests, if label 'Ready for code review' is set
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_MERGE_REQUEST_ID
      when: manual
      allow_failure: true
    - if: $CI_COMMIT_TAG
      when: manual
      allow_failure: true
    expire_in: 1 year
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/coverage-report.tar.gz
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/
    policy: pull
    key: "${CI_COMMIT_REF_SLUG}-gcc"
ralfulrich's avatar
ralfulrich committed

Ralf Ulrich's avatar
CI  
Ralf Ulrich committed

##########################################################
Ralf Ulrich's avatar
CI  
Ralf Ulrich committed
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
  rules:
    - if: '$CI_MERGE_REQUEST_LABELS =~ /Ready for code review/' # run on merge requests, if label 'Ready for code review' is set
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual
      allow_failure: true
    - if: $CI_MERGE_REQUEST_ID
      when: manual
      allow_failure: true
    - if: $CI_COMMIT_TAG
      when: manual
      allow_failure: true
Ralf Ulrich's avatar
Ralf Ulrich committed
      - ${CI_PROJECT_DIR}/build/
    policy: pull
    key: "${CI_COMMIT_REF_SLUG}-gcc"
##########################################################
# template for all Python jobs
.python:
  stage: python
  tags:
    - corsika
  before_script:
    - apt-get update && apt-get install -y python3-pip
  script:
ralfulrich's avatar
ralfulrich committed
    - cd ${CI_PROJECT_DIR}/python  # change into the Python directory
    - pip3 install --user -e '.[test]'  # install the package + test deps
    - python3 --version
    - python3 -m mypy corsika
    - python3 -m isort --atomic --check-only corsika tests
    - python3 -m black -t py37 corsika tests
    - python3 -m flake8 corsika tests
    - python3 -m pytest --cov=corsika tests
    - cd ${CI_PROJECT_DIR}  # reset the directory
  coverage: '/^TOTAL\s*\d+\s*\d+\s*(.*\%)/'

# the default Python version Ubuntu 18.04 is Python3.8
python-3.8:
  extends: .python
  image: corsika/devel:u-18.04
  dependencies:
    - build-u-18_04
  cache:
    key: "${CI_COMMIT_REF_SLUG}-gcc"
  artifacts:
    when: always
    expire_in: 1 year
    paths:
      - ${CI_PROJECT_DIR}/Python/python-test.log
  allow_failure: true