Update invalid commit message #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Validate Commit Messages | |
on: | |
push: | |
branches: | |
- '**' | |
pull_request: | |
branches: | |
- '**' | |
jobs: | |
validate-commit-messages: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Validate commit messages | |
run: | | |
COMMIT_MESSAGE_HEADER=$(git log -1 --pretty=%B | head -n 1) | |
echo "commit message header: ${COMMIT_MESSAGE_HEADER}" | |
# Define the regex for Conventional Commits | |
commit_regex='^\[#(noissue|[0-9]+?)\].*' | |
error_msg="Commit message does not follow the Conventional Commits format: | |
[#issue-number] messge | |
Examples: | |
[#1001] Refactor servermap | |
[#noissue] Update README.md" | |
# Validate each commit message | |
if ! echo "${COMMIT_MESSAGE_HEADER}" | grep -Eq "$commit_regex"; then | |
echo "$error_msg" | |
echo "Invalid commit message: ${COMMIT}" | |
exit 1 | |
fi |