Skip to content

Commit 6f0db9a

Browse files
committed
Run pre-commit on changed files in CI
1 parent 6711875 commit 6f0db9a

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

.github/workflows/pre-commit.yaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
name: pre-commit
22

33
on:
4+
workflow_dispatch:
45
pull_request:
6+
branches:
7+
- pybind11
58
push:
9+
branches:
10+
- pybind11
611

712
jobs:
813
pre-commit:
914
runs-on: ubuntu-22.04
1015
steps:
11-
- uses: actions/checkout@v3
12-
- uses: actions/setup-python@v4
16+
- uses: actions/checkout@v4
1317
with:
14-
python-version: '3.10'
15-
- uses: pre-commit/action@v3.0.0
18+
fetch-depth: 0
19+
20+
- uses: actions/setup-python@v5
1621
with:
17-
extra_args: "--all-files"
22+
python-version: '3.10'
23+
24+
- name: Install pre-commit
25+
run: python -m pip install pre-commit
26+
27+
- name: Run pre-commit on changed files
28+
shell: bash
29+
run: |
30+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
31+
base_ref="${{ github.event.pull_request.base.sha }}"
32+
elif [[ -n "${{ github.event.before }}" && ! "${{ github.event.before }}" =~ ^0+$ ]]; then
33+
base_ref="${{ github.event.before }}"
34+
else
35+
base_ref="$(git rev-parse HEAD~1)"
36+
fi
37+
38+
pre-commit run --show-diff-on-failure --color=always --from-ref "$base_ref" --to-ref "${{ github.sha }}"

0 commit comments

Comments
 (0)