|
| 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 |
0 commit comments