forked from membermatters/MemberMatters
-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (58 loc) · 1.86 KB
/
Copy pathpre-commit.yml
File metadata and controls
65 lines (58 loc) · 1.86 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
58
59
60
61
62
63
64
65
name: pre-commit
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
- dev
permissions: {}
jobs:
pre-commit:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.x"
- name: Get changed files
id: file_changes
env:
BASE_REF: ${{ github.base_ref || github.event.before || '' }}
HEAD_SHA: ${{ github.sha }}
run: |
if [ -n "${BASE_REF}" ]; then
git fetch --deepen=100 origin "${BASE_REF}" 2>/dev/null || true
if [[ "${BASE_REF}" =~ ^[0-9a-f]{40}$ ]]; then
DIFF=$(git diff --name-only "${BASE_REF}" "${HEAD_SHA}")
else
DIFF=$(git diff --name-only "origin/${BASE_REF}" "${HEAD_SHA}")
fi
else
DIFF=$(git diff --name-only HEAD~1 "${HEAD_SHA}")
fi
echo "Diff between ${BASE_REF:-HEAD~1} and ${HEAD_SHA}"
echo "files=$( echo "$DIFF" | xargs echo )" >> $GITHUB_OUTPUT
- name: Pre-commit cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
id: cache-pre-commit
with:
path: ~/.cache/pre-commit/
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Execute pre-commit
id: pre-commit
if: hashFiles('.pre-commit-config.yaml') != ''
continue-on-error: true
env:
SKIP: no-commit-to-branch
FILES: ${{ steps.file_changes.outputs.files }}
run: |
pre-commit run \
--color=always \
--show-diff-on-failure \
--files $FILES
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1