Skip to content

Commit c5cf25d

Browse files
authored
Add GitHub Actions workflow to update pre-commit hooks (#73)
1 parent 4c225de commit c5cf25d

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Update pre-commit
2+
3+
on:
4+
# first of every month at midnight
5+
schedule:
6+
- cron: '0 0 1 * *'
7+
# on demand
8+
workflow_dispatch:
9+
10+
jobs:
11+
update:
12+
name: Update pre-commit hooks
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/[email protected]
18+
19+
- name: Set up Python
20+
uses: actions/[email protected]
21+
22+
- name: Get Python version
23+
id: python-version
24+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
25+
26+
- name: Restore cache
27+
uses: actions/[email protected]
28+
with:
29+
path: |
30+
~/.cache/pip
31+
~/.cache/pre-commit
32+
key: pre-commit-${{ runner.os }}-${{ steps.python-version.outputs.version }}-${{ hashFiles('.pre-commit-config.yaml') }}
33+
34+
- name: Install pre-commit
35+
run: pip install pre-commit
36+
37+
- name: Update pre-commit hooks
38+
run: pre-commit autoupdate
39+
40+
- name: Get pull request body
41+
id: pull-request-body
42+
run: >
43+
echo ::set-output name=body::$(git diff --unified=1 |
44+
grep -E 'repo:|rev:' |
45+
sed 's|.*com/||; s/.*rev: //' |
46+
sed 'N;s/\n/: /; N;s/\n/ -> /; s/^/- /')
47+
48+
- name: Create pull request
49+
if: success()
50+
uses: peter-evans/[email protected]
51+
with:
52+
branch: pre-commit/update-hooks
53+
delete-branch: true
54+
commit-message: Update pre-commit hooks
55+
title: Update pre-commit hooks
56+
body: ${{ steps.pull-request-body.outputs.body }}
57+
labels: |
58+
dependencies
59+
pre-commit

0 commit comments

Comments
 (0)