-
Notifications
You must be signed in to change notification settings - Fork 1
52 lines (46 loc) · 1.92 KB
/
check_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
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: '^DEV-[0-9]+\ (feat|fix|refactor|chore|tests|docs|style|perf|build|ci|revert|deps)(\(.*\))?:\ '
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 prefix the title with the issue number followed by a space, a conventional commit prefix, and a colon (e.g. \"DEV-XXXX feat: \")"
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}")
if [[ ! "${commit_message}" =~ ${{ env.REGEX_VALIDATION_PATTERN }} ]]; then
echo "Error: Commit message in wrong format: \"${commit_message}\""
echo "Please prefix the commit message with the issue number followed by a space, a conventional commit prefix, and a colon (e.g. \"DEV-XXXX feat: \")"
exit 1
fi
done