tools/ci.sh: Fix commit msg checking when PR branch HEAD behind master.

Fixes the problem noted at
https://github.com/micropython/micropython/pull/15547#issuecomment-2434479702
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 <angus@redyak.com.au>
This commit is contained in:
Angus Gratton
2024-10-30 11:18:59 +11:00
committed by Damien George
parent d34b15ac6f
commit 9591b0a53c
2 changed files with 13 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
name: Check commit message formatting
on: [push, pull_request]
on: [pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
@@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '100'
fetch-depth: 100
- uses: actions/setup-python@v5
- name: Check commit message formatting
run: source tools/ci.sh && ci_commit_formatting_run

View File

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