-
Notifications
You must be signed in to change notification settings - Fork 1
53 lines (47 loc) · 2.36 KB
/
pr_meta.yml
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: Check Pull Request Meta
on:
pull_request:
types:
- opened
- synchronize
- edited
jobs:
check-pr-meta:
runs-on: ubuntu-20.04
env:
REGEX_VALIDATION_PATTERN: '^(feat|themes|highlights|utils|plugins|config|fix|refactor|chore|tests|docs|style|perf|build|ci|revert|deps)(\(.*\))?(!)?:\ .*\ \(DEV-[0-9]+\)$'
steps:
- name: Check PR Title
if: github.event_name == 'pull_request'
env:
PR_TITLE: "${{ github.event.pull_request.title }}"
run: |
# Check PR Title
if ! echo "$PR_TITLE" | grep --perl-regexp --quiet "${{ env.REGEX_VALIDATION_PATTERN }}"
then
echo "Error: PR title in wrong format: \"$PR_TITLE\""
echo "Please suffix the title with the issue number followed by a space, a conventional commit prefix, and a colon (e.g. feat: <commit message> (DEV-XXXX))"
exit 1
fi
- name: Checkout Code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check PR Commit Messages
run: |
# Check PR Commit Messages
commit_range=""
if [ "${{ github.event_name }}" == "push" ]; then
commit_range="${{ github.event.before }}..${{ github.event.after }}"
elif [ "${{ github.event_name }}" == "pull_request" ]; then
commit_range="${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"
fi
for commit_sha in $(git rev-list --no-merges "${commit_range}"); do
commit_message=$(git log --format=%B -n 1 "${commit_sha}" | head -n 1)
echo "Checking commit message: \"${commit_message}\""
if [[ ! "${commit_message}" =~ ${{ env.REGEX_VALIDATION_PATTERN }} ]]; then
echo "Error: Commit message in wrong format: \"${commit_message}\""
echo "Please suffix the commit message with the issue number followed by a space, a conventional commit prefix, and a colon (e.g. feat: <commit message> (DEV-XXXX))"
exit 1
fi
done