variables:
  RUN:
    value: "all"
    description: "The tests that should run. Possible values: ubuntu, win-msvc, win-mingw, mac, all."
  GIT_DEPTH: 15

stages:
  - build
  - deploy

build_ubuntu_gcc:
  only:
    variables:
      - $RUN =~ /\bubuntu.*/i || $RUN =~ /\ball.*/i
  stage: build
  tags: 
    - ubuntu-gcc-cached
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
  timeout: 15m
  retry: 1
  script:
    - mkdir debug
    - cd debug
    - cmake -DCMAKE_BUILD_TYPE=Debug ..
    - cmake --build . -j 4
  artifacts:
    name: "Documentation - $CI_PIPELINE_ID"
    paths:
      - doc/html
      - doc/latex
    expire_in: never

build_win10_msvc:
  only:
    variables:
      - $RUN =~ /\bwin-msvc.*/i || $RUN =~ /\ball.*/i
  stage: build
  tags: 
    - win10-msvc-cached
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
  timeout: 15m
  retry: 0
  script:
    - cd 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\'
    - .\Launch-VsDevShell.ps1
    - cd $CI_PROJECT_DIR
    - mkdir debug
    - cd debug
    - cmake -DCMAKE_BUILD_TYPE=Debug ..
    - cmake --build . -j 4

build_win10_mingw:
  only:
    variables:
      - $RUN =~ /\bwin-mingw.*/i || $RUN =~ /\ball.*/i
  stage: build
  tags: 
    - win10-mingw-cached
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
  timeout: 15m
  retry: 0
  script:
    - mkdir debug
    - cd debug
    - cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-g++.exe .. -G "Unix Makefiles"
    - cmake --build . -j 4

build_mac_clang:
  only:
    variables:
      - $RUN =~ /\bmac.*/i || $RUN =~ /\ball.*/i
  stage: build
  tags: 
    - catalina-clang-cached
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
  timeout: 15m
  retry: 1
  script:
    - mkdir debug
    - cd debug
    - export LDFLAGS="-L/usr/local/opt/llvm/lib"
    - export CPPFLAGS="-I/usr/local/opt/llvm/include"
    - cmake -DCMAKE_C_COMPILER="/usr/local/opt/llvm/bin/clang" -DCMAKE_CXX_COMPILER="/usr/local/opt/llvm/bin/clang++" -DCMAKE_BUILD_TYPE=Debug ..
    - cmake --build . -j 4

deploy_doc_develop:
  only:
    variables:
      - $RUN =~ /\bubuntu.*/i || $RUN =~ /\ball.*/i
    refs:
      - develop
  stage: deploy
  needs: ["build_ubuntu_gcc"]
  dependencies: 
    - build_ubuntu_gcc
  tags: 
    - webserver
  variables:
    GIT_STRATEGY: none
  script:
    - rsync -avh doc/html/ /var/www/html/develop --delete
    - echo "Check it out at https://vkcv.de/develop"

deploy_doc_branch:
  only:
    variables:
      - $RUN =~ /\bubuntu.*/i || $RUN =~ /\ball.*/i
  except:
    refs:
      - develop
  stage: deploy
  needs: ["build_ubuntu_gcc"]
  dependencies: 
    - build_ubuntu_gcc
  tags: 
    - webserver
  variables:
    GIT_STRATEGY: none
  script:
    - rsync -avh  doc/html/ /var/www/html/branch/$CI_COMMIT_BRANCH --delete
    - echo "Check it out at https://vkcv.de/branch/$CI_COMMIT_BRANCH"