forked from Slicer/Slicer
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (80 loc) · 3.49 KB
/
pre-commit-autoupdate.yml
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
83
84
85
86
87
88
89
90
91
92
93
94
name: Pre-commit auto-update
on:
# every day at midnight
schedule:
- cron: "0 0 * * *"
# on demand
workflow_dispatch:
permissions:
contents: read
jobs:
auto-update:
permissions:
# Needed for peter-evans/create-pull-request to create branch
contents: write
# Needed for peter-evans/create-pull-request to create a PR
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/create-github-app-token@31c86eb3b33c9b601a1f60f98dcbfd1d70f379b4 # v1.10.3
id: app-token
with:
app-id: ${{ vars.SLICER_APP_ID }}
private-key: ${{ secrets.SLICER_APP_PRIVATE_KEY }}
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
with:
python-version: 3.12
- run: pip install pre-commit
- name: pre-commit autoupdate
run: |
# To ensure the output only contain lines like the following:
# `Updating https://github.com/org/user ... updating v1.2.3 -> v1.2.4`
# without interleaved string like the following:
# `[INFO] Initializing environment for https://github.com/org/user.`
# we perform the autoupdate twice. This ensures the second run can easily be parsed.
pre-commit autoupdate --config .pre-commit-config.yaml > /dev/null 2>&1
git checkout -- .pre-commit-config.yaml
pre-commit autoupdate --config .pre-commit-config.yaml | tee /tmp/pre-commit-autoupdate.log
- name: Save parse-autoupdate.py
run: |
cat <<EOF >> /tmp/parse-autoupdate.py
import re
import sys
for line in sys.stdin:
match = re.match(r"\[https://github.com/([^/]+/[^/]+)\] updating (v?[\d.]+) -> (v?[\d.]+)", line.strip())
if match:
repo_url = match.group(1)
old_version = match.group(2)
new_version = match.group(3)
print(f"- [{repo_url}: {old_version} -> {new_version}](https://github.com/{repo_url}/compare/{old_version}...{new_version})")
EOF
- name: Parse autoupdate output
id: parse-autoupdate
run: |
{
echo 'AUTOUPDATE_LOG<<EOF'
echo "updates:"
cat /tmp/pre-commit-autoupdate.log | python /tmp/parse-autoupdate.py
echo EOF
} >> "$GITHUB_OUTPUT"
shell: bash
- uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6.1.0
with:
token: ${{ steps.app-token.outputs.token }}
commit-message: |
ENH: Update pre-commit hooks
${{ steps.parse-autoupdate.outputs.AUTOUPDATE_LOG }}
committer: slicer-app[bot] <163601113+slicer-app[bot]@users.noreply.github.com>
author: slicer-app[bot] <163601113+slicer-app[bot]@users.noreply.github.com>
signoff: false
branch: update/pre-commit-hooks
delete-branch: true
title: "ENH: Update pre-commit hooks"
body: |
<!--pre-commit autoupdate log start-->
${{ steps.parse-autoupdate.outputs.AUTOUPDATE_LOG }}
<!--pre-commit autoupdate log start-->
This pull-request was auto-generated by the [pre-commit-autoupdate][1] GitHub action workflow.
[1]: https://github.com/${{ github.repository }}/blob/main/.github/workflows/pre-commit-autoupdate.yml
draft: false