Skip to content

Fix logic when skipping repositories clones

Achilleas Pipinellis requested to merge axil-fix-skip-logic into main

What does this MR do and why?

When we trigger a review app in one of the upstream projects, we skip cloning the other four projects to save time.

The logic to skip the clone was faulty, as the CI_DEFAULT_BRANCH variable would always be main (since the task runs in gitlab-docs), which would make the comparison to always be false.

PS. Found out thanks to Sarah's port to Go 😄 Read from here and below gitlab-org/technical-writing-group/gitlab-docs-hugo!4 (comment 1652846339).

PS2. This seems to have been broken since Feb 2 2021! gitlab!53361 (merged)

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

IMPORTANT: Clone this repository in a new location, as the rake task will overwrite the doc repositories.

  1. We have the following variables that are either set or not:
  • REMOVE_BEFORE_CLONE: effectively the same as CI, so this is always true in the job's context.
  • CI_PIPELINE_SOURCE=pipeline: only true when an upstream review app is running.
  • MERGE_REQUEST_IID_<product>: only true when an upstream review app is running.
  • BRANCH_<product>: only true when an upstream review app is running.
  • CI_COMMIT_REF_NAME: whether the gitlab-docs pipeline runs in main, an MR, or a stable branch.

If a variable is not in a command below, it means it's not explicitly set.

  • Hourly pipeline running in main of gitlab-docs, or when we merge an MR of gitlab-docs into main (clone all):

    REMOVE_BEFORE_CLONE=true \
    CI_COMMIT_REF_NAME=main \
    bundle exec rake clone_repositories
  • Pipeline running in a stable branch of gitlab-docs (clone all stable branches):

    REMOVE_BEFORE_CLONE=true \
    CI_COMMIT_REF_NAME=16.6 \
    bundle exec rake clone_repositories
  • Merge request pipeline in gitlab-docs (clone all):

    REMOVE_BEFORE_CLONE=true \
    CI_COMMIT_REF_NAME=test-branch \
    bundle exec rake clone_repositories
  • Review app in one of the upstream projects (clone only runner):

    REMOVE_BEFORE_CLONE=true \
    CI_COMMIT_REF_NAME=main \
    CI_PIPELINE_SOURCE=pipeline \
    MERGE_REQUEST_IID_RUNNER=4442 \
    BRANCH_RUNNER=generate-k8s-api-permissions-docs \
    bundle exec rake clone_repositories

In all cases, except the last one, CI_PIPELINE_SOURCE, MERGE_REQUEST_IID_<product>, and BRANCH_<product> are not set.

The logic is that when you run a review app from an upstream product, CI_PIPELINE_SOURCE=pipeline is always true for the given gitlab-docs pipeline. Then, only one of the 5 products gets the MERGE_REQUEST_IID_<product> and BRANCH_<product> set, which means the code branch == product["default_branch"] will be set to false, and so it will not be skipped. For the 4 rest of them, the code branch == product["default_branch"] will be set to true, and so they'll be skipped.

Merge request acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Achilleas Pipinellis

Merge request reports