default:
    image: rboman/waves-py3:2020.3
    before_script:
        - wget https://bootstrap.pypa.io/get-pip.py
        - python3 get-pip.py
        - python3 -m pip install scipy==1.10.1 --user
        - source /opt/intel/mkl/bin/mklvars.sh intel64
        - source /opt/intel/tbb/bin/tbbvars.sh intel64
        - 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 # we use clang-format-10 exclusively
        - ./format/format.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/raeValidation.py -v
        - python3 run.py blast/validation/oneraValidation.py -v
        - python3 run.py blast/validation/lannValidation.py -v
        - set -e
        - if [ $? -ne 0 ]; then exit 1; fi
    dependencies:
        - build
    when: manual