Skip to content

Commit a62cf34

Browse files
author
Sunil Thaha
authored
Merge pull request #2188 from vprashar2929/ci-comm-lint-1
ci: use custom hook for linting PR commits
2 parents ffdfb2b + 7343141 commit a62cf34

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

.github/workflows/pr-checks.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ jobs:
117117
- name: Run Pre-commit
118118
run: pre-commit run --all-files
119119

120-
# Using vanilla commitlint instead of running via pre-commit because pre-commit
121-
# hooks are meant to run on the commit-msg hook which will only run at the time of commit creation.
122-
# Also it will only validate the current commit message, not the entire commit history.
123120
commit-msg-check:
124121
runs-on: ubuntu-latest
125122
steps:
@@ -128,14 +125,14 @@ jobs:
128125
with:
129126
fetch-depth: 0 # Fetch all the history of PR commits
130127

131-
- name: Setup node
132-
uses: actions/setup-node@v4
133-
134-
- name: Install commitlint
135-
run: npm install @commitlint/cli @commitlint/config-conventional
128+
- name: Setup Pre-commit
129+
run: pip install pre-commit
136130

137-
- name: Validate PR commits
138-
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
131+
- name: Run Pre-commit
132+
run: pre-commit run --hook-stage manual pr-commit-lint --all-files
133+
env:
134+
FROM: ${{ github.event.pull_request.base.sha }}
135+
TO: ${{ github.event.pull_request.head.sha }}
139136

140137
build-images:
141138
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ default_install_hook_types:
22
- pre-commit
33
- commit-msg
44
repos:
5+
# This hook lints commit messages within a specified range, ideal for validating all commits in a PR.
6+
# Environment variables $FROM (start of range) and $TO (end of range) are set in PR Checks workflow.
7+
- repo: local
8+
hooks:
9+
- id: pr-commit-lint
10+
name: pr-commit-lint
11+
stages: [manual]
12+
language: node
13+
additional_dependencies:
14+
- "@commitlint/cli"
15+
- "@commitlint/config-conventional"
16+
pass_filenames: false
17+
entry: bash -c "commitlint --from $FROM --to $TO --verbose"
18+
519
- repo: https://github.com/pre-commit/pre-commit-hooks
620
rev: v5.0.0
721
hooks:

0 commit comments

Comments
 (0)