Skip to content

Commit 9591b0a

Browse files
projectgusdpgeorge
authored andcommitted
tools/ci.sh: Fix commit msg checking when PR branch HEAD behind master.
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]>
1 parent d34b15a commit 9591b0a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

.github/workflows/commit_formatting.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Check commit message formatting
22

3-
on: [push, pull_request]
3+
on: [pull_request]
44

55
concurrency:
66
group: ${{ github.workflow }}-${{ github.ref }}
@@ -12,7 +12,7 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414
with:
15-
fetch-depth: '100'
15+
fetch-depth: 100
1616
- uses: actions/setup-python@v5
1717
- name: Check commit message formatting
1818
run: source tools/ci.sh && ci_commit_formatting_run

tools/ci.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ function ci_c_code_formatting_run {
3939
# commit formatting
4040

4141
function ci_commit_formatting_run {
42-
git remote add upstream https://github.com/micropython/micropython.git
43-
git fetch --depth=100 upstream master
42+
# Default GitHub Actions checkout for a PR is a generated merge commit where
43+
# the parents are the head of base branch (i.e. master) and the head of the
44+
# PR branch, respectively. Use these parents to find the merge-base (i.e.
45+
# where the PR branch head was branched)
46+
4447
# If the common ancestor commit hasn't been found, fetch more.
45-
git merge-base upstream/master HEAD || git fetch --unshallow upstream master
46-
# For a PR, upstream/master..HEAD ends with a merge commit into master, exclude that one.
47-
tools/verifygitlog.py -v upstream/master..HEAD --no-merges
48+
git merge-base HEAD^1 HEAD^2 || git fetch --unshallow origin
49+
50+
MERGE_BASE=$(git merge-base HEAD^1 HEAD^2)
51+
HEAD=$(git rev-parse HEAD^2)
52+
echo "Checking commits between merge base ${MERGE_BASE} and PR head ${HEAD}..."
53+
tools/verifygitlog.py -v "${MERGE_BASE}..${HEAD}"
4854
}
4955

5056
########################################################################################

0 commit comments

Comments
 (0)