Skip to content

Commit 6d89033

Browse files
authored
ci: lint PR titles instead of individual commits (#495)
1 parent 1910e77 commit 6d89033

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

.github/workflows/basic.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ jobs:
3636
- name: Check typescript type validity
3737
run: npm run ts-lint
3838

39+
# Individual PR commits are NOT linted: PRs are squash-merged and the
40+
# PR title becomes the commit message, so the title is what must follow
41+
# the conventional-commit format (enforced by pr-title.yml). This
42+
# push-time check remains as a backstop for the squashed commits landing
43+
# on main and for direct pushes.
3944
- name: Validate current commit (last commit) with commitlint
4045
if: github.event_name == 'push'
4146
run: npx commitlint --last --verbose
42-
43-
- name: Validate PR commits with commitlint
44-
if: github.event_name == 'pull_request'
45-
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose

.github/workflows/pr-title.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: PR title
2+
3+
# PRs are squash-merged and the PR title becomes the commit message on main,
4+
# which release-please parses for versioning. Individual commits inside a PR
5+
# are free-form; the PR title is what must follow the conventional-commit
6+
# format. Runs on `edited` so fixing the title re-triggers the check.
7+
8+
on:
9+
pull_request:
10+
types: [opened, edited, synchronize, reopened]
11+
branches-ignore:
12+
- release-please-**
13+
14+
jobs:
15+
lint-pr-title:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v6
19+
20+
- uses: actions/setup-node@v6
21+
with:
22+
node-version: 'lts/*'
23+
cache: 'npm'
24+
25+
# Root-only install: commitlint and its config live in the root
26+
# devDependencies; the workspaces are not needed for this check.
27+
- name: Install commitlint
28+
run: npm ci --workspaces=false --ignore-scripts
29+
30+
- name: Validate PR title with commitlint
31+
env:
32+
PR_TITLE: ${{ github.event.pull_request.title }}
33+
run: printf '%s\n' "$PR_TITLE" | npx commitlint --verbose

0 commit comments

Comments
 (0)