stages:
  - trigger pipelines
  - deploy

variables:
  IMAGE_REGISTRY_URL: $CI_REGISTRY/dumux-repositories/dumux-docker-ci
  DUMUX_CI_DUNE_LATEST_RELEASE: "2.9"
  REVEAL_THEME: "serif"
  PANDOC_VERSION: 3.1.2

# rules for the default triggers:
# - pipelines are triggered for merge requests and external triggers (e.g. nightly build in dumux)
# - Within merge requests, we require to start the pipeline manually by clicking play for the trigger
# - if the pipeline was triggered externally (from dumux), we may receive merge-request-related variables
.default-trigger:
  stage: trigger pipelines
  trigger:
    include:
      - local: .gitlab-ci/default.yml
    strategy: depend
  rules:
    - if: $CI_PIPELINE_SOURCE == "pipeline"
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      when: manual
  variables:
    MR_TARGET_BRANCH_NAME: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
    DUMUX_MR_SOURCE_BRANCH: $DUMUX_MERGE_REQUEST_SOURCE_BRANCH
    DUMUX_MR_TARGET_BRANCH: $DUMUX_MERGE_REQUEST_TARGET_BRANCH
    DUMUX_TRIGGER_COMMIT_SHA: $DUMUX_COMMIT_SHA
    DUMUX_TRIGGER_REF_SHA: $DUMUX_REFERENCE_SHA

full-dune-latest-release-gcc:
  extends: .default-trigger
  variables:
    IMAGE: $IMAGE_REGISTRY_URL/full:dune-$DUMUX_CI_DUNE_LATEST_RELEASE-gcc-ubuntu-20.04

pages:
  image: alpine:latest
  stage: deploy
  script:
  - wget https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux-amd64.tar.gz -O pandoc.tar.gz
  - tar -xvf pandoc.tar.gz
  - export PATH=$PATH:$(pwd)/pandoc-$PANDOC_VERSION/bin
  - |
    mkdir build && cd build
      for MDFILE in ../slides/*.md; do
        TARGET=${MDFILE/.md/.html}
        pandoc -t revealjs -s --mathjax -o ${TARGET} ../slides/${MDFILE} \
              -V revealjs-url=https://unpkg.com/reveal.js/ \
              -V theme=${REVEAL_THEME} \
              --include-in-header=../slides/dumux_course.css
      done
    cd ..
  - mkdir public && mv build/* public
  artifacts:
    paths:
    - public
