Skip to content

GitHub Actions - Automate npm package updates and release notes #2

GitHub Actions - Automate npm package updates and release notes

GitHub Actions - Automate npm package updates and release notes #2

name: Check for Conventional Commits
on: pull_request
jobs:
check_commits:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required to get all commits in the PR
- name: Get PR commits
id: get_commits
run: |
PR_NUMBER="${{ github.event.number }}"
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
echo "PR_COMMITS=$(git log --pretty=format:'%s' $BASE_SHA...$HEAD_SHA)" >> "$GITHUB_OUTPUT"
- name: Check for conventional commits
continue-on-error: true
run: |
commits="${{ steps.get_commits.outputs.PR_COMMITS }}"
IFS=$'\n' read -r -d '' -a commit_array <<< "$commits"
has_conventional_commit=false
for commit_message in "${commit_array[@]}"; do
if [[ "$commit_message" =~ ^(feat|fix|build|chore|ci|docs|perf|refactor|revert|style|test)(\([^)]+\))?: .* ]]; then
has_conventional_commit=true
break
fi
done
if [[ "$has_conventional_commit" == "false" ]]; then
echo "::warning::Pull request does not contain at least one conventional commit. A new package version won't be created for this pull request."
exit 1
else
echo "::notice::Pull request contains at least one conventional commit. A new package version will be created for this pull request."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}