Repository navigation
82 lines (71 loc) · 2.71 KB
/
Copy pathpre-commit.yml
File metadata and controls
82 lines (71 loc) · 2.71 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
74
75
76
77
78
79
80
81
82
name: Scheduled Pre-Commit Auto-Update
"on":
schedule:
# 06:00 UTC on the 1st of every month
- cron: "0 6 1 * *"
# Manual trigger from the Actions tab
workflow_dispatch:
# Serialize scheduled and manual runs: avoids duplicate work and push races
concurrency:
group: pre-commit-autoupdate
cancel-in-progress: false
jobs:
auto-update:
runs-on: ubuntu-latest
timeout-minutes: 10
# Needed for GITHUB_TOKEN to commit and push the updated config
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
# Full history avoids shallow-clone issues on push
fetch-depth: 0
- name: Set up latest Python
uses: actions/setup-python@v6
with:
# Floating spec: resolves to the latest stable Python 3 on every run
python-version: "3.x"
- name: Install pre-commit
# No `pip install --upgrade pip`: setup-python already ships a current
# pip, and the upgrade costs ~15s on every run for no benefit here.
run: pip install pre-commit
- name: Cache pip and pre-commit
# NOTE: setup-python's built-in `cache: pip` is intentionally NOT used:
# it keys off requirements*.txt files, which this repo doesn't have,
# so it would silently do nothing. This explicit step actually caches.
uses: actions/cache@v5
with:
path: |
~/.cache/pip
~/.cache/pre-commit
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
pre-commit-${{ runner.os }}-
- name: Run pre-commit autoupdate
id: autoupdate
run: |
pre-commit autoupdate
# Detect changes (step output, not env var)
if git diff --quiet -- .pre-commit-config.yaml; then
echo "changes=false" >> "$GITHUB_OUTPUT"
echo "No pre-commit updates available."
else
echo "changes=true" >> "$GITHUB_OUTPUT"
echo "Pre-commit updates detected:"
git diff --stat -- .pre-commit-config.yaml
fi
- name: Commit and push updates
if: steps.autoupdate.outputs.changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .pre-commit-config.yaml
# Only commit if staged content differs (avoids empty-commit race)
if git diff --cached --quiet; then
echo "Nothing staged, skipping commit."
else
git commit -m "chore(deps): auto-update pre-commit hooks"
git push
fi