-
Notifications
You must be signed in to change notification settings - Fork 4
98 lines (90 loc) · 3.39 KB
/
commit-lint.yaml
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
---
name: Lint Commit Messages
on:
pull_request:
merge_group:
jobs:
commit-lint:
runs-on:
group: infra1-runners-arc
labels: runners-small
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v4
- run: |
set -eu
cat << EOF > commitlint.config.mjs
/* eslint-disable import/no-extraneous-dependencies */
import { maxLength } from '@commitlint/ensure';
import { default as conventionalConfig } from '@commitlint/config-conventional';
import { execSync } from 'child_process';
import toLines from '@commitlint/to-lines';
const headerMaxLength = 70;
const validateHeaderMaxLengthIgnoringDeps = (parsedCommit) => {
const { type, scope, header } = parsedCommit;
const isDepsCommit = type === 'chore' && scope === 'deps';
return [
isDepsCommit || maxLength(header, headerMaxLength),
\`header must not be longer than \${headerMaxLength}\`,
];
}
const validateRisk = process.env.GITHUB_REPOSITORY?.match(/gooddata\/(gdc-nas|gdc-ui|gooddata-ui-sdk|gdc-panther)/)
export default {
extends: ['@commitlint/config-conventional'],
plugins: [
'commitlint-plugin-function-rules',
{
rules: {
'risk-rule': (parsedCommit) => {
const { type, subject } = parsedCommit;
if (type === 'chore' && subject?.startsWith('update')) return [true]; // skip renovate and extimage bumps
try {
const trailers = execSync('git interpret-trailers --parse', {
input: parsedCommit.raw || '',
}).toString();
const matches = toLines(trailers)?.filter((ln) => ln.match(/^risk:\s*(nonprod|low|high)/i))?.length;
return [
matches === 1,
\`Should have exactly one risk label of value nonprod|low|high, but \${matches} found.\`,
];
} catch (err) {
console.error(err.toString());
return [false, 'Error while trying to find risk label'];
}
},
},
},
],
rules: {
'header-max-length': [0],
'body-max-line-length': [0],
'function-rules/header-max-length': [
2,
'always',
validateHeaderMaxLengthIgnoringDeps,
],
'subject-case': [
2,
'never',
['upper-case', 'camel-case', 'kebab-case', 'pascal-case', 'snake-case'],
],
'type-enum': [
2,
'always',
[
...conventionalConfig.rules['type-enum'][2], // Include default types
'config', // Configuration change i.e. hiera or gitops config change
],
],
'risk-rule': [
validateRisk ? 2 : 0,
'always',
],
},
}
EOF
cat commitlint.config.mjs
shell: bash
- uses: wagoid/commitlint-github-action@v6