Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tools/ci: Fix commit message checking when PR branch HEAD behind master. #16114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

projectgus
Copy link
Contributor

@projectgus projectgus commented Oct 30, 2024

Summary

Fixes the subtle problem noted here - workflow log here. Specifically, default CI HEAD for a PR is a (generated) merge commit into the master branch's current HEAD. If the PR branch isn't fully rebased (i.e. is one or more commits behind latest mater) then the commit check runs against commits from master as well!

Also drops running this check on push, the pull_request event is triggered by default on open and update, so that should cover all cases where this check needs to run.

Testing

I made this PR branch the default branch in my fork and opened a series of dummy PRs:

  1. Up to date with a valid commit message. Passes on master, still passes.
  2. Up to date with an invalid commit message. Fails on master, still fails.
  3. Old branch (100+ commits out of date) with invalid message. Fails on master but probably tests a lot of unrelated commits. Tests correct commits and fails with this PR. Note this run needed to do an "unshallow" fetch to find the merge base, due to being more than 100 commits out of date.
  4. Old branch (one commit out of date) with valid message. This is the kind of branch which fails on master as it tests unrelated commits. Checks one commit and passes with this PR.

This work was funded through GitHub Sponsors.

@projectgus projectgus added the tools Relates to tools/ directory in source, or other tooling label Oct 30, 2024
@projectgus
Copy link
Contributor Author

@andrewleech I just saw you tackled this exact problem in #12658, but I think there are still some scenarios where it still checks the wrong commits.

@projectgus projectgus force-pushed the bugfix/ci_commit_message branch from 92d11ce to 09de917 Compare October 30, 2024 05:40
@dpgeorge
Copy link
Member

Thanks, this looks good to me, and your testing is thorough!

As you noted, do we also need to update the related logic in ci_code_size_build?

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (d34b15a) to head (9591b0a).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16114   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21345    21345           
=======================================
  Hits        21040    21040           
  Misses        305      305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andrewleech
Copy link
Contributor

andrewleech commented Oct 30, 2024

That looks great @projectgus , thanks for the clear description both here and in the script.
I'm pretty sure I never realised GitHub ran its actions in a trial merge, that does complicate it just a little bit more!

Oh the existing comment did mention the merge and try to exclude it, regardless I like the look of your changes and testing.

@projectgus
Copy link
Contributor Author

projectgus commented Oct 30, 2024

I'm pretty sure I never realised GitHub ran its actions in a trial merge, that does complicate it just a little bit more!

Yeah, I hadn't realised either until I looked at this. There is a way to tell the GitHub checkout action to check out the PR branch HEAD instead of the merge commit, but this actually gives us more work in this case because we still don't know what the merge base is, and we need this to know which commits to check! Whereas having the dummy merge commit (in this case) means we have all of the git history we need without needing to fetch anything new.

As you noted, do we also need to update the related logic in ci_code_size_build?

I looked at this yesterday and thought it was OK, but I just looked again and I think there's a bug: it currently compares the PR branch's merge base against the generated merge commit. So that means any changes merged on master which aren't in the PR branch are included in the size comparison.

I think it should either compare the merge base with the PR branch HEAD, or compare the generated merge commit with the master branch. Probably the second one as that's exactly what the code size increase would be if the PR was merged.

Will submit another PR for this.

Fixes the problem noted at
micropython#15547 (comment)
which is that, because default CI HEAD for a PR is a (generated) merge
commit into the master branch's current HEAD, then if the PR branch isn't
fully rebased then the commit check runs against commits from master as
well!

Also drops running this check on push, the pull_request event is triggered
by default on open and update ("synchronized" event), which probably covers
the cases where this check should run.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
@dpgeorge dpgeorge force-pushed the bugfix/ci_commit_message branch from 09de917 to 9591b0a Compare October 31, 2024 12:18
@dpgeorge dpgeorge merged commit 9591b0a into micropython:master Oct 31, 2024
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Relates to tools/ directory in source, or other tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants