default:
    image: rboman/waves-py3:2023.0
    before_script:
        - source /opt/intel/oneapi/mkl/latest/env/vars.sh
        - source /opt/intel/oneapi/tbb/latest/env/vars.sh
        - echo $(nproc)
        - printenv | sort

.global_tag: &global_tag_def
    tags:
        - mn2l
#        - warson   # you can choose a set of runners here

variables:
    GIT_SUBMODULE_STRATEGY: recursive
    GIT_STRATEGY: clone # workaround full clone for each pipeline (https://gitlab.com/gitlab-org/gitlab-runner/-/issues/26993)
    GIT_LFS_SKIP_SMUDGE: 1 # do not pull LFS

stages:
    - build
    - test
    - validation

format:
    <<: *global_tag_def
    stage: build
    script:
        - clang-format --version
        - ./modules/dartflo/ext/amfe/scripts/format_code.py
        - mkdir -p patches
        - if git diff --patch --exit-code > patches/clang-format.patch; then echo "Clang format changed nothing"; else echo "Clang format found changes to make!"; false; fi
    artifacts:
        paths:
            - patches/
        expire_in: 1 day
        when: on_failure
    allow_failure: true

build:
    <<: *global_tag_def
    stage: build
    script:
        - git submodule init
        - git submodule update
        - rm -rf build workspace
        - mkdir build
        - cd build
        - cmake -Wno-dev ..
        - make -j 8
    artifacts:
        paths:
            - build/
        expire_in: 1 day

doxygen:
    <<: *global_tag_def
    stage: test
    script:
        - cd build
        - make dox
    artifacts:
        paths:
            - build/doxygen/
        expire_in: 1 week
    dependencies:
        - build

ctest:
    <<: *global_tag_def
    stage: test
    script:
        - cd build
        - ctest --output-on-failure -j 8
    dependencies:
        - build

cvalidation:
    <<: *global_tag_def
    stage: validation
    script:
        - set +e
        - python3 run.py blast/validation/highlift_2D.py -v; HIGHLIFT_STATUS=$?
        - python3 run.py blast/validation/rae2822_2D.py -v; RAE_STATUS=$?
        - python3 run.py blast/validation/oneraM6_3D.py -v; ONERA_STATUS=$?
        - python3 run.py blast/validation/lann_3D.py -v; LANN_STATUS=$?
        - python3 run.py blast/validation/agard_3D.py -v; AGARD_STATUS=$?
        - set -e
        - |
          echo "HIGHLIFT Validation Status: $HIGHLIFT_STATUS"
          echo "RAE Validation Status: $RAE_STATUS"
          echo "ONERA Validation Status: $ONERA_STATUS"
          echo "LANN Validation Status: $LANN_STATUS"
          echo "AGARD Validation Status: $AGARD_STATUS"
        - if [ $HIGHLIFT_STATUS -ne 0 ] || [ $RAE_STATUS -ne 0 ] || [ $ONERA_STATUS -ne 0 ] || [ $LANN_STATUS -ne 0 ] || [ $AGARD_STATUS -ne 0 ]; then exit 1; fi
    dependencies:
        - build
    when: manual