Problem/Motivation
Our gitlabci template makes use of the CI_MERGE_REQUEST_PROJECT_URL environment variable for fetching.
This assumes the repository is publicly available and doesn't work for private repositories.
The security team has a private fork of core on our gitlab instance for testing security issues.
Tests currently fail on the use of this variable because we can't fetch the repository over https
Steps to reproduce
Proposed resolution
Use 'origin' instead of the repository URL
Remaining tasks
- Follow up: In the test-only script, make sure that the correct commit is fetched. (See Comments #9, #12.)
- Follow-up: Avoid false positives when a Git command fails. For example, when the test-only script tries to use a commit that has not been fetched. (See Comments #9, #12.)
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
N/A
Issue fork drupal-3412415
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
larowlanComment #5
larowlanComment #7
fjgarlin commentedThe changes look good to me.
I went a bit through git history about CI_MERGE_REQUEST_PROJECT_URL in the two places where it was used:
- We were using
originbefore and that was changed here #3387400: GitlabCI should fetch less from git, but I think it can be brought back.- The other place where it was present was like that from the very beginning #3386566: Add support for 'test only' changes to gitlab CI, and you (@larowlan) did that initial job, so you're familiar with the change already :-)
Marking RTBC.
Comment #8
longwaveDo we not need CI_MERGE_REQUEST_PROJECT_URL for MRs? What is "origin" in that case - the MR repo or the base repo? Sure I have seen the "test only" script failing somewhere because of an invalid git object ID, and now I wonder if that's because the MR repo was out of date compared to the base repo.
Comment #9
longwaveAh, here it is: https://git.drupalcode.org/project/drupal/-/jobs/570956
A test-only job that looks like it succeeded (it should have failed) but because it ran no tests and resulted in an error:
Comment #10
drummIn case it it helpful, GitLab has some “magic” refs around MRs, https://docs.gitlab.com/ee/user/project/merge_requests/reviews/#checkout...
Comment #11
fjgarlin commentedCI_MERGE_REQUEST_REF_PATHcontains the above value. I'm not entirely sure about how to use it in this context tho.Comment #12
benjifisherRegarding the invalid object error mentioned in #9: I am pretty sure that comes from these lines in
test-only.sh:For a MR,
$TARGET_BRANCHshould be 11.x. Fetching with--depth 50on 2024-01-04 would not reach7ea369d937df18d7d4fb802f7249a7b7f7de4708.Maybe, instead of fetching a branch, we should fetch a commit. Maybe the script should be less optimistic and fail when it tries to access a "bad object". (I vote yes and yes.) But both of those suggestions are out of scope for the current issue. I will add the tag for a follow-up.
Regarding Comment #10: the
headof the MR is checked out. The hard part is getting the target branch.From Comment #8:
That seems like the key question. I think "MR repo" will normally mean the issue fork. (For security issues, the MR repo and the base repo are both the private fork.) I am not sure which repo
CI_MERGE_REQUEST_PROJECT_URLrefers to, but I am pretty sure thatoriginrefers to the MR repo/issue fork. That is where we clone the source branch for the MR.I think that is what we want. For the test-only script, we want to find tests that the MR adds or changes. If the main branch of the base repo has commits that are not mirrored in the MR repo (issue fork or private fork) and those commits make test changes, then we do not want to look at those. The same idea applies to the spell-check job: we want to look at changes introduced by the current MR.
Short version: I agree with Comment #7: using
originis the right fix. Back to RTBC.Comment #13
benjifisherComment #16
catchNot really possible to test this conclusively without merging it, so I've just done that. Committed/pushed to 11.x and cherry-picked to 10.2.x, thanks!
Comment #17
andypostIt makes regression - spellcheck job (for ex) now comparing against issue's fork 11.x branch instead of project's (target repo) one
Comment #18
benjifisher@andypost:
Why is that a bad thing? In Comment #12, I suggested that comparing against the 11.x branch in the issue fork is the right thing to do.
Comment #19
andypostSometimes issue forks has no 11.x branch yet or it's outdated so follow-up is #3401988: Spell-checking job fails with "Argument list too long" when too many files are changed
Comment #20
benjifisherMaybe we should automatically update the target branch in the issue fork whenever
Probably that is not going to happen before we finish the transition from Drupal issues to GitLab.
Or maybe there is some way in the CI job to access
HEAD...11.x(the common ancestor commit of the source and target branches).Comment #21
benjifisher@andypost: Maybe #3416154: The test-only script for GitLab CI does not reliably use the right commit is the right approach for both the test-only job and the spell-check job.
Comment #22
drummThe issue fork’s 11.x branch should be completely irrelvant as its not the target branch, the canonical project’s 11.x branch is the target. Worst case, someone could push mismatched code to the fork’s 11.x designed to undermine the test results. Keeping the canonical branches automatically synced to every issue fork would be impractical since there are thousands of them.
Comment #24
quietone commentedI chatted with @benjifisher about the followups. Two already exist related to the first item in #12. There are #3416154: The test-only script for GitLab CI does not reliably use the right commit and #3419182: Test-only job fails with "couldn't find remote ref refs/heads/11.x" when 11.x branch does not exist in fork. I have added a new issue for the second point. #3421799: Let the test-only script for GitLab CI fail when it tries to access a "bad object"
Comment #25
quietone commentedAnd I forgot to remove the tag.