Repository navigation
49 lines (42 loc) · 1.62 KB
/
Copy pathconventional-commits.yml
File metadata and controls
49 lines (42 loc) · 1.62 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
name: Conventional Commits
on:
pull_request:
branches: [ main ]
types: [ opened, edited, synchronize, reopened, ready_for_review ]
permissions:
contents: read
pull-requests: read
jobs:
validate:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- name: Validate PR title and commits
uses: actions/github-script@v9
with:
script: |
const allowed = /^(build|chore|ci|deps|docs|feat|fix|perf|refactor|revert|style|test)(\([A-Za-z0-9._/-]+\))?!?: .+$/;
const allowedSpecial = /^(Merge .+|Revert ".+")$/;
const failures = [];
const title = context.payload.pull_request.title;
if (!allowed.test(title) && !allowedSpecial.test(title)) {
failures.push(`PR title: ${title}`);
}
// Only the PR title is validated. Linting every intermediate commit too broke
// automated PRs whose fixup commits (e.g. from Copilot's CI-failure auto-fix)
// aren't conventional themselves, even though the PR title is compliant.
if (failures.length > 0) {
core.setFailed([
'Conventional Commit validation failed.',
'',
'Expected format:',
' type(scope): description',
' type: description',
'',
'Allowed types:',
' build, chore, ci, deps, docs, feat, fix, perf, refactor, revert, style, test',
'',
'Failures:',
...failures.map(f => ` - ${f}`),
].join('\n'));
}