Skip to content

Commit

Permalink
ci: add PR squash message checker
Browse files Browse the repository at this point in the history
  • Loading branch information
a-dubs committed Sep 23, 2024
1 parent 78322fb commit 233ee3a
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,42 @@ jobs:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout the PR
uses: actions/checkout@v3

- uses: webiny/action-conventional-commits@v1.3.0
with:
allowed-commit-types: "feat,fix,docs,ci,test,refactor,chore"
allowed-commit-types: "feat,fix,docs,ci,test,refactor,chore"


- name: Validate PR merge type and commit message
id: validate
run: |
# Extract the PR body
PR_BODY=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }} | jq -r .body)
# Check if the "Squash merge" checkbox is selected
if echo "$PR_BODY" | grep -q "\- \[x\] Squash merge"; then
echo "Squash merge selected."
# Extract the proposed commit message block
COMMIT_MESSAGE=$(echo "$PR_BODY" | sed -n '/## Proposed Commit Message/,/##/p' | sed '1d;$d')
if [ -z "$COMMIT_MESSAGE" ]; then
echo "Error: Proposed commit message block is empty."
exit 1
fi
# Check if the commit message follows the conventional commits format
if ! echo "$COMMIT_MESSAGE" | grep -E '^(feat|fix|docs|ci|test|refactor|chore)(\(.+\))?: .{1,72}$'; then
echo "Error: Commit message does not follow the conventional commits format."
exit 1
fi
else
echo "Squash merge not selected. Skipping commit message check."
fi
- name: Fail if validation failed
if: steps.validate.outputs.result != 'success'
run: exit 1

0 comments on commit 233ee3a

Please sign in to comment.