Testing against main ref

Migrated issue

Reported by: jonathan1055

Related to !44 (merged) !49 (closed) !51 (closed) !43 (merged)

This issue is a follow-up from the discussion on #3557370: PHPCS fails on d7-basic - The Drupal standard is not found

Problem/Motivation

Gitlab Templates Downstream (GTD) branches should run against the 'main' ref by default, so that scheduled branches and stand-alone MR are always testing the latest changes in Gitlab Templates (GT).

However, we cannot simply hardcode ref: 'main' in each GTD branch's .gitlab-ci.yml as that would prevent them being tested as downstream pipelines from an upsream GT merge request.

Initial proposed resolution

In gitlab_templates > .gitlab-ci.yml

.downstream-base:
  ...
  variables:
    # So downstream plugins know which .gitlab-ci.yml include to use.
    _GITLAB_TEMPLATES_REPO: $CI_PROJECT_PATH
    _GITLAB_TEMPLATES_REF: $CI_COMMIT_REF_NAME
    _GTD_TEMPLATE_REF: $CI_COMMIT_REF_NAME
    ...

Then in gitlab_templates_downstream > .gitlab-ci.yml

variables:
  ...
  _GTD_TEMPLATE_REF: 'main'

include:
  - project: $_GITLAB_TEMPLATES_REPO
    ref: $_GTD_TEMPLATE_REF

That would set up the correct ref for downstream piipelines and main for “normal” project pipelines

Actual resolution

  • Use the project CI/CD settings to specify an override value "main" for _GITLAB_TEMPLATES_REF
  • This variable is also automatically copied to issue fork branches when the fork is created
  • Some existing issue forks do not have this setting, and that cannot be changed. We will work with this, and the problem will diminish as MR and issues are closed