# All jobs should extend this which defines some defaults that cannot be
# specified in “default”.
.base:
  # Use an image tagged with the branch name because “:latest” is not
  # well-defined if multiple branches are open (see issue #1981).
  image: $CI_REGISTRY_IMAGE/ci_$ci_distro:$CI_COMMIT_REF_NAME
  tags: [saas-linux-medium-$ci_arch]
  # DNS hiccups seem fairly common; this retries the job if that (or some
  # other failure that’s not our fault) happens.
  retry:
    max: 2
    when: runner_system_failure
  artifacts:
    when: always
    name: ${CI_JOB_NAME}-${ci_arch}_${CI_COMMIT_SHORT_SHA}
    expire_in: 1 week
    untracked: true
  before_script:
    # “variables” keyword does not seem to expand $PATH correctly, the main
    # symptom being that docker(1) can’t be found in ci-images.
    - export PATH=$PATH:$CI_PROJECT_DIR/test/gitlab.com
    - |
      if [[ $ci_prefix ]]; then
          export PATH=$(cd $ci_prefix && pwd)/bin:$PATH
      else
          export PATH=$PWD/bin:$PATH
      fi
    # Mount a generous tmpfs to put our image builder crap in.
    #- if [[ $(id -u) -ne 0 ]]; alias mount='sudo mount'; fi
    #- mount -t tmpfs -o size=50% weirdal /var/tmp
    # Print various useful information about the job.
    - info.sh


# Each job should also either extend one of these or define “rules” manually.
# The initial motivation here was to do an abbreviated CI for merge trains,
# which will in most cases have just completed an MR CI. In that case, we
# mostly want to check for merge problems, and another long CI would be
# redundant.
.rules-quick:
  rules:
    - if: $CH_PIPELINE_MODE == "ci"
      when: on_success
.rules-standard:
  rules:
    - if: (   $CH_PIPELINE_MODE == "ci"
           && $CI_MERGE_REQUEST_EVENT_TYPE != "merge_train")
      when: on_success
.rules-premium:
  # Use this rule if the job requires some “Premium” level or above feature,
  # e.g. GPU runners [1], so CI works in “Free” tier forks. We couldn’t find a
  # way to test subscription tier directly, so just test if it’s in the
  # original group. See: #2052.
  #
  # [1]: https://docs.gitlab.com/ci/runners/hosted_runners/gpu_enabled/
  rules:
    - if: (   $CH_PIPELINE_MODE == "ci"
           && $CI_MERGE_REQUEST_EVENT_TYPE != "merge_train"
           && $CI_PROJECT_ROOT_NAMESPACE == "charliecloud")
      when: on_success
