Skip to content

Commit 6c26e63

Browse files
committed
chore: switch to commitlint.js for checking the commit msgs in CI
This allows us to have some control over what is an allowed commit message. This is important since some, like those from renovate, will be over the other tools 72 character limit.
1 parent a1b7bee commit 6c26e63

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

.github/workflows/commitlint.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
name: Conventional Commitlint
1+
name: Commit Linter
22

33
on:
44
push:
55
branches: ["main"]
66
pull_request:
77

8+
permissions:
9+
contents: read
10+
pull-requests: read
811
jobs:
912
commitlint:
1013
runs-on: ubuntu-latest
@@ -13,5 +16,23 @@ jobs:
1316
contents: read
1417
pull-requests: read
1518
steps:
16-
- name: Conventional Commitlint
17-
uses: opensource-nepal/commitlint@v1
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- name: Setup node
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: lts/*
26+
cache: npm
27+
- name: Install commitlint
28+
run: npm install -D @commitlint/cli @commitlint/config-conventional
29+
- name: Print versions
30+
run: |
31+
git --version
32+
node --version
33+
npm --version
34+
npx commitlint --version
35+
36+
- name: Validate PR commits with commitlint
37+
if: github.event_name == 'pull_request'
38+
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ rebar3.crashdump
2020
doc
2121
!_index.md
2222
guides
23+
# don't commit the stuff required for commitlint to work
24+
node_modules
25+
package-lock.json
26+
package.json

commitlint.config.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
RuleConfigCondition,
3+
RuleConfigSeverity,
4+
TargetCaseType,
5+
} from "@commitlint/types";
6+
7+
export default {
8+
parserPreset: "conventional-changelog-conventionalcommits",
9+
rules: {
10+
"body-leading-blank": [RuleConfigSeverity.Warning, "always"] as const,
11+
"body-max-line-length": [RuleConfigSeverity.Error, "always", 100] as const,
12+
"footer-leading-blank": [RuleConfigSeverity.Warning, "always"] as const,
13+
"footer-max-line-length": [
14+
RuleConfigSeverity.Error,
15+
"always",
16+
100,
17+
] as const,
18+
"header-max-length": [RuleConfigSeverity.Error, "always", 100] as const,
19+
"header-trim": [RuleConfigSeverity.Error, "always"] as const,
20+
"subject-case": [
21+
RuleConfigSeverity.Error,
22+
"never",
23+
["sentence-case", "start-case", "pascal-case", "upper-case"],
24+
] as [RuleConfigSeverity, RuleConfigCondition, TargetCaseType[]],
25+
"subject-empty": [RuleConfigSeverity.Error, "never"] as const,
26+
"subject-full-stop": [RuleConfigSeverity.Error, "never", "."] as const,
27+
"type-case": [RuleConfigSeverity.Error, "always", "lower-case"] as const,
28+
"type-empty": [RuleConfigSeverity.Error, "never"] as const,
29+
"type-enum": [
30+
RuleConfigSeverity.Error,
31+
"always",
32+
[
33+
"chore",
34+
"feat",
35+
"fix",
36+
],
37+
] as [RuleConfigSeverity, RuleConfigCondition, string[]],
38+
},
39+
};

justfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ changelogs:
88
git cliff 29b747722addf39ce40014ee1a905a973c9044be.. --include-path "${dir}/**" --workdir ${dir} -o ${dir}/CHANGELOG.md
99
fi
1010
done
11+
12+
# lint the commits between HEAD and the point from `origin/main` this branch was created from
13+
commit-lint:
14+
npm install -D @commitlint/cli @commitlint/config-conventional
15+
npx commitlint --verbose --from `git merge-base --fork-point origin/main` --to HEAD

0 commit comments

Comments
 (0)