22
33on :
44 push :
5- branches : [main, cpp-sequential ]
5+ branches : [main, dev ]
66 pull_request :
77 workflow_dispatch :
88
@@ -22,18 +22,33 @@ jobs:
2222 timeout-minutes : 10
2323 steps :
2424 - uses : actions/checkout@v4
25+ with :
26+ fetch-depth : 0 # need history to diff against the base ref
2527 - uses : actions/setup-python@v5
2628 with :
2729 python-version : ' 3.12'
28- cache : pip
29- - name : Install clang-format / cmake-format
30- run : |
31- sudo apt-get update
32- sudo apt-get install -y clang-format-17
33- sudo ln -sf "$(command -v clang-format-17)" /usr/local/bin/clang-format
3430 - run : pip install pre-commit
35- - name : pre-commit (all files)
36- run : pre-commit run --all-files --show-diff-on-failure
31+ # clang-format / cmake-format come pinned from their pre-commit mirrors,
32+ # so no apt install is needed. Lint only the files this PR/push changed,
33+ # so the existing tree is not retroactively reformatted; new work must
34+ # still satisfy every hook.
35+ - name : pre-commit (changed files)
36+ run : |
37+ set -e
38+ if [ "${{ github.event_name }}" = "pull_request" ]; then
39+ git fetch --no-tags --depth=1 origin "${{ github.base_ref }}"
40+ FROM="origin/${{ github.base_ref }}"
41+ else
42+ FROM="${{ github.event.before }}"
43+ fi
44+ if [ -z "$FROM" ] || [ "$FROM" = "0000000000000000000000000000000000000000" ] \
45+ || ! git cat-file -e "$FROM^{commit}" 2>/dev/null; then
46+ echo "No usable base ref — linting all files."
47+ pre-commit run --all-files --show-diff-on-failure
48+ else
49+ echo "Linting files changed in $FROM..HEAD"
50+ pre-commit run --from-ref "$FROM" --to-ref HEAD --show-diff-on-failure
51+ fi
3752
3853 # ----------------------------------------------------- CPU build + test ------
3954 cpu :
0 commit comments