Skip to content

Commit aac9f67

Browse files
root: ci: Add husky,commitlint.config.js& Update docs
fsfsdf
1 parent 022469e commit aac9f67

File tree

14 files changed

+1657
-355
lines changed

14 files changed

+1657
-355
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

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARG IMAGE_BASE=alpine:3.22.2@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c6
44
FROM ${IMAGE_BASE} AS image-base
55

66

7-
FROM --platform=${BUILDPLATFORM} golang:1.24.11@sha256:cf1272dbf972a94f39a81dcb9dc243a8d2f981e5dd3b5a5c965f6d9ab9268b26 AS backend-build
7+
FROM --platform=${BUILDPLATFORM} golang:1.24.11@sha256:28252a22a79f4995895749d69853d4c8f750167bd94113ae4da4a570ec5ce7b2 AS backend-build
88

99
WORKDIR /headlamp
1010

@@ -28,7 +28,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
2828
--mount=type=cache,target=/go/pkg/mod \
2929
cd ./backend && go build -o ./headlamp-server ./cmd/
3030

31-
FROM --platform=${BUILDPLATFORM} node:22@sha256:4ad2c2b350ab49fb637ab40a269ffe207c61818bb7eb3a4ea122001a0c605e1f AS frontend-build
31+
FROM --platform=${BUILDPLATFORM} node:22@sha256:379c51ac7bbf9bffe16769cfda3eb027d59d9c66ac314383da3fcf71b46d026c AS frontend-build
3232

3333
# We need .git and app/ in order to get the version and git version for the frontend/.env file
3434
# that's generated when building the frontend.

Dockerfile.plugins

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the plugin
2-
FROM node:22@sha256:4ad2c2b350ab49fb637ab40a269ffe207c61818bb7eb3a4ea122001a0c605e1f as builder
2+
FROM node:22@sha256:379c51ac7bbf9bffe16769cfda3eb027d59d9c66ac314383da3fcf71b46d026c as builder
33

44
# Set the working directory
55
WORKDIR /headlamp-plugins

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)