-
Notifications
You must be signed in to change notification settings - Fork 16
65 lines (54 loc) · 2.41 KB
/
pr_precommit.yml
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
name: PR pre-commit
on:
push:
branches:
- main
pull_request_target:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
pre-commit:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: tj-actions/changed-files@v45
id: changed-files
- name: List changed files
run: echo '${{ steps.changed-files.outputs.all_changed_files }}'
# only check the full repository if PR and correctly labelled
- if: ${{ github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'full pre-commit') }}
name: Full pre-commit
uses: pre-commit/[email protected]
with:
extra_args: --all-files
- if: ${{ github.event_name != 'pull_request_target' || !contains(github.event.pull_request.labels.*.name, 'full pre-commit') }}
name: Local pre-commit
uses: pre-commit/[email protected]
with:
extra_args: --files ${{ steps.changed-files.outputs.all_changed_files }}
# push fixes if pre-commit fails and PR is eligible
- if: ${{ failure() && github.event_name == 'pull_request_target' && github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'stop pre-commit fixes')}}
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.PR_APP_ID }}
private-key: ${{ secrets.PR_APP_KEY }}
- if: ${{ failure() && github.event_name == 'pull_request_target' && !github.event.pull_request.draft && !contains(github.event.pull_request.labels.*.name, 'stop pre-commit fixes') }}
name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
token: ${{ steps.app-token.outputs.token }}
- if: ${{ failure() && github.event_name == 'pull_request_target' && github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'stop pre-commit fixes')}}
name: Push pre-commit fixes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Automatic `pre-commit` fixes
commit_user_name: tsml-actions-bot[bot]