Skip to content

ci: add github action for conventional commits #4

ci: add github action for conventional commits

ci: add github action for conventional commits #4

name: Conventional Commits
on:
pull_request:
branches:
- "*"
jobs:
build:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- name: Checkout the PR
uses: actions/checkout@v3
- uses: webiny/[email protected]
with:
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