Skip to content

Commit 35de70e

Browse files
root: ci: Add husky,commitlint.config.js& Update docs
fsfsdf Restoring the changes
1 parent d36a68d commit 35de70e

File tree

8 files changed

+1588
-311
lines changed

8 files changed

+1588
-311
lines changed

.github/workflows/lint-commit.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint Commit Messages
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
lint-commit:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
with:
11+
fetch-depth: 0
12+
- name: Setup Node.js
13+
uses: actions/setup-node@v4
14+
with:
15+
node-version: '20'
16+
cache: "npm"
17+
cache-dependency-path: package-lock.json
18+
- name: Install dependencies
19+
run: npm ci
20+
- name: Lint commit messages
21+
run: npm run lint:commit

commitlint.config.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module.exports = {
2+
plugins: [
3+
{
4+
rules: {
5+
'headlamp-format': ({ header }) => {
6+
if (!header) {
7+
return [false, 'Commit message header must not be empty'];
8+
}
9+
if (/ :/.test(header)) {
10+
return [false, 'There should be no space before ":"'];
11+
}
12+
const parts = header.split(':').map(p => p.trim());
13+
if (parts.length < 2) {
14+
return [
15+
false,
16+
'Commit message must follow format: <area>: <description>',
17+
];
18+
}
19+
const [area, subOrDesc] = parts;
20+
if (!area) {
21+
return [false, 'Area must not be empty'];
22+
}
23+
if (!subOrDesc) {
24+
return [false, 'Description or sub-area must not be empty'];
25+
}
26+
const strictAreas = ['app', 'frontend', 'backend'];
27+
if (strictAreas.includes(area.toLowerCase()) && parts.length < 3) {
28+
return [
29+
false,
30+
`Commits starting with "${area}" must follow format: ` +
31+
`<${area}>: <sub-area>: <description>\n` +
32+
`Example: "${area}: HomeButton: Fix navigation"`,
33+
];
34+
}
35+
const description =
36+
parts.length >= 3 ? parts.slice(2).join(': ') : parts[1];
37+
if (!description) {
38+
return [false, 'Description must not be empty'];
39+
}
40+
if (description[0] !== description[0].toUpperCase()) {
41+
return [false, 'Description must start with a capitalized verb'];
42+
}
43+
return [true, ''];
44+
},
45+
},
46+
},
47+
],
48+
49+
rules: {
50+
'headlamp-format': [2, 'always'],
51+
'header-max-length': [2, 'always', 72],
52+
'body-max-line-length': [2, 'always', 72],
53+
},
54+
};

docs/contributing.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ dedicated [i18n docs](./development/i18n).
185185
For general guidelines on making PRs/commits easier to review, please check
186186
out Kinvolk's
187187
[contribution guidelines on git](https://github.com/kinvolk/contribution/tree/master/topics/git.md).
188+
We also use `commitlint` to enforce these guidelines automatically. You can check your commits locally by running:
189+
190+
```bash
191+
npm run lint:commit
192+
```
193+
194+
This command checks all commit messages that exist after origin/main against our guidelines. The same check runs in our CI system for every Pull Request.
188195

189196
## Testing
190197

0 commit comments

Comments
 (0)