Skip to content

Commit 8da4eff

Browse files
committed
ci: ensure that all the commits are linted by pre-commit hook
This commit ensures that all the commits are linted by pre-commit hook in a PR. Signed-off-by: vprashar2929 <[email protected]>
1 parent 0d0ca5f commit 8da4eff

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

.github/workflows/pr-checks.yaml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ jobs:
107107
steps:
108108
- name: Checkout source
109109
uses: actions/checkout@v3
110-
with:
111-
ref: ${{ github.event.pull_request.head.sha }}
112110

113111
- name: Setup Python
114112
uses: actions/setup-python@v3
@@ -119,11 +117,25 @@ jobs:
119117
- name: Run Pre-commit
120118
run: pre-commit run --all-files
121119

122-
- name: Run Commitlint
123-
run: |
124-
COMMIT_MSG=$(git log -1 --pretty=%B)
125-
echo "$COMMIT_MSG" > .git/COMMIT_EDITMSG
126-
pre-commit run commitlint --hook-stage commit-msg --commit-msg-file .git/COMMIT_EDITMSG
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.
123+
commit-msg-check:
124+
runs-on: ubuntu-latest
125+
steps:
126+
- name: Checkout source
127+
uses: actions/checkout@v4
128+
with:
129+
fetch-depth: 0 # Fetch all the history of PR commits
130+
131+
- name: Setup node
132+
uses: actions/setup-node@v4
133+
134+
- name: Install commitlint
135+
run: npm install @commitlint/cli @commitlint/config-conventional
136+
137+
- name: Validate PR commits
138+
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
127139

128140
build-images:
129141
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)