forked from espressif/arduino-esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (78 loc) · 2.79 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Pre-commit check
on:
pull_request_target:
types: [opened, reopened, synchronize, labeled, unlabeled]
jobs:
lint:
if: |
contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge')
name: Checking if any fixes are needed
runs-on: ubuntu-latest
steps:
- name: Checkout latest commit
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Get Python version hash
run: |
echo "Using $(python -VV)"
echo "PY_HASH=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- name: Restore pre-commit cache
uses: actions/cache/restore@v4
id: restore-cache
with:
path: |
~/.cache/pre-commit
~/.cache/pip
key: pre-commit|${{ env.PY_HASH }}|${{ hashFiles('.pre-commit-config.yaml', '.github/workflows/pre-commit.yml') }}
- name: Install python dependencies
run: python -m pip install pre-commit docutils
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected]
- name: Run pre-commit hooks in changed files
run: pre-commit run --color=always --show-diff-on-failure --files ${{ steps.changed-files.outputs.all_changed_files }}
- name: Save pre-commit cache
uses: actions/cache/save@v4
if: ${{ always() && steps.restore-cache.outputs.cache-hit != 'true' }}
continue-on-error: true
with:
path: |
~/.cache/pre-commit
~/.cache/pip
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
- name: Push changes using pre-commit-ci-lite
uses: pre-commit-ci/[email protected]
if: always()
with:
msg: "ci(pre-commit): Apply automatic fixes"
report-run:
name: Check if the PR has run the pre-commit checks
permissions:
statuses: write
needs: lint
if: always()
runs-on: ubuntu-latest
steps:
- name: Report success
if: |
contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') &&
needs.lint.result == 'success'
uses: conda/actions/[email protected]
with:
context: pre-commit-result
state: success
description: All pre-commit checks passed
- name: Report pending
if: |
!contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') ||
needs.lint.result == 'failure'
uses: conda/actions/[email protected]
with:
context: pre-commit-result
state: pending
description: The pre-commit checks need to be successful before merging