-
Notifications
You must be signed in to change notification settings - Fork 29
100 lines (81 loc) · 3.34 KB
/
Copy pathcommitmessage.yml
File metadata and controls
100 lines (81 loc) · 3.34 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Commit message check
on:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install commitlint
run: npm install -D @commitlint/cli @commitlint/config-conventional
- name: Validate all commits in PR
id: commitlint
run: |
MERGE_BASE=$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
npx commitlint --default-config --from "$MERGE_BASE" --to ${{ github.event.pull_request.head.sha }} --verbose
- name: Comment on PR if commitlint failed
if: failure() && steps.commitlint.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- commitlint-comment -->';
const body = `${marker}
⚠️ **Commit message check failed**
One or more commits in this PR don't follow [Conventional Commits](https://www.conventionalcommits.org/) format.
Each commit message should look like:
\`\`\`
type(optional-scope): subject
\`\`\`
Allowed types: \`build\`, \`chore\`, \`ci\`, \`docs\`, \`feat\`, \`fix\`, \`perf\`, \`refactor\`, \`revert\`, \`style\`, \`test\`
Example: \`fix(auth): correct token expiry check\` or \`fix: correct token expiry check\`
See the failed job logs for the specific commit(s) and rule(s) that failed.`;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.data.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Resolve PR comment if commitlint passed
if: success() && steps.commitlint.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- commitlint-comment -->';
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.data.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: `${marker}\n✅ **Commit message check passed** — all commits now follow Conventional Commits format.`,
});
}