-
Notifications
You must be signed in to change notification settings - Fork 12
70 lines (59 loc) · 2.19 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
63
64
65
66
67
68
69
70
name: pre-commit
on:
push:
branches:
- main
pull_request:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true
env:
# renovate: datasource=pypi depName=pre-commit versioning=pep440
PRE_COMMIT_VERSION: ==2.20.0
jobs:
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check if pre-commit should run on all files
id: run-all-files
uses: fkirc/skip-duplicate-actions@f11521568414503656a5af807dc3018c012552c4 # tag=v5.2.0
continue-on-error: true
with:
do_not_skip: '["schedule", "workflow_dispatch"]'
paths: |-
[
".github/workflows/pre-commit.yml",
".pre-commit-config.yaml"
]
skip_after_successful_duplicate: false
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3.1.0
with:
fetch-depth: 0
- name: Set up pre-commit
run: pipx install "pre-commit${PRE_COMMIT_VERSION}"
- name: Set pre-commit cache key parts
run: |
echo "PY_HASH=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- name: Set up pre-commit cache
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # tag=v3.0.11
with:
path: ~/.cache/pre-commit
key: pre-commit-go-${{ env.PY_HASH }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit
run: |
declare -a EXTRA_ARGS=()
if [[ '${{ steps.run-all-files.outputs.should_skip }}' != 'true' ]]; then
EXTRA_ARGS=(--all-files)
elif [[ "${GITHUB_EVENT_NAME}" == 'pull_request' ]]; then
EXTRA_ARGS=(--from-ref "origin/${GITHUB_BASE_REF}" --to-ref "${GITHUB_SHA}")
else
EXTRA_ARGS=(--from-ref "${GITHUB_SHA}^" --to-ref "${GITHUB_SHA}")
fi
pre-commit run --show-diff-on-failure --color=always "${EXTRA_ARGS[@]}"
- name: 'pre-commit-ci-lite: Apply automatic fixes'
uses: pre-commit-ci/lite-action@50143aaf27e2c42e75a5e06185a471d9582e89df # v1.0.0
if: always()