Skip to content

Commit 79a8adf

Browse files
committed
add autoupdate workflow
1 parent 5cb32c4 commit 79a8adf

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Pre-commit Autoupdate
2+
3+
on:
4+
schedule:
5+
# Run weekly on Monday at 9am UTC
6+
- cron: "0 9 * * 1"
7+
workflow_dispatch:
8+
9+
permissions: {}
10+
11+
jobs:
12+
autoupdate:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Generate GitHub App token
16+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2
17+
id: app-token
18+
with:
19+
app-id: ${{ vars.AUTOMATION_APP_ID }}
20+
private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
21+
22+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23+
with:
24+
token: ${{ steps.app-token.outputs.token }}
25+
persist-credentials: true
26+
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@61cb8a9741eeb8a550a1b8544337180c0fc8476b # v7.2.0
29+
30+
- name: Run prek autoupdate
31+
working-directory: "{{cookiecutter.project_slug}}"
32+
run: uvx prek autoupdate --freeze --cooldown-days 7
33+
34+
- name: Create Pull Request
35+
env:
36+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
37+
run: |
38+
if git diff --quiet; then
39+
echo "No changes to commit"
40+
exit 0
41+
fi
42+
43+
git config user.name "github-actions[bot]"
44+
git config user.email "github-actions[bot]@users.noreply.github.com"
45+
46+
branch="pre-commit-autoupdate"
47+
git checkout -b "$branch"
48+
git add -A
49+
git commit -m "build(deps): update pre-commit hooks"
50+
git push --force origin "$branch"
51+
52+
if gh pr view "$branch" &>/dev/null; then
53+
echo "PR already exists"
54+
else
55+
gh pr create \
56+
--title "build(deps): update pre-commit hooks" \
57+
--body "Automated update of pre-commit hooks using \`prek autoupdate --freeze --cooldown-days 7\`.
58+
59+
This PR was auto-generated by the pre-commit-autoupdate workflow."
60+
fi

cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"_copy_without_render": [
3232
".github/workflows/docs.yml",
3333
".github/workflows/lint.yml",
34+
".github/workflows/pre-commit-autoupdate.yml",
3435
".github/workflows/tests.yml",
3536
".github/workflows/zizmor.yml"
3637
],
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Pre-commit Autoupdate
2+
3+
on:
4+
schedule:
5+
# Run weekly on Monday at 9am UTC
6+
- cron: "0 9 * * 1"
7+
workflow_dispatch:
8+
9+
permissions: {}
10+
11+
jobs:
12+
autoupdate:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Generate GitHub App token
16+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2
17+
id: app-token
18+
with:
19+
app-id: ${{ vars.AUTOMATION_APP_ID }}
20+
private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
21+
22+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23+
with:
24+
token: ${{ steps.app-token.outputs.token }}
25+
persist-credentials: true
26+
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@61cb8a9741eeb8a550a1b8544337180c0fc8476b # v7.2.0
29+
30+
- name: Run prek autoupdate
31+
run: uvx prek autoupdate --freeze --cooldown-days 7
32+
33+
- name: Create Pull Request
34+
env:
35+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
36+
run: |
37+
if git diff --quiet; then
38+
echo "No changes to commit"
39+
exit 0
40+
fi
41+
42+
git config user.name "github-actions[bot]"
43+
git config user.email "github-actions[bot]@users.noreply.github.com"
44+
45+
branch="pre-commit-autoupdate"
46+
git checkout -b "$branch"
47+
git add -A
48+
git commit -m "build(deps): update pre-commit hooks"
49+
git push --force origin "$branch"
50+
51+
if gh pr view "$branch" &>/dev/null; then
52+
echo "PR already exists"
53+
else
54+
gh pr create \
55+
--title "build(deps): update pre-commit hooks" \
56+
--body "Automated update of pre-commit hooks using \`prek autoupdate --freeze --cooldown-days 7\`.
57+
58+
This PR was auto-generated by the pre-commit-autoupdate workflow."
59+
fi

0 commit comments

Comments
 (0)