From 690dfc2668aea85549e6dbaad131e15afb1ecb21 Mon Sep 17 00:00:00 2001 From: Marco Donadoni Date: Fri, 22 Mar 2024 12:31:54 +0100 Subject: [PATCH] ci(commitlint): do not check merge commit's ancestors (#92) --- .github/workflows/ci.yml | 2 +- run-tests.sh | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57e4cae..68b7000 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - name: Check commit message compliance of the pull request if: github.event_name == 'pull_request' run: | - ./run-tests.sh --check-commitlint ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.number }} + ./run-tests.sh --check-commitlint ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.number }} lint-shellcheck: runs-on: ubuntu-20.04 diff --git a/run-tests.sh b/run-tests.sh index 77ac166..8c6bad3 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -16,15 +16,25 @@ check_commitlint () { npx commitlint --from="$from" --to="$to" found=0 while IFS= read -r line; do - if echo "$line" | grep -qP "\(\#$pr\)$"; then + commit_hash=$(echo "$line" | cut -d ' ' -f 1) + commit_title=$(echo "$line" | cut -d ' ' -f 2-) + commit_number_of_parents=$(git rev-list --parents "$commit_hash" -n1 | awk '{print NF-1}') + if [ "$commit_number_of_parents" -gt 1 ]; then + if echo "$commit_title" | grep -qP "^chore\(.*\): merge "; then + break + else + echo "✖ Merge commits are not allowed in feature branches: $commit_title" + found=1 + fi + elif echo "$commit_title" | grep -qP "^chore\(.*\): release"; then true - elif echo "$line" | grep -qP "^chore\(.*\): release"; then + elif echo "$commit_title" | grep -qP "\(\#$pr\)$"; then true else - echo "✖ Headline does not end by '(#$pr)' PR number: $line" + echo "✖ Headline does not end by '(#$pr)' PR number: $commit_title" found=1 fi - done < <(git log "$from..$to" --format="%s") + done < <(git log "$from..$to" --format="%H %s") if [ $found -gt 0 ]; then exit 1 fi