-
Notifications
You must be signed in to change notification settings - Fork 0
38 lines (36 loc) · 1.62 KB
/
commit-message.yml
File metadata and controls
38 lines (36 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
name: Commit message workflow
on: [push]
jobs:
commit:
name: Commit message
runs-on: ubuntu-latest
steps:
- name: Pull repository
uses: actions/checkout@v3
- name: Validate commit message
run: |
# Get the commit message
commit_message=$(git log -1 --pretty=%B)
# Check if the commit is empty
if [ -z "$commit_message" ]; then
echo "Error: Your commit is empty. Please provide a descriptive commit message."
exit 1
fi
# Check if the commit message matches the pattern
if ! echo "$commit_message" | grep -E '^(feat|enhancement|fix|docs|style|refactor|perf|test|chore|ci|build)\(([A-Za-z0-9_-]+)\) ?: ?.+$' > /dev/null && ! echo "$commit_message" | grep -E '^Merge pull request #[0-9]+ from [A-Za-z0-9.#_\/-]+$' > /dev/null && ! echo "$commit_message" | grep -E "^Merge (?:remote-tracking )?branch '[A-Za-z0-9.#_\/-]+' into [A-Za-z0-9.#_\/-]+$" > /dev/null; then
echo "Error: Your commit message does not match the format:"
echo " <type>(<scope>): <short summary>"
echo "or"
echo " Merge pull request #<pull request number> from <branch>"
echo "or"
echo " Merge branch <branch> into <branch>"
echo
echo "Example:"
echo " feat(auth): add user authentication"
echo "or"
echo " Merge pull request #001 from Corppooling/hotfix/important-fix"
echo "or"
echo " Merge branch 'master' into hotfix/{id}-important-fix"
echo
exit 1
fi