-
Notifications
You must be signed in to change notification settings - Fork 1
117 lines (92 loc) · 3.69 KB
/
commitlint.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# validate either actual commits or pr title
# src: https://raw.githubusercontent.com/patternfly/patternfly-elements/24dd236afbbc90045165fd33ddaf036e56e26cd7/.github/workflows/commitlint.yml
name: commitlint
on:
pull_request:
types:
- opened
- edited
- labeled
- auto_merge_enabled
- synchronize
- reopened
- ready_for_review
pull_request_review:
types:
- submitted
jobs:
pr-title:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v5
id: commitlint
continue-on-error: true
with:
configFile: .commitlint.config.js
- name: Validate PR Title
id: prTitle
if: ${{ steps.commitlint.outcome == 'failure' }}
uses: aslafy-z/conventional-pr-title-action@v3.1.1
continue-on-error: true
with:
success-state: Title follows the conventional commit format.
failure-state: Please update the title to use conventional commit format.
context-name: conventional-pr-title
preset: '@commitlint/config-conventional@latest'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Format Commitlint Messages
id: format
if: ${{ steps.commitlint.outcome == 'failure' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const results = ${{ steps.commitlint.outputs.results }};
const titleGood = ${{ steps.prTitle.outcome == 'success' }};
const totalErrors = results.reduce((a, r) => a + r.errors.length, 0);
const totalWarnings = results.reduce((a, r) => a + r.warnings.length, 0);
const header = `
## ?? Commitlint Problems for this PR: ${!titleGood ? '' : `
**The PR title conforms to conventional commit style**
?? **Make sure the PR is squashed into a single commit using the PR title** ??`}
?? Found ${totalErrors} errors, ${totalWarnings} warnings
?? Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
`;
const comment = results.reduce((acc, result) => {
if (!result.errors.length && !result.warnings.length) {
return acc;
}
const [firstLine, ...rest] = result.message.split('\n');
const body = rest.join('\n').trim();
const icon = result.errors.length ? '?' : '??';
const hash = result.hash.substring(0, 8);
return `${acc} ${!body.length ? '\n\n' : `
<details><summary>`}
${hash} - ${firstLine} ${!body.length ? '\n\n' : `\
</summary>
${body}
</details>
`}${result.errors.map(error => `
- ? ${error}`).join('')} ${result.warnings.map(warn => `
- ?? ${warn}`).join('')}`;
}, header);
core.setOutput('comment', comment);
- name: Update PR
if: ${{ steps.commitlint.outcome == 'failure' && steps.prTitle.outcome == 'failure' }}
id: comment
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: commitlint
message: |
${{ steps.format.outputs.comment }}
- name: Fail Job on Error
if: ${{ steps.commitlint.outcome == 'failure' && steps.prTitle.outcome == 'failure' }}
uses: actions/github-script@v6
with:
script: |
core.setFailed("There were problems with this PR's commit messages")