Fix logic when skipping repositories clones
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
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.
- We have the following variables that are either set or not:
-
REMOVE_BEFORE_CLONE
: effectively the same asCI
, 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 thegitlab-docs
pipeline runs inmain
, 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
ofgitlab-docs
, or when we merge an MR ofgitlab-docs
intomain
(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.
-
I have evaluated the MR acceptance checklist for this merge request.