# gitlab-ci file for fpm

default:
    image: rboman/waves-py3:2020.3
    before_script:
        - source /opt/intel/mkl/bin/mklvars.sh intel64
        - source /opt/intel/tbb/bin/tbbvars.sh intel64

.global_tag: &global_tag_def
    tags:
        - mn2l

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
    - format
    - test

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 $(nproc)
    artifacts:
        paths:
            - build/
        expire_in: 1 day

format:
    <<: *global_tag_def
    stage: format
    script:
        - clang-format --version # we use clang-format-10 exclusively
        - ./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
    dependencies:
        - build
    allow_failure: true

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 $(nproc)
    #timeout: 10 hours  # will be available in 12.3
    dependencies:
        - build
