Skip to content

Commit 5cad2be

Browse files
authored
Merge pull request #513 from ginglis13/add-commitlint
ci: add commitlint workflow for PR commit messages
2 parents 3f586cd + 7ddbd6b commit 5cad2be

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

.commitlint.config.mjs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* [commitlint](https://github.com/conventional-changelog/commitlint) configuration
2+
*
3+
* Bottlerocket kit repos use a `scope: description` convention where the scope
4+
* is typically a package name (e.g. `kernel-6.12: update to 6.12.94`) or an
5+
* area (e.g. `changelog: add release notes for v7.1.0`).
6+
*
7+
* This differs from standard Conventional Commits which require a fixed type
8+
* prefix (feat, fix, etc.). We enforce the structural rules (colon separator,
9+
* line lengths, casing) while allowing any lowercase scope before the colon.
10+
*/
11+
import { RuleConfigSeverity } from "@commitlint/types";
12+
13+
// Custom plugin to validate the "scope: description" format used in kit repos.
14+
const kitScopePlugin = {
15+
rules: {
16+
// Validates that the header matches `lowercase-scope: lowercase description`
17+
"kit-scope-format": (parsed, _when, _value) => {
18+
const header = parsed.header;
19+
// Match: one or more lowercase words/numbers/dots/dashes, colon, space, then description
20+
const pattern = /^[a-z][a-z0-9._-]*: .+$/;
21+
return [
22+
pattern.test(header),
23+
"header must match the format 'scope: description' (e.g. 'kernel-6.12: update to 6.12.94')",
24+
];
25+
},
26+
},
27+
};
28+
29+
export default {
30+
plugins: [kitScopePlugin],
31+
rules: {
32+
// Structural rules
33+
"header-max-length": [RuleConfigSeverity.Error, "always", 72],
34+
"header-trim": [RuleConfigSeverity.Error, "always"],
35+
"body-max-line-length": [RuleConfigSeverity.Error, "always", 72],
36+
"body-leading-blank": [RuleConfigSeverity.Error, "always"],
37+
38+
// Subject rules (applied to text after the colon)
39+
"subject-full-stop": [RuleConfigSeverity.Error, "never", "."],
40+
41+
// Custom kit scope format
42+
"kit-scope-format": [RuleConfigSeverity.Error, "always"],
43+
},
44+
ignores: [
45+
(message) => message.includes("Merge pull request #"),
46+
(message) => message.startsWith("Revert \""),
47+
],
48+
};

.github/workflows/commitlint.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Lint Commit Messages
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- edited
8+
- reopened
9+
- synchronize
10+
11+
jobs:
12+
commitlint:
13+
if: github.repository == 'bottlerocket-os/bottlerocket-kernel-kit'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
- name: Setup Node
20+
uses: actions/setup-node@v4
21+
- name: Install commitlint
22+
run: npm install @commitlint/cli @commitlint/types
23+
- name: Lint commits in PR
24+
env:
25+
WORKSPACE: ${{ github.workspace }}
26+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
27+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
28+
run: |
29+
npx commitlint \
30+
-g "${WORKSPACE}/.commitlint.config.mjs" \
31+
--from "${BASE_SHA}" \
32+
--to "${HEAD_SHA}" \
33+
--verbose

0 commit comments

Comments
 (0)