-
Notifications
You must be signed in to change notification settings - Fork 744
91 lines (74 loc) · 2.58 KB
/
Copy pathprecommit.yml
File metadata and controls
91 lines (74 loc) · 2.58 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Changed Files Pre-Commit Check
on:
push:
pull_request:
permissions:
contents: write
env:
PRE_COMMIT_COLOR: always
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout repository for main repository
if: github.event_name != 'pull_request'
uses: actions/checkout@v6
with:
fetch-depth: 10
- name: Check PR repository
uses: actions/checkout@v6
if: github.event_name == 'pull_request'
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 10
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.13"
cache: pip
- name: Install pre-commit
run: pip install pre-commit
- id: changed-files
name: Determine changed files
if: github.event_name == 'pull_request'
uses: dorny/paths-filter@v4
with:
token: ${{ github.token }}
list-files: shell
filters: |
repo:
- added|modified: ['**']
- name: Generate cache key
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- name: Cache pre-commit environments
uses: actions/cache@v5
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit (allow autofixes) for PR
if: github.event_name == 'pull_request'
run: |
pre-commit run --files ${{ steps.changed-files.outputs.repo_files }} || true
- name: Commit fixes for PR
if: github.event_name == 'pull_request'
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: "apply pre-commit fixes for PR"
- name: Verify pre-commit passes for PR
if: github.event_name == 'pull_request'
run: |
pre-commit run --files ${{ steps.changed-files.outputs.repo_files }}
- name: Run pre-commit on Push
if: github.event_name != 'pull_request'
run: |
pre-commit run --all-files
# - name: Commit fixes on Push
# if: github.event_name != 'pull_request'
# uses: stefanzweifel/git-auto-commit-action@v7
# with:
# commit_message: "apply pre-commit fixes"
#- name: Verify pre-commit passes for Push
# if: github.event_name != 'pull_request'
# run: |
# pre-commit run --files ${{ steps.changed-files.outputs.repo_files }}