From 1919a2d2d65682726decf32ae1404dc5cc507012 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 13 Jul 2024 14:08:44 +0200 Subject: [PATCH 1/4] Reapply "Check for fixup commits on CI" This reverts commit f2db9fa3f91311fb42967234222bc510cf89b8bf. --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ scripts/check_for_fixups.sh | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 scripts/check_for_fixups.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64c890894..9b0a04938 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -219,3 +219,25 @@ jobs: CODACY_PROJECT_TOKEN=${{ secrets.CODACY_PROJECT_TOKEN }} \ bash <(curl -Ls https://coverage.codacy.com/get.sh) report \ --force-coverage-parser go -r coverage.out + + check-for-fixups: + runs-on: ubuntu-latest + if: github.ref != 'refs/heads/master' + steps: + # See https://github.com/actions/checkout/issues/552#issuecomment-1167086216 + - name: "PR commits + 1" + run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" + + - name: "Checkout PR branch and all PR commits" + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + fetch-depth: ${{ env.PR_FETCH_DEPTH }} + + - name: "Fetch the other branch with enough history for a common merge-base commit" + run: | + git fetch origin ${{ github.event.pull_request.base.ref }} + + - name: Check for fixups + run: | + ./scripts/check_for_fixups.sh ${{ github.event.pull_request.base.ref }} diff --git a/scripts/check_for_fixups.sh b/scripts/check_for_fixups.sh new file mode 100755 index 000000000..c2c2e1a21 --- /dev/null +++ b/scripts/check_for_fixups.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +base_ref=$1 + +# Determine the base commit +base_commit=$(git merge-base HEAD origin/"$base_ref") + +# Check if base_commit is set correctly +if [ -z "$base_commit" ]; then + echo "Failed to determine base commit." + exit 1 +fi +echo "Base commit: $base_commit" + +# Get commits with "fixup!" in the message from base_commit to HEAD +commits=$(git log -i -P --grep "fixup\!" --format="%h %s" "$base_commit..HEAD") + +if [ -z "$commits" ]; then + echo "No fixup commits found." + exit 0 +else + echo "Fixup commits found:" + echo "$commits" + exit 1 +fi From 463cf35e64f0a6e1d74ca3ece49064306a039ab8 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 13 Jul 2024 14:39:28 +0200 Subject: [PATCH 2/4] Make checkout action work with forks --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b0a04938..2143d3910 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -231,6 +231,7 @@ jobs: - name: "Checkout PR branch and all PR commits" uses: actions/checkout@v4 with: + repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.ref }} fetch-depth: ${{ env.PR_FETCH_DEPTH }} From 891362dfb2dd525e1cc824e0c4c7ac19efbdf3de Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 13 Jul 2024 15:01:19 +0200 Subject: [PATCH 3/4] Use extended regex rather than perl regex in the git call My local git is not compiled with PCRE support, so using -E makes it easier for me to test the script locally. And -E is good enough for the simple matching we want to do here. --- scripts/check_for_fixups.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_for_fixups.sh b/scripts/check_for_fixups.sh index c2c2e1a21..12a07e3fd 100755 --- a/scripts/check_for_fixups.sh +++ b/scripts/check_for_fixups.sh @@ -13,7 +13,7 @@ fi echo "Base commit: $base_commit" # Get commits with "fixup!" in the message from base_commit to HEAD -commits=$(git log -i -P --grep "fixup\!" --format="%h %s" "$base_commit..HEAD") +commits=$(git log -i -E --grep "fixup\!" --format="%h %s" "$base_commit..HEAD") if [ -z "$commits" ]; then echo "No fixup commits found." From 20ccb03a4545aa59f8fc0caafa1cbeda331a2f54 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 13 Jul 2024 14:47:37 +0200 Subject: [PATCH 4/4] Extend check for fixups Also check for squash! and amend! (these are all anchored to the beginning of the subject), and WIP and DROPME for good measure (but only if they occur in the first line, otherwise it wouldn't let me merge this very commit :) --- scripts/check_for_fixups.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/check_for_fixups.sh b/scripts/check_for_fixups.sh index 12a07e3fd..31ed8640e 100755 --- a/scripts/check_for_fixups.sh +++ b/scripts/check_for_fixups.sh @@ -13,13 +13,13 @@ fi echo "Base commit: $base_commit" # Get commits with "fixup!" in the message from base_commit to HEAD -commits=$(git log -i -E --grep "fixup\!" --format="%h %s" "$base_commit..HEAD") +commits=$(git log -i -E --grep '^fixup!' --grep '^squash!' --grep '^amend!' --grep '^[^\n]*WIP' --grep '^[^\n]*DROPME' --format="%h %s" "$base_commit..HEAD") if [ -z "$commits" ]; then echo "No fixup commits found." exit 0 else - echo "Fixup commits found:" + echo "Fixup or WIP commits found:" echo "$commits" exit 1 fi