-
Notifications
You must be signed in to change notification settings - Fork 1.5k
57 lines (55 loc) · 2.17 KB
/
pre-commit.yml
File metadata and controls
57 lines (55 loc) · 2.17 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
name: pre-commit
on:
pull_request:
push:
permissions: {}
jobs:
detect-precommit:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
precommits: ${{ steps.find-precommit.outputs.precommits }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Find precommit configurations
id: find-precommit
working-directory: .
run: |
PRECOMMITS=$(find . -name ".pre-commit-config.yaml" -exec dirname {} \; | sed 's/^\.\///' | jq -R -s -c 'split("\n")[:-1]')
echo "precommits=$PRECOMMITS" >> $GITHUB_OUTPUT
pre-commit:
needs: [detect-precommit]
if: ${{ needs.detect-precommit.outputs.precommits != '[]' && needs.detect-precommit.outputs.precommits != '' }}
strategy:
fail-fast: false
matrix:
precommit: ${{ fromJson(needs.detect-precommit.outputs.precommits) }}
name: Precommit ${{ matrix.precommit }}
defaults:
run:
shell: bash
working-directory: ${{ matrix.precommit }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 #v6.2.0
with:
python-version-file: ${{ matrix.precommit }}/.python-version
- run: |
echo "github.workspace=${{ github.workspace }}"
echo "env.GITHUB_WORKSPACE=${{ env.GITHUB_WORKSPACE }}"
echo "vars.GITHUB_WORKSPACE=${{ vars.GITHUB_WORKSPACE }}"
python -m pip install --require-hashes --requirement ${{ github.workspace }}/.github/workflows/pre-commit-requirements.txt
python -m pip freeze --local
- uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 #v5.0.3
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ runner.os }}|${{ hashFiles(matrix.precommit) }}
- name: Set SKIP variable for main branch
if: github.ref == 'refs/heads/main'
run: echo "SKIP=no-commit-to-branch" >> $GITHUB_ENV
- run: SKIP="$SKIP" pre-commit run --show-diff-on-failure --color=always --all-files
working-directory: ${{ matrix.precommit }}