-
Notifications
You must be signed in to change notification settings - Fork 15
62 lines (52 loc) · 1.72 KB
/
pre-commit.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
name: pre-commit
on:
push:
branches-ignore:
- 'master'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
pre-commit:
runs-on: ubuntu-latest
if: >-
!endsWith(github.event.head_commit.message, '# ci skip') &&
(
startsWith(github.ref, 'refs/heads') ||
github.event.pull_request.draft == false
)
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Cache pre-commit
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}-
- name: Run pre-commit
id: precommit
uses: pre-commit/[email protected]
continue-on-error: true
- name: Commit files
if: steps.precommit.outcome == 'failure' && startsWith(github.ref, 'refs/heads')
run: |
if [[ `git status --porcelain --untracked-files=no` ]]; then
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git checkout -- .github/workflows
git commit -m "pre-commit" -a
fi
shell: bash -ex {0}
- name: Push changes
if: steps.precommit.outcome == 'failure' && startsWith(github.ref, 'refs/heads')
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Check pre-commit
if: steps.precommit.outcome == 'failure'
uses: pre-commit/[email protected]