Skip to content

ci: Reintroduce fixed "test-each-commit" job - #28497

Merged
fanquake merged 1 commit into
bitcoin:masterfrom
hebasto:230915-each-commit
Sep 19, 2023
Merged

fanquake merged 1 commit into
bitcoin:masterfrom
hebasto:230915-each-commit

Conversation

@hebasto

@hebasto hebasto commented Sep 15, 2023 •

Copy link
Copy Markdown
Member

This is a fixed version of #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.

For historical context, please see:

A note for reviewers: To test scripts locally, ensure that you works with a shallow copy of the repo.

@DrahtBot

DrahtBot commented Sep 15, 2023 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK MarcoFalke

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@maflcko

maflcko commented Sep 17, 2023

Copy link
Copy Markdown
Member

Can you explain what was wrong in my implementation and how you fixed it?

lgtm ACK either way. Thanks!

@hebasto

hebasto commented Sep 18, 2023

Copy link
Copy Markdown
Member Author

Can you explain what was wrong in my implementation and how you fixed it?

Sure.

First, let's reproduce the problem locally. Consider https://github.com/bitcoin/bitcoin/actions/runs/6184348331?pr=26711:

$ git init bitcoin
$ cd bitcoin
$ git remote add origin https://github.com/bitcoin/bitcoin
$ git fetch --depth=8 origin 0b98391134811cf0cb809566d67174cd4148364a
$ git checkout 0b98391134811cf0cb809566d67174cd4148364a

Now git log --merges -1 --format='%H' produces an empty string, because there are no merge commits indeed:

$ git log --oneline 
0b98391 (HEAD) [refactor] use CheckPackageMempoolAcceptResult in previous tests
4c42a23 [unit test] package validation subsets and subpackages
baf475d [test util] CheckPackageMempoolAcceptResult
2143915 [policy] allow any ancestor package, not just child-with-unconfirmed-parents
6ffdadc [validation] submit ancestor subpackages
af6eb62 [validation] add a PreChecks loop to linearize by fee and find obvious errors
f00b0ec [refactor] specify what transactions were too low feerate
05f1e5f (grafted) [validation] fully abort package validation for non-TX_SINGLE_FAILURE failures

We need to fetch N + 2 commits, where N represents the number of commits in the pull request.

@maflcko

maflcko commented Sep 18, 2023

Copy link
Copy Markdown
Member

Ah thanks, so that was another bug. Though, my approach also failed for pull requests with a single commit.

@hebasto

hebasto commented Sep 19, 2023

Copy link
Copy Markdown
Member Author

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:

  • checkout:
$ git init bitcoin
$ cd bitcoin
$ git remote add origin https://github.com/bitcoin/bitcoin
$ git fetch --depth=8 origin a241d6069cf0542acdd8ec6be63724da19f10720
$ git checkout a241d6069cf0542acdd8ec6be63724da19f10720
  • the following step:
$ git checkout HEAD~

git log --merges -1 --format='%H' returns 1e9d367d0d39f9252bf8f738c216c0fe4c64a898, which is correct.

However, git log ^1e9d367d0d39f9252bf8f738c216c0fe4c64a898 HEAD --format='%H' produces an empty line, because

$ git rev-parse HEAD
1e9d367d0d39f9252bf8f738c216c0fe4c64a898

and git log is effectively pointed at the empty set of commits.

Fixed by removing the previous git checkout HEAD~ command.

@maflcko

maflcko commented Sep 19, 2023

Copy link
Copy Markdown
Member

Fixed by removing the previous git checkout HEAD~ command.

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.

@hebasto

hebasto commented Sep 19, 2023

Copy link
Copy Markdown
Member Author

Fixed by removing the previous git checkout HEAD~ command.

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.

if: github.event.pull_request.commits != 1

?

@maflcko

maflcko commented Sep 19, 2023 •

Copy link
Copy Markdown
Member

The general idea is that if a pull request has N commits, this check is run min(6, N-1) times.

