Skip to content

Commit e3382ee

Browse files
Merge pull request #486 from ScriptedAlchemy/codex/commitlint-hook
ci: migrate commit linting
2 parents 495ba7d + 4048405 commit e3382ee

11 files changed

Lines changed: 1449 additions & 171 deletions

.githooks/commit-msg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
set -euo pipefail
33

44
repo_root="$(git rev-parse --show-toplevel)"
5-
"$repo_root/scripts/check-conventional-commits.sh" --message-file "$1"
5+
cd "$repo_root"
6+
7+
git stripspace --strip-comments < "$1" | npm run --silent lint:commit --

.github/conventional-commit-baseline.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ jobs:
2929
with:
3030
fetch-depth: 0
3131

32+
- uses: actions/setup-node@v4
33+
with:
34+
node-version: 22
35+
cache: npm
36+
37+
- name: Install commit message lint dependencies
38+
run: npm ci
39+
3240
- name: Reject tracked ignored files
3341
run: scripts/check-release-pr-integrity.sh HEAD HEAD
3442

@@ -37,7 +45,7 @@ jobs:
3745
env:
3846
BASE_SHA: ${{ github.event.pull_request.base.sha }}
3947
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
40-
run: scripts/check-conventional-commits.sh "$BASE_SHA..$HEAD_SHA"
48+
run: npm run lint:commit -- --from "$BASE_SHA" --to "$HEAD_SHA"
4149

4250
- name: Validate pushed commit messages
4351
if: github.event_name == 'push'
@@ -48,14 +56,13 @@ jobs:
4856
set -euo pipefail
4957
if [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
5058
if git rev-parse "${HEAD_SHA}^" >/dev/null 2>&1; then
51-
RANGE="${HEAD_SHA}^..${HEAD_SHA}"
59+
npm run lint:commit -- --from "${HEAD_SHA}^" --to "$HEAD_SHA"
5260
else
53-
RANGE="$HEAD_SHA"
61+
git show --no-patch --format=%B "$HEAD_SHA" | npm run lint:commit --
5462
fi
5563
else
56-
RANGE="${BEFORE_SHA}..${HEAD_SHA}"
64+
npm run lint:commit -- --from "$BEFORE_SHA" --to "$HEAD_SHA"
5765
fi
58-
scripts/check-conventional-commits.sh "$RANGE"
5966
6067
release-version-drift:
6168
name: Release Version Drift

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
2+
/node_modules/
23
.DS_Store
34
.codegraph
45
.tracedecay

AGENTS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ cargo test-all
3535

3636
## Git
3737

38-
- Every non-merge commit subject must pass `scripts/check-conventional-commits.sh` before push.
38+
- Every non-merge commit subject must pass
39+
`npm run lint:commit -- --from origin/master --to HEAD` before push.
3940
- Use `<type>: <subject>` or `<type>(<scope>): <subject>` with one of:
4041
`build`, `chore`, `ci`, `docs`, `feat`, `fix`, `perf`, `refactor`, `revert`, `style`, `test`.
4142
- Keep the subject at 72 characters or fewer. Example: `fix(doctor): avoid false orphan warnings`.

CONTRIBUTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,12 @@ scripts/install-git-hooks.sh
160160
CI validates commit subjects with:
161161

162162
```bash
163-
scripts/check-conventional-commits.sh origin/master..HEAD
163+
npm ci
164+
npm run lint:commit -- --from origin/master --to HEAD
164165
```
165166

166167
Run the same command locally before pushing to lint every non-merge commit in a
167-
branch range. Merge commits are skipped to match CI behavior.
168+
branch range. Commitlint exempts merge commits to match CI behavior.
168169

169170
## Pull Requests
170171

commitlint.config.cjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const allowedTypes = [
2+
"build",
3+
"chore",
4+
"ci",
5+
"docs",
6+
"feat",
7+
"fix",
8+
"perf",
9+
"refactor",
10+
"revert",
11+
"style",
12+
"test",
13+
];
14+
15+
module.exports = {
16+
defaultIgnores: false,
17+
ignores: [(message) => /^Merge[ \t]/.test(message)],
18+
parserPreset: {
19+
name: "tracedecay",
20+
parserOpts: {
21+
headerCorrespondence: ["type", "scope", "breaking", "subject"],
22+
headerPattern:
23+
/^(\w*)(?:\(([A-Za-z0-9._/-]+)\))?(!)?: ([^\s].*)$/,
24+
},
25+
},
26+
rules: {
27+
"header-max-length": [2, "always", 72],
28+
"subject-empty": [2, "never"],
29+
"type-empty": [2, "never"],
30+
"type-enum": [2, "always", allowedTypes],
31+
},
32+
};

0 commit comments

Comments
 (0)