Check the target branch when pulling upstream projects
This is a re-submission of !3430 (merged) which we had to revert in !3431 (merged).
If a merge request is targeting a stable branch, compile_dev
pulls from the
default upstream branches instead of the stable ones.
We can fix that by checking the CI_MERGE_REQUEST_TARGET_BRANCH_NAME
variable.
Closes #1362 (closed)
Also needed for #1361 (closed)
Live test
I cherry-picked this commit into the following MRs that target a stable branch, and it worked:
How to test locally
In lack of rspec
tests, here's how you can test this manually:
- Pull this branch in a new directory outside of your GDK installation. This is because Nanoc uses the parent path to pull the repositories, and we don't want to overwrite them:
git clone --branch axil-target-branch-upstream --single-branch https://gitlab.com/gitlab-org/gitlab-docs.git --depth 1 cd gitlab-docs
- Test the following scenarios:
- Runs on stable branches,
CI_COMMIT_REF_NAME
matches a stable branch name,CI_MERGE_REQUEST_TARGET_BRANCH_NAME
is not defined. It should clone the 15.5 upstream branches:REMOVE_BEFORE_CLONE=true CI_COMMIT_REF_NAME=15.5 bin/rake clone_repositories
- Runs on merge requests targeting stable branches,
CI_MERGE_REQUEST_TARGET_BRANCH_NAME
matches a stable branch name. It should clone the 15.5 upstream branches:REMOVE_BEFORE_CLONE=true CI_COMMIT_REF_NAME=test-branch CI_MERGE_REQUEST_TARGET_BRANCH_NAME=15.5 bin/rake clone_repositories
- Runs on
main
branch,CI_COMMIT_REF_NAME
matchesmain
,CI_MERGE_REQUEST_TARGET_BRANCH_NAME
is not defined. It should clone the default upstream branches:REMOVE_BEFORE_CLONE=true CI_COMMIT_REF_NAME=main bin/rake clone_repositories
- Runs on merge requests targeting
main
. It should clone the default upstream branches:REMOVE_BEFORE_CLONE=true CI_COMMIT_REF_NAME=test-branch CI_MERGE_REQUEST_TARGET_BRANCH_NAME=main bin/rake clone_repositories
- Runs locally, no
CI_COMMIT_REF_NAME
orCI_MERGE_REQUEST_TARGET_BRANCH_NAME
is defined. It should clone the default upstream branches:REMOVE_BEFORE_CLONE=true bin/rake clone_repositories
- Runs on stable branches,
Edited by Achilleas Pipinellis