Problem/Motivation
When a new branch is pushed to an old fork and the fork existed before the 11.x branch, and an MR is created against 11.x, the spellcheck job fails with
couldn't find remote ref refs/heads/11.x
See https://git.drupalcode.org/issue/drupal-3112295/-/jobs/719518
The workaround is to of course push 11.x to the fork, but then you also have to hide the 11.x branch from the issue's fork branches. This is 2 steps that shouldn't be required.
Steps to reproduce
Find an issue with a fork that existed pre 11.x
Create a new branch on the fork with some changes
Create an MR with that branch against 11.x
Proposed resolution
Not sure, I thought we fixed this in #3401988: Spell-checking job fails with "Argument list too long" when too many files are changed
Merge request link
Remaining tasks
Figure out why.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | Screenshot 2024-02-02 at 16.29.19.png | 65.11 KB | fjgarlin |
Issue fork drupal-3418207
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
fjgarlin commented#3401988: Spell-checking job fails with "Argument list too long" when too many files are changed was technically solved, as we shouldn't get that error anymore.
This one is now different and happens when
11.xis not present in the fork (ie: old forks).I think there are two possible ways of approaching this:
1. Catch the fail and let the users know what's needed and how to do it, instead of getting a hard git fail.
2. Check if the desired target branch is there, and if it's not, fetch it from the remote to the job. We can do this before the
git fetch -v...line. Note that this would not update the fork nor rebase, it would just do it inside the job.Comment #3
mondrakeAh, now I see. I also hit that in #3306554: InvocationMocker::withConsecutive() is deprecated in PHPUnit 9.6 and removed from PHPUnit 10, MR!3795. I think it's critical, it also affects rebasing of RTBC MRs.
Comment #4
longwaveThis is tricky to test as you need an issue fork that doesn't contain 11.x; you can't delete branches from issue fork repos. So I found an old issue and started experimenting.
From reading the docs I think
$CI_MERGE_REQUEST_TARGET_BRANCH_SHAis the correct variable to use, and shouldn't require fetching; because the MR merges into the target repo for the purposes of the build, then this SHA should be present already in the local repo.https://git.drupalcode.org/project/drupal/-/jobs/731750 is 11.x but rolled back a few commits (so HEAD is not the same as origin/11.x), and with a change to .gitlab-ci.yml to diff against
$CI_MERGE_REQUEST_TARGET_BRANCH_SHA- which should be the tip of the target branch, in this case 11.x. This seemed to work, only one file was present in the diff:https://git.drupalcode.org/project/drupal/-/jobs/731793 is the same but cleaned up and with a deliberate spelling error:
So this looks to work for the MR case at least; however not sure what we need to do (if anything) about other job types here?
Comment #6
longwaveComment #7
longwaveDo we also need the same changes in the test-only.sh script? And can we lower
GIT_DEPTHagain?Comment #8
fjgarlin commentedThanks for the changes and the testing!!
Purely based on the code and your testing, it looks good and it it could potentially go into RTBC, but I don't know if somebody else wants to double check.
The reason why we needed to increase the depth value was due to old forks, where there were many commits between the target (11.x) and the branch within the repo. Not sure if this simplified "git diff" command takes care of that.
Comment #9
neclimdulFrom: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#predef...
Sounds good. Seems like this will work as long as we're using the correct type of merge pipeline. That also explains why we can get rid of the fetch so great news!
Comment #10
longwaveAs this is affecting multiple other issues let's get this in and either revert or iterate from here. Backported to 10.2.x to keep things in sync there as well.
Committed and pushed cdf03eab78 to 11.x and b320fc757d to 10.2.x. Thanks!
Comment #13
longwaveReopening, because this is only apparently working in MRs created by core committers.
I think this is because the target SHA variable is only available in "merged results pipelines" which only maintainers can use, issue forks created by non maintainers work a bit differently.and don't have the target branch available. Somehow we have to take both these into account in the CI script.
Comment #14
longwaveThis is all documented at https://docs.gitlab.com/ee/ci/pipelines/merge_request_pipelines.html#typ...
This type of pipeline is created by non-committers.
This type of pipeline is created by committers.
But, if possible, we want the target branch to be combined with the source branch in an MR in all cases - it's possible that an MR is based on an outdated branch, and interacts badly with a change made since in the target branch, and we won't know that if the changes are not combined?
The previous git fetch script tried to work around this - but only for the spellchecking case - but ideally surely we need it for all CI jobs?
Comment #15
longwaveMaybe we just need to (automatically) check the "Enable merged results pipelines" setting in issue forks? https://docs.gitlab.com/ee/ci/pipelines/merged_results_pipelines.html
Comment #16
longwaveGitLab uses pull mirroring to keep forked repositories up to date: https://gitlab.com/gitlab-community/meta#configure-pull-mirroring
Unsure if we can enable the same thing here, one for @drumm @fjgarlin I guess? This might also become easier once we have
maininstead of version branches, but because we have thousands? of issue repos this might not be feasible either.Comment #17
fjgarlin commentedI think that's the default for all projects. You can see it in https://git.drupalcode.org/project/PROJECT-NAME/-/settings/merge_requests

That pull mirroring seems to be for community-forks, but I'm not sure we are using those at all.
Comment #18
neclimdul"as long as we're using the correct type of merge pipeline." welp...
Comment #19
fjgarlin commentedNow enabling "mirroring" by default might be an option: https://about.gitlab.com/blog/2016/12/01/how-to-keep-your-fork-up-to-dat...
https://docs.gitlab.com/ee/user/project/repository/forking_workflow.html
We might be able to do that at forks creation.
Will need to double check it with @drumm.
API method: https://docs.gitlab.com/ee/api/projects.html#configure-pull-mirroring-fo...
Comment #20
longwaveI found some code over in GitLab's own repo that appears to do something kinda similar: https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/rails.gitl...
In other words if
CI_MERGE_REQUEST_TARGET_BRANCH_SHAis set then use that, otherwise useCI_MERGE_REQUEST_DIFF_BASE_SHA. I think as a stopgap we should try that here and see if it works on both project MRs and fork MRs?Comment #21
longwaveComment #23
longwavehttps://git.drupalcode.org/project/drupal/-/jobs/739167 created by a committer:
https://git.drupalcode.org/issue/drupal-3418207/-/jobs/739378 created by a non-committer:
IMHO this is the best we can do for this specific issue and we need forks to stay up to date in order for all jobs to run against correctly updated branches, not just the spellcheck job.
Comment #24
fjgarlin commentedThis is a GREAT find! Even tho the "echo" lines aren't needed, they might be useful for debugging.
Based on the link shown in #20 and the tests done in #23, and the fact that the code looks ok and it runs as it should, I'm marking this issue RTBC. Both MRs have the same code.
Once deployed, we should follow up with the test-only code (https://git.drupalcode.org/project/drupal/-/blob/11.x/.gitlab-ci/scripts...). Or maybe alter the scope of this issue to include that too (in that case it'd need to be moved to "Needs work"). For now, I'll leave this issue as is.
Comment #27
longwaveLet's commit this here as spell checking is not currently working at all in non-committer MRs, and then handle test-only in a followup which I will create shortly.
Committed and pushed e1312a3d8b to 11.x and 993fc38bf1 to 10.2.x. Thanks!