Skip to content

Check the target branch when pulling upstream projects

Achilleas Pipinellis requested to merge axil-target-branch-upstream into main

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:

  1. 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
  2. Test the following scenarios:
    1. 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
    2. 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
    3. Runs on main branch, CI_COMMIT_REF_NAME matches main, 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
    4. 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
    5. Runs locally, no CI_COMMIT_REF_NAME or CI_MERGE_REQUEST_TARGET_BRANCH_NAME is defined. It should clone the default upstream branches:
      REMOVE_BEFORE_CLONE=true bin/rake clone_repositories
Edited by Achilleas Pipinellis

Merge request reports