-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (73 loc) · 2.76 KB
/
Copy pathcommitlint.yml
File metadata and controls
86 lines (73 loc) · 2.76 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
84
85
86
name: Commitlint
on:
pull_request:
types: [opened, edited, synchronize, reopened, ready_for_review]
permissions:
pull-requests: read
jobs:
commitlint:
name: Commitlint
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Validate commit messages
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
TRUSTED_AUTOMATION_USERS: dependabot[bot]
with:
script: |
const pr = context.payload.pull_request;
const trustedAutomationUsers = (process.env.TRUSTED_AUTOMATION_USERS || '')
.split(',')
.map((login) => login.trim())
.filter(Boolean);
if (trustedAutomationUsers.includes(pr.user.login)) {
core.info(`Commit message validation is delegated for trusted automation @${pr.user.login}.`);
return;
}
const allowedTypes = new Set([
'feat',
'fix',
'docs',
'style',
'refactor',
'test',
'chore',
'perf',
'revert',
]);
const commits = await github.paginate(github.rest.pulls.listCommits, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
per_page: 100,
});
const failures = [];
for (const commit of commits) {
const shortSha = commit.sha.slice(0, 7);
const subject = commit.commit.message.split('\n')[0];
const match = subject.match(/^([a-z]+)(?:\(([a-z0-9._-]+)\))?(!)?: (.+)$/u);
if (subject.length > 72) {
failures.push(`${shortSha}: first line is ${subject.length} chars; max is 72`);
continue;
}
if (!match) {
failures.push(`${shortSha}: '${subject}' is not Conventional Commits format`);
continue;
}
const [, type, , , description] = match;
if (!allowedTypes.has(type)) {
failures.push(`${shortSha}: unsupported type '${type}'`);
}
if (/^[A-Z]/.test(description)) {
failures.push(`${shortSha}: subject must not start with a capital letter`);
}
if (description.endsWith('.')) {
failures.push(`${shortSha}: subject must not end with a period`);
}
}
if (failures.length > 0) {
core.setFailed(`Commit message validation failed:\n- ${failures.join('\n- ')}`);
} else {
core.info('All commit messages follow Conventional Commits.');
}