-
Notifications
You must be signed in to change notification settings - Fork 1
48 lines (41 loc) · 1.53 KB
/
pre-commit.yml
File metadata and controls
48 lines (41 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: Pre-commit
"on":
push:
branches: [master]
pull_request:
branches: [master]
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'
- name: Install pre-commit
run: pip install pre-commit
- name: Cache pre-commit hooks
uses: actions/cache@v5
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
pre-commit-
- name: Run commit-msg hooks for PR commits
if: github.event_name == 'pull_request'
run: |
echo "Running commit-msg hooks for all commits in the PR"
# iterate commits in the PR and run commit-msg hook against each message
git --no-pager log --pretty=format:%H origin/${{ github.event.pull_request.base.ref }}..HEAD | while read commit; do
echo "Checking commit $commit"
# write message into .git/COMMIT_EDITMSG so commitlint and other tools can read it
git show --no-patch --format=%B $commit > .git/COMMIT_EDITMSG
pre-commit run --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG --verbose || exit 1
rm -f .git/COMMIT_EDITMSG
done
- name: Run pre-commit (skip Rust hooks)
run: SKIP=fmt,clippy pre-commit run --all-files --verbose