stages:
  - trigger
  - downstream modules

variables:
  IMAGE_REGISTRY_URL: $CI_REGISTRY/dumux-repositories/dumux-docker-ci

# Cases in which to create pipelines at all. The trigger jobs may further
# specify how exactly they should be created in different situations.
workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

###################################################################################
# Stage 1: trigger the Dumux test pipelines                                       #
# In this stage, we trigger the test pipeline with different configurations, i.e. #
# different Dune versions, compilers, etc. Within merge requests, we create three #
# test pipelines including two different compilers and a full and minimal setup   #
# of dependencies. In all other situations, additional test jobs are created.     #
###################################################################################

# basic trigger job to start the test pipeline
.base-trigger:
  stage: trigger
  trigger:
    include: .gitlab-ci/default.yml
    strategy: depend
  variables:
    TRIGGER_SOURCE: $CI_PIPELINE_SOURCE
  rules:
  - if: $CI_PIPELINE_SOURCE == "schedule"
    when: always
  - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    when: manual

# trigger for jobs that should not be created in merge requests
.non-mr-trigger:
  extends: .base-trigger
  rules:
    - if: $CI_PIPELINE_SOURCE != "merge_request_event"

#############################################
# pipelines to be created in merge requests #
full-dune-2.7-gcc:
  extends: .base-trigger
  variables:
    IMAGE: $IMAGE_REGISTRY_URL/full:dune-2.7-gcc-ubuntu-20.04

minimal-dune-2.7-gcc:
  extends: .base-trigger
  variables:
    IMAGE: $IMAGE_REGISTRY_URL/minimal:dune-2.7-gcc-ubuntu-20.04

full-dune-2.7-clang:
  extends: .base-trigger
  variables:
    IMAGE: $IMAGE_REGISTRY_URL/full:dune-2.7-clang-ubuntu-20.04

##################################
# additional scheduled pipelines #
full-dune-master-gcc:
  extends: .non-mr-trigger
  variables:
    IMAGE: $IMAGE_REGISTRY_URL/full:dune-master-gcc-ubuntu-20.04

full-dune-master-clang:
  extends: .non-mr-trigger
  variables:
    IMAGE: $IMAGE_REGISTRY_URL/full:dune-master-clang-ubuntu-20.04


#########################################################
# Stage 2: trigger test pipelines of downstream modules #
#########################################################

# trigger lecture test
trigger lecture:
  stage: downstream modules
  trigger:
    project: dumux-repositories/dumux-lecture
    # TODO: use master when lecture pipeline is set up
    branch: feature/test-dumux-trigger
    strategy: depend
  variables:
    DUMUX_MERGE_REQUEST_BRANCH: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
