-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (78 loc) · 2.45 KB
/
Copy pathpr-validation.yaml
File metadata and controls
83 lines (78 loc) · 2.45 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: PR validation
on:
pull_request:
types: [opened, edited, synchronize]
branches: [develop, main]
permissions:
contents: read
pull-requests: read
jobs:
pr-title:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feat
fix
docs
style
refactor
perf
test
chore
ci
build
requireScope: false
subjectPattern: ^[a-z].+[^.]$
subjectPatternError: |
The subject "{subject}" must start lowercase and not end with a period.
commit-messages:
name: Validate commit messages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Check each commit against docs/git-commits.md
env:
BASE: ${{ github.event.pull_request.base.sha }}
HEAD: ${{ github.event.pull_request.head.sha }}
run: |
types='feat|fix|docs|style|refactor|perf|test|chore|ci|build'
pattern="^(${types})(\([a-z0-9-]+\))?!?: [a-z].{0,70}$"
fail=0
while read -r sha; do
subj=$(git log -1 --format=%s "$sha")
case "$subj" in
"Merge "*|"Revert "*) continue ;;
esac
if ! echo "$subj" | grep -qE "$pattern"; then
echo "::error::invalid commit subject: $subj"
fail=1
fi
done < <(git rev-list "$BASE..$HEAD")
exit $fail
issue-reference:
name: Check issue reference
runs-on: ubuntu-latest
steps:
- name: Verify PR references an issue
if: github.event.pull_request.base.ref == 'develop'
env:
PR_BODY: ${{ github.event.pull_request.body }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
if echo "$PR_TITLE" | grep -qiE '^(chore|style)\b'; then
echo "Trivial PR (chore/style) — issue reference not required."
exit 0
fi
if echo "$PR_BODY" | grep -qiE '(close[sd]?|fix(e[sd])?|resolve[sd]?)\s+#[0-9]+'; then
echo "Issue reference found."
exit 0
fi
echo "::error::PR must reference a GitHub issue in the body (e.g. 'Closes #12'). See docs/git-workflow.md."
exit 1