-
Notifications
You must be signed in to change notification settings - Fork 26
73 lines (59 loc) · 1.96 KB
/
format.yml
File metadata and controls
73 lines (59 loc) · 1.96 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
66
67
68
69
70
71
72
73
name: pre-commit (PR only on changed files)
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
jobs:
detect_changes:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.changed_files.outputs.changed }}
steps:
- name: Checkout PR
uses: actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false
- name: Detect changed files
id: changed_files
run: |
# git fetch origin ${{ github.base_ref }}
# CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
echo "Base SHA: $BASE_SHA"
echo "Head SHA: $HEAD_SHA"
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
{
echo "changed<<EOF"
echo "$CHANGED_FILES"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Show changed files
run: |
echo "Changed files:"
echo "${{ steps.changed_files.outputs.changed }}"
precommit:
needs: detect_changes
runs-on: ubuntu-latest
if: ${{ needs.detect_changes.outputs.changed != '' }}
steps:
- name: Checkout PR head commit
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit (CI check-only stage) on changed files
env:
CHANGED_FILES: ${{ needs.detect_changes.outputs.changed }}
run: |
mapfile -t files <<< "$CHANGED_FILES"
pre-commit run --hook-stage manual --files "${files[@]}" --show-diff-on-failure