##############################################################################
# CI for CEPCSW at IHEP GitLab
##############################################################################

workflow:
  rules:
    # These 3 rules from https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Workflows/MergeRequest-Pipelines.gitlab-ci.yml
    # Run on merge requests
    - if: $CI_MERGE_REQUEST_IID
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    # Run on tags
    - if: $CI_COMMIT_TAG
    # Run when called from an upstream pipeline https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html?tab=Multi-project+pipeline#use-rules-to-control-downstream-pipeline-jobs
    - if: $CI_PIPELINE_SOURCE == 'pipeline'
    - if: $CI_PIPELINE_SOURCE == 'parent-child'
    # Run on commits to the default branch
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    # The last rule above blocks manual and scheduled pipelines on non-default branch. The rule below allows them:
    - if: $CI_PIPELINE_SOURCE == "schedule"
    # Run if triggered from Web using 'Run Pipelines'
    - if: $CI_PIPELINE_SOURCE == "web"
    # Run if triggered from WebIDE
    - if: $CI_PIPELINE_SOURCE == "webide"



stages:
  - build

##############################################################################
# Template for Build and Test
##############################################################################
# Due to cmake/ctest will hardcode the path in build directory,
# the test job will be failed if it is executed on a different nodes.
# Therefore, put the build script and test script together.

.build_template:
  stage: build
  variables:
    CEPCSW_LCG_RELEASE:
    CEPCSW_LCG_PLATFORM:
    CEPCSW_LCG_VERSION:
  script:
    - bash ./.build.ci.sh
    - bash ./.test.ci.sh

##############################################################################
# Build CentOS 7 (LCG)
##############################################################################
build:lcg:el7:
  extends: .build_template
  variables:
    CEPCSW_LCG_RELEASE: LCG
    CEPCSW_LCG_PLATFORM: x86_64-centos7-gcc11-opt
    CEPCSW_LCG_VERSION: 103.0.2
  tags:
    - centos7
  artifacts:
    paths:
      - InstallArea
      - TDR_o1_v01.tgeo.root
      - TDR_o1_v02.tgeo.root
    reports:
      junit: build.${CEPCSW_LCG_VERSION}.${CEPCSW_LCG_PLATFORM}/cepcsw-ctest-result.xml

##############################################################################
# Build the docs
##############################################################################
build:docs:
  stage: build 
  tags:
    - centos7
  script:
    - bash ./.build.ci.sh docs
  artifacts:
    paths:
      - docs/build/html/