image: gcc:14

before_script:
  - apt-get update && apt-get install -y cmake ninja-build libeigen3-dev git

stages:
    - test
    - release
    - static_analyze

test:
    stage: test
    script:
      - mkdir build && cd build
      - cmake -DCMAKE_BUILD_TYPE=Debug -DTUG_ENABLE_TESTING=ON -G Ninja ..
      - ninja 
      - ctest --output-junit test_results.xml
    artifacts:
      when: always
      paths:
        - build/test_results.xml
      reports:
        junit: build/test_results.xml

doc:
  stage: release
  image: python:slim
  before_script:
    - apt-get update && apt-get install --no-install-recommends -y graphviz imagemagick doxygen make
    - pip install --upgrade pip && pip install Sphinx Pillow breathe sphinx-rtd-theme sphinx-mdinclude
    - mkdir public
  script:
    - pushd docs_sphinx
    - make html
    - popd && mv docs_sphinx/_build/html/* public/
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH

push:
  stage: release
  variables:
    GITHUB_REPOSITORY: 'git@github.com:POET-Simulator/tug.git'
    ORIGINAL_REPO_URL: 'https://git.gfz-potsdam.de/naaice/tug.git'
    ORIGINAL_REPO_NAME: 'tug'
  before_script:
    # I know that there is this file env variable in gitlab, but somehow it does not work for me (still complaining about white spaces ...)
    # Therefore, the ssh key is stored as a base64 encoded string
    - mkdir -p ~/.ssh && echo $GITHUB_SSH_PRIVATE_KEY | base64 -d > ~/.ssh/id_ed25519 && chmod 0600 ~/.ssh/id_ed25519
    - ssh-keyscan github.com >> ~/.ssh/known_hosts
  script:
    - rm -rf $ORIGINAL_REPO_NAME.git
    - git clone --mirror $ORIGINAL_REPO_URL "$ORIGINAL_REPO_NAME.git" && cd $ORIGINAL_REPO_NAME.git
    - git push --mirror $GITHUB_REPOSITORY

lint:
  stage: static_analyze
  before_script:
    - apk add clang-extra-tools openmp-dev
  script:
    - mkdir lint && cd lint
    - cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-checks=cppcoreguidelines-*,clang-analyzer-*,performance-*" -DTUG_ENABLE_TESTING=OFF ..
    - make tug
  when: manual