@hebasto

hebasto commented Sep 19, 2023

Copy link
Copy Markdown
Member Author

The general idea is that if a pull request has N commits, this check is run max(6, N-1) times.

min(6, N-1) ?

@hebasto

hebasto commented Sep 19, 2023 •

Copy link
Copy Markdown
Member Author

The general idea is that if a pull request has N commits, this check is run min(6, N-1) times.

Then it holds, that the check might be skipped if a pull request has the only commit, right?

@hebasto

hebasto commented Sep 19, 2023

Copy link
Copy Markdown
Member Author

The general idea is that if a pull request has N commits, this check is run min(6, N-1) times.

Then it holds, that the check might be skipped if a pull request has the only commit, right?

OK, I'll update the code.

@maflcko

maflcko commented Sep 19, 2023

Copy link
Copy Markdown
Member

Oh, I see. You are suggesting to add the check if: github.event.pull_request.commits != 1 and re-add the git checkout HEAD~? Then yes, this should work.

The new job checks at most 6 commits of a pull request, excluding the
top one.
@hebasto

hebasto commented Sep 19, 2023

Copy link
Copy Markdown
Member Author

Updated 57ee0b5 -> 27b636a (pr28497.01 -> pr28497.02, diff):

@maflcko

maflcko commented Sep 19, 2023

Copy link
Copy Markdown
Member

lgtm ACK 27b636a

@maflcko

maflcko commented Sep 19, 2023

Copy link
Copy Markdown
Member

Windows CI failure seems unrelated

@maflcko

maflcko commented Sep 19, 2023

Copy link
Copy Markdown
Member

rfm?

@fanquake
fanquake merged commit 737aac8 into bitcoin:master Sep 19, 2023
@hebasto
hebasto deleted the 230915-each-commit branch September 19, 2023 16:11
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Sep 25, 2023
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
@ryanofsky

ryanofsky commented Oct 2, 2023 •

Copy link
Copy Markdown
Contributor

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 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 91328ff 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.

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:

  • When checking out d898e96 which contains more than 6 non-merge commits it executes on the last 6 commits.
  • When checking out 1b2a5f1 which contains 1 non-merge commit, it executes only just that commit.
  • When checking out 91328ff which is a merge commit, it succeeds right away and executes nothing.

To decipher the $(git rev-list -n7 --reverse HEAD ^$(git rev-list -n1 --merges HEAD)^@ | head -1) expression:

  • The git rev-list -n7 --reverse HEAD parts lists HEAD and up to 6 of its most recent ancestor commits in chronological order.
  • The extra ^$(git rev-list -n1 --merges HEAD)^@ argument is just there to exclude ancestors of merge commits:
    • $(git rev-list -n1 --merges HEAD) finds the most recent merge commit
    • The ^@ suffix after it expands that merge commit into a list of the parent commits it merges
    • The ^ prefix before it excludes all these merge parents and their ancestors

I'd be happy to make or review a PR with this fix if it seems right

@maflcko

maflcko commented Oct 3, 2023

Copy link
Copy Markdown
Member

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.

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 3, 2023
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.
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 3, 2023
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.
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 3, 2023
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.
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 3, 2023
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.
@ryanofsky

Copy link
Copy Markdown
Contributor

No objection if it makes the code clearer or is an improvement otherwise.

Thanks, implemented the change in #28573

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 4, 2023
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.
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 5, 2023
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.
fanquake added a commit to bitcoin-core/gui that referenced this pull request Oct 9, 2023
… 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
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Oct 13, 2023
…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
janus pushed a commit to BitgesellOfficial/bitgesell that referenced this pull request Apr 1, 2024
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.
Comment thread .github/workflows/ci.yml
env:
MAX_COUNT: 6
steps:
- run: echo "FETCH_DEPTH=$((${{ github.event.pull_request.commits }} + 2))" >> "$GITHUB_ENV"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bitcoin bitcoin locked and limited conversation to collaborators May 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants