Repository navigation
ci: Reintroduce fixed "test-each-commit" job - #28497
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
|
Can you explain what was wrong in my implementation and how you fixed it? lgtm ACK either way. Thanks! |
Sure. First, let's reproduce the problem locally. Consider https://github.com/bitcoin/bitcoin/actions/runs/6184348331?pr=26711: Now We need to fetch |
|
Ah thanks, so that was another bug. Though, my approach also failed for pull requests with a single commit. |
The https://github.com/bitcoin/bitcoin/actions/runs/6184007676?pr=28476 is such a case. Reproducing it locally:
However, and Fixed by removing the previous |
Seems wasteful, because the HEAD commit is already checked by all other CI tasks, so I'd say it would make sense to skip it. |
? |
|
The general idea is that if a pull request has |
|
Then it holds, that the check might be skipped if a pull request has the only commit, right? |
OK, I'll update the code. |
|
Oh, I see. You are suggesting to add the check |
The new job checks at most 6 commits of a pull request, excluding the top one.
57ee0b5 to
27b636a
Compare
|
Updated 57ee0b5 -> 27b636a (pr28497.01 -> pr28497.02, diff):
|
|
lgtm ACK 27b636a |
|
Windows CI failure seems unrelated |
|
rfm? |
27b636a ci: Reintroduce fixed "test-each-commit" job (Hennadii Stepanov) Pull request description: This is a fixed version of bitcoin#28279: > Currently, if a pull request has more than one commit, previous commits may fail to compile, or may fail the tests. This is problematic, because it breaks git-bisect, or worse. > > Fix this by adding a CI task for this. The new job checks at most 6 commits of a pull request, excluding the top one. The maximum number of tested commits is 6, which derives from the time [constrains](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idtimeout-minutes). For historical context, please see: - bitcoin#28279 - bitcoin#28477 - bitcoin#28478 **A note for reviewers:** To test scripts locally, ensure that you works with a _shallow_ copy of the repo. ACKs for top commit: MarcoFalke: lgtm ACK 27b636a Tree-SHA512: 0c69ced13509fa0ed2dd6ef13f4c710d678e31b294b6318b59ab1ba899086a71b5c893aaf70e143036349329167bf8e16bdca319b2c761e2aef6222d0db1470c
|
This job is failing for me on #25722 (https://github.com/bitcoin/bitcoin/actions/runs/6303163392/job/17147055820?pr=25722) with 1b2a5f1. The problem is that the PR only contains a one commit after the last merge, so the job should be skipped, but the I think a nice way to fix this would be instead of figuring out the commit after the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. I tested the following command line and it seem to work well in all cases: git rebase --exec "echo Running test-one-commit on \$( git log -1 ); echo" $(git rev-list -n7 --reverse HEAD ^$(git rev-list -n1 --merges HEAD)^@ | head -1)Test cases:
To decipher the
I'd be happy to make or review a PR with this fix if it seems right |
No objection if it makes the code clearer or is an improvement otherwise. However, I don't think merge commits are supported in mergeable pull requests, unless it is a subtree bump. So unless the bug also affects subtree bumps, I don't think we need to spend time fixing it. |
Instead of figuring out the commit *after* the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. From bitcoin#28497 (comment): The problem is that the PR only contains a one commit after the last merge, so the job _should_ be skipped, but the `pull_request.commits != 1` check is not smart enough to skip it because the PR is based on another PR and has merge ancestor commits. So specifically what happens is that after HEAD~ is checked out, the new HEAD is a merge commit, so the range `$(git log --merges -1 --format=%H)..HEAD` is equivalent to HEAD..HEAD, which is empty, so the `COMMIT_AFTER_LAST_MERGE` variable is empty and the rebase command fails.
Instead of figuring out the commit *after* the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. From bitcoin#28497 (comment): The problem is that the PR only contains a one commit after the last merge, so the job _should_ be skipped, but the `pull_request.commits != 1` check is not smart enough to skip it because the PR is based on another PR and has merge ancestor commits. So specifically what happens is that after HEAD~ is checked out, the new HEAD is a merge commit, so the range `$(git log --merges -1 --format=%H)..HEAD` is equivalent to HEAD..HEAD, which is empty, so the `COMMIT_AFTER_LAST_MERGE` variable is empty and the rebase command fails.
Instead of figuring out the commit *after* the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. From bitcoin#28497 (comment): The problem is that the PR only contains a one commit after the last merge, so the job _should_ be skipped, but the `pull_request.commits != 1` check is not smart enough to skip it because the PR is based on another PR and has merge ancestor commits. So specifically what happens is that after HEAD~ is checked out, the new HEAD is a merge commit, so the range `$(git log --merges -1 --format=%H)..HEAD` is equivalent to HEAD..HEAD, which is empty, so the `COMMIT_AFTER_LAST_MERGE` variable is empty and the rebase command fails.
Instead of figuring out the commit *after* the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. From bitcoin#28497 (comment): The problem is that the PR only contains a one commit after the last merge, so the job _should_ be skipped, but the `pull_request.commits != 1` check is not smart enough to skip it because the PR is based on another PR and has merge ancestor commits. So specifically what happens is that after HEAD~ is checked out, the new HEAD is a merge commit, so the range `$(git log --merges -1 --format=%H)..HEAD` is equivalent to HEAD..HEAD, which is empty, so the `COMMIT_AFTER_LAST_MERGE` variable is empty and the rebase command fails.
Thanks, implemented the change in #28573 |
Instead of figuring out the commit *after* the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. From bitcoin#28497 (comment): The problem is that the PR only contains a one commit after the last merge, so the job _should_ be skipped, but the `pull_request.commits != 1` check is not smart enough to skip it because the PR is based on another PR and has merge ancestor commits. So specifically what happens is that after HEAD~ is checked out, the new HEAD is a merge commit, so the range `$(git log --merges -1 --format=%H)..HEAD` is equivalent to HEAD..HEAD, which is empty, so the `COMMIT_AFTER_LAST_MERGE` variable is empty and the rebase command fails.
Instead of figuring out the commit *after* the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. From bitcoin#28497 (comment): The problem is that the PR only contains a one commit after the last merge, so the job _should_ be skipped, but the `pull_request.commits != 1` check is not smart enough to skip it because the PR is based on another PR and has merge ancestor commits. So specifically what happens is that after HEAD~ is checked out, the new HEAD is a merge commit, so the range `$(git log --merges -1 --format=%H)..HEAD` is equivalent to HEAD..HEAD, which is empty, so the `COMMIT_AFTER_LAST_MERGE` variable is empty and the rebase command fails.
… parent of head is merge commit 88c8e3a github actions: Fix test-one-commit when parent of head is merge commit (Ryan Ofsky) Pull request description: Instead of figuring out the commit *after* the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. Explanation of the problem from bitcoin/bitcoin#28497 (comment): > The problem is that the PR only contains a one commit after the last merge, so the job _should_ be skipped, but the `pull_request.commits != 1` check is not smart enough to skip it because the PR is based on another PR and has merge ancestor commits. So specifically what happens is that after HEAD~ is checked out, the new HEAD is a merge commit, so the range `$(git log --merges -1 --format=%H)..HEAD` is equivalent to HEAD..HEAD, which is empty, so the `COMMIT_AFTER_LAST_MERGE` variable is empty and the rebase command fails. Note: In the current version of this PR, the "test each commit" job is skipped, because this PR only contains a single commit. But I manually verified the code works in earlier versions of the PR that included dummy commits. ACKs for top commit: maflcko: lgtmrecr ACK 88c8e3a RandyMcMillan: utACK 88c8e3a Tree-SHA512: a6865b5c8b96eb0b622b3255971a3cf050dd0f5a356cdfcf7f0cbb659e4a363612e8e62b3ae4fd6b5d9a40bc29176891bc4690659b026c5ef8feea25c8e263cc
…of head is merge commit 88c8e3a github actions: Fix test-one-commit when parent of head is merge commit (Ryan Ofsky) Pull request description: Instead of figuring out the commit *after* the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. Explanation of the problem from bitcoin#28497 (comment): > The problem is that the PR only contains a one commit after the last merge, so the job _should_ be skipped, but the `pull_request.commits != 1` check is not smart enough to skip it because the PR is based on another PR and has merge ancestor commits. So specifically what happens is that after HEAD~ is checked out, the new HEAD is a merge commit, so the range `$(git log --merges -1 --format=%H)..HEAD` is equivalent to HEAD..HEAD, which is empty, so the `COMMIT_AFTER_LAST_MERGE` variable is empty and the rebase command fails. Note: In the current version of this PR, the "test each commit" job is skipped, because this PR only contains a single commit. But I manually verified the code works in earlier versions of the PR that included dummy commits. ACKs for top commit: maflcko: lgtmrecr ACK 88c8e3a RandyMcMillan: utACK 88c8e3a Tree-SHA512: a6865b5c8b96eb0b622b3255971a3cf050dd0f5a356cdfcf7f0cbb659e4a363612e8e62b3ae4fd6b5d9a40bc29176891bc4690659b026c5ef8feea25c8e263cc
Instead of figuring out the commit *after* the last merge and rebasing on that with a ~1 suffix, just figure out the last merge commit directly and rebase on it. This way, if HEAD happens to be a merge commit, the rebase just succeeds immediately without blank variables or errors. From bitcoin/bitcoin#28497 (comment): The problem is that the PR only contains a one commit after the last merge, so the job _should_ be skipped, but the `pull_request.commits != 1` check is not smart enough to skip it because the PR is based on another PR and has merge ancestor commits. So specifically what happens is that after HEAD~ is checked out, the new HEAD is a merge commit, so the range `$(git log --merges -1 --format=%H)..HEAD` is equivalent to HEAD..HEAD, which is empty, so the `COMMIT_AFTER_LAST_MERGE` variable is empty and the rebase command fails.
| env: | ||
| MAX_COUNT: 6 | ||
| steps: | ||
| - run: echo "FETCH_DEPTH=$((${{ github.event.pull_request.commits }} + 2))" >> "$GITHUB_ENV" |
There was a problem hiding this comment.
I'm surprised this doesn't cause a failure on pull requests that build on other pull requests.
If pull request B has 3 commits that build on top of pull request A with 10 commits, then FETCH_DEPTH would be 5. I believe that should cause git log --merges -1 below to fail, because it won't have the merge commit.
But looking at #28201 this seems to work fine. But when pull request A is on this repo and pull request B is on a fork repo it doesn't, it seems: #29274 (comment)
There was a problem hiding this comment.
@ryanofsky fixed a simpler case of this in #28573, where PR B has 1 commit. Though I'm confused why he ran into it while #28201 doesn't.
There was a problem hiding this comment.
@ryanofsky fixed a simpler case of this in #28573, where PR B has 1 commit. Though I'm confused why he ran into it while #28201 doesn't.
I think there shouldn't be a problem here because even if a pull request is based on another pull request, the github.event.pull_request.commits number will include the number of commits in both pull requests, because github treats pull requests as being independent and isn't aware of relationships between them.
The case I was fixing in #28573 was a more strange case described in #28497 (comment). Sometimes, when I have a PR B based on a PR A, I base the new commits in B on top of A merged with master, instead of just A like most other developers do. (I do this just because it lets me avoid needing to rebase A when B has a merge conflict.) This didn't work with the old test-each-commit implementation because the pushed branch had a extra merge commit that the script was not expecting, and broke it.
There was a problem hiding this comment.
because github treats pull requests as being independent and isn't aware of relationships between them.
On the fork I tested on the pull request wasn't against master but against branch A.
This is a fixed version of #28279:
The new job checks at most 6 commits of a pull request, excluding the top one.
The maximum number of tested commits is 6, which derives from the time constrains.
For historical context, please see:
A note for reviewers: To test scripts locally, ensure that you works with a shallow copy of the repo.