ci/github-script/prepare: identify real base branch#435596
ci/github-script/prepare: identify real base branch#435596wolfgangwalther merged 4 commits intoNixOS:masterfrom
Conversation
ci/github-script/prepare.js
Outdated
There was a problem hiding this comment.
The commands given in this comment should be the same as in verify-base-branch.sh earlier, but I'm hoping we can improve on them. I tried, and currently the --onto commit is not well chosen.
Example:
- My branch is branched off of release-25.05.
- My PR is targeting master.
I get this:
git rebase --onto $(git merge-base upstream/master HEAD) $(git merge-base upstream/release-25.05 HEAD)
While this "works" in the sense of "the PR will not contain bad commits afterwards", this is likely to lead to conflicts both during the rebase and then in the PR as well (the reverse of those earlier conflicts). That's because the merge-base for upstream/master HEAD is actually branch-off for release-25.05 and both branches (master and release) have advanced in the meantime. Considering backports, I might be rebasing over conflicts where a similar change has been made later in both branches.
In my concrete example, the only commit of my PR above was an update to ci/pinned.json. Now, with this rebase command, I hit a conflict, because this file didn't even exist in the merge-base that I rebased onto. I can't even solve this conflict properly, because when I keep the file away, my entire commit is gone - I only had this change!
What I think we should be telling users instead in this case would be to:
git rebase --onto upstream/master $(git merge-base upstream/release-25.05 HEAD)
This would work better. I can see where the previous approach likely came from, and that's when dealing with staging/master changes. In that case, it might be more helpful to actually target a merge-base between master and staging first, for fewer rebuilds. But even in that case... I'd say the Nr. 1 priority should be to not let the contributor lose changes due to too many conflicts. Thus, I'd say we should always do --onto <target>.
cc @infinisil, I'd like to know your opinion, too, as the one who wrote verify-base-branch.sh.
c1f3b00 to
70942db
Compare
|
Interesting CI failure for I wonder.. whether that appears in the same case that the "symlink creation errors" have appeared in before... |
70942db to
262c3c3
Compare
262c3c3 to
4b8b775
Compare
There was a problem hiding this comment.
Thanks for improving #435596 (comment)
I have a couple wording suggestions for the new comment.
It'd also be great to get @infinisil's ack. Especially w.r.t. #435596 (comment).
Otherwise LGTM 🚀
Well, specifically for the comment, I only proposed the change, so far, but didn't implement it, yet. So that shouldn't block merging this. But I agree, it would be good if you, @infinisil, could have a quick look at the general approach for "is this the right branch?" verification here, having spent time on that topic more than enough yourself. |
philiptaron
left a comment
There was a problem hiding this comment.
Approved with some thoughts.
4b8b775 to
60c8d5e
Compare
|
Improved wording based on the resolved comments. |
|
Something doesn't work well, yet: That's PRs for staging/haskell-updates. Example: #429810 Doing this locally: Surprise... the |
60c8d5e to
0f1d397
Compare
|
I added an |
0f1d397 to
40e4426
Compare
Could we exclude the That way you would never attempt to match a branch against itself. |
This is the very first step to extending the commits job to do more than just cherry-picks in the future: It could check reverts or merge commits, but also the commit message format and more. Of course, cherry-picks are still just checked on the stable branches as before. For now, this allows us to run the part that dismisses automated reviews automatically. This helps us when we do branch related checks in the prepare step, which would also create such a review. To avoid cluttering multiple reviews across a PR, we'll want all of these reviews to be handled by the same code, thus this change.
This allows re-using postReview in the next commit.
No, that won't be enough. I tried this at first, but this would still break on staging-next, which includes commits from staging, but merges into master. For that case, the script would still suggest staging as the best fit. I found no other way than to say "if merging between development branches, don't check", which is what I implemented as "only check if the head branch is WIP". Note that every branch that is not a development or channel branch is a WIP branch. That includes not only the |
40e4426 to
74a0d67
Compare
…nches This moves the no-channel-base check into the prepare script to exit early and prevent all of CI to run against those branches. We also provide better output by posting a "Changes Requested" review, using the existing infrastructure from the old cherry-picks check. The review will be dismissed automatically once the branch has been corrected, because the commits check will run and do it.
|
I tested this against a wide variety of different PRs now, targeting different branches etc. - one more thing that doesn't work, yet: A PR targeting That's minus 22 commits, interesting :D The solution to this is to always include the current target branch in the set of branches to check as well. Once I do that, the script will return Tested again against all these different branches - this seems to work well now. |
When a contributor mistakenly sets the wrong target branch for a Pull Request, this can lead to bad consequences for CI. Most prominent is the mass ping of codeowners, that is already handled in `ci/request-reviews/verify-base-branch.sh`. But there are other things that go wrong: - After eval, a mass ping of maintainers would still be possible, in theory. Practically, this doesn't happen, because we have a limit of 10 reviewer requests at the same time. - This will most often contain a change to `ci/pinned.json`, thus the full Eval matrix of all Lix/Nix versions will be run, burning a lot of resources. - The PR will be labelled with almost all labels that are available. We can improve on the current situation with some API calls to determine the "best" merge-base for the current PR. We then consider this as the "real base". If the current target is not the real base, we fail the prepare step, which is early enough to prevent all other CI from running.
74a0d67 to
87d9b08
Compare
|
Successfully created backport PR for |
When a contributor mistakenly sets the wrong target branch for a Pull Request, this can lead to bad consequences for CI. Most prominent is the mass ping of codeowners, that is already handled in
ci/request-reviews/verify-base-branch.sh(cc @infinisil). But there are other things that go wrong:ci/pinned.json, thus the full Eval matrix of all Lix/Nix versions will be run, burning a lot of resources.We can improve on the current situation with some API calls to determine the "best" merge-base for the current PR. We then consider this as the "real base". If the current target is not the real base, we fail the prepare step, which is early enough to prevent all other CI from running.
As a preparatory step, this also moves the
no-channel-branchjob into theprepareworkflow with the same consequences: When your PR is targeting a channel branch, we're not running any CI anymore, unlike previously, where we ran everything and had one tiny job fail.Things done
Add a 👍 reaction to pull requests you find important.