From 05dfeeccf864c46ccb66e0900438406c136fdd66 Mon Sep 17 00:00:00 2001 From: Restioson Date: Mon, 28 Oct 2024 13:56:28 +0200 Subject: [PATCH] chore(ci): lint for bang commits (fixup, squash, drop, edit) This makes sure we don't accidentally merge commits which should be squashed up or rebased first. --- .github/workflows/testing.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 25e7370..11cf731 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -117,3 +117,24 @@ jobs: with: name: django-logs path: app/debug.log + lint-commits: + runs-on: ubuntu-latest + if: github.event.ref != 'refs/heads/main' + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get all commits on current main + run: git fetch origin main + - name: Log all commits we will analyse + run: git log --pretty=format:%s origin/main..HEAD + + # - We use -v here, which inverts the match, because we want to output an exit status of 1 when a match _is_ + # found (usually 0 is for a match) + # - We use a -z here, which makes \0 be the line separator, because if feeding multiline text into grep, it will + # exit with a status of 0 regardless of whether there is a match ( + - name: Disallow bang commits + run: | + git log --pretty=format:%s origin/main..HEAD | grep "fixup!|squash!|drop!|edit!" + if [ $? -eq 0 ]; then echo "Found bang commit (or error) - rebase required before merge"; exit 1; fi