Skip to content

Commit 10386fa

Browse files
authored
Added GitHub Action to enforce stable branch commit message prefix.
1 parent ac2d907 commit 10386fa

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Check commit prefix
2+
3+
on:
4+
pull_request:
5+
types: [edited, opened, synchronize, reopened, ready_for_review]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
check-commit-prefix:
13+
if: startsWith(github.event.pull_request.base.ref, 'stable/')
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Calculate commit prefix
19+
id: vars
20+
run: |
21+
BASE="${{ github.event.pull_request.base.ref }}"
22+
HEAD="${{ github.event.pull_request.head.ref }}"
23+
echo "BASE=$BASE" >> $GITHUB_ENV
24+
echo "HEAD=$HEAD" >> $GITHUB_ENV
25+
VERSION="${BASE#stable/}"
26+
echo "prefix=[$VERSION]" >> $GITHUB_OUTPUT
27+
28+
- name: Check PR title prefix
29+
run: |
30+
TITLE="${{ github.event.pull_request.title }}"
31+
PREFIX="${{ steps.vars.outputs.prefix }}"
32+
if [[ "$TITLE" != "$PREFIX"* ]]; then
33+
echo "❌ PR title must start with the required prefix: $PREFIX"
34+
exit 1
35+
fi
36+
echo "✅ PR title has the required prefix."
37+
38+
- name: Fetch base and head branches
39+
run: |
40+
git fetch origin $BASE
41+
git fetch origin $HEAD
42+
43+
- name: Check commit messages prefix
44+
run: |
45+
PREFIX="${{ steps.vars.outputs.prefix }}"
46+
COMMITS=$(git rev-list origin/${BASE}..origin/${HEAD})
47+
echo "Checking commit messages for required prefix: $PREFIX"
48+
FAIL=0
49+
for SHA in $COMMITS; do
50+
MSG=$(git log -1 --pretty=%s $SHA)
51+
echo "Checking commit $SHA: $MSG"
52+
if [[ "$MSG" != "$PREFIX"* ]]; then
53+
echo "❌ Commit $SHA must start with the required prefix: $PREFIX"
54+
FAIL=1
55+
fi
56+
done
57+
58+
if [[ $FAIL -eq 1 ]]; then
59+
echo "One or more commit messages are missing the required prefix."
60+
exit 1
61+
fi
62+
63+
echo "✅ All commits have the required prefix."

0 commit comments

Comments
 (0)