Skip to content

Commit 530d3e2

Browse files
committed
Add workflow to check pull request title for correct prefix
1 parent 121c6b8 commit 530d3e2

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Ensure PR title has correct prefix
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
check-pr-summary:
13+
name: Check if PR title has a good prefix
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
pull-requests: read
18+
steps:
19+
- name: Check PR title
20+
env:
21+
PR_TITLE: ${{ github.event.pull_request.title }}
22+
run: |
23+
echo "Pull request title='${PR_TITLE}'"
24+
good_prefixes="feat fix security notice chore docs ci test"
25+
good_prefix_arr=($good_prefixes)
26+
if [[ "${PR_TITLE}" =~ ^(.+?)\:.+ ]]; then
27+
prefix=${BASH_REMATCH[1]}
28+
echo "prefix: ${prefix}"
29+
prefix_without_parens=$(echo "${prefix}" |cut -d'(' -f1)
30+
echo "prefix without parens = ${prefix_without_parens}"
31+
for good_prefix in "${good_prefix_arr[@]}"
32+
do
33+
if [[ "${prefix_without_parens}" == "${good_prefix}" ]]; then
34+
echo "prefix is good"
35+
exit 0
36+
fi
37+
done
38+
echo "Commit title prefix ${prefix_without_parens} is not valid"
39+
echo "Prefix must be one of ${good_prefixes}"
40+
exit 1
41+
else
42+
echo "Invalid PR title. Must begin with a prefix (e.g. "feat: blah blah"), and the prefix must be one of ${good_prefixes}"
43+
exit 1
44+
fi
45+
shell: bash

0 commit comments

Comments
 (0)