|
| 1 | +name: Bump pre-commit hooks |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 12 1 * *" |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: {} |
| 9 | + |
| 10 | +jobs: |
| 11 | + bump-pre-commit-hooks: |
| 12 | + if: github.repository_owner == 'fastapi' |
| 13 | + runs-on: ubuntu-latest |
| 14 | + timeout-minutes: 10 |
| 15 | + steps: |
| 16 | + - name: Dump GitHub context |
| 17 | + env: |
| 18 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 19 | + run: echo "$GITHUB_CONTEXT" |
| 20 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 21 | + with: |
| 22 | + token: ${{ secrets.LATEST_CHANGES }} |
| 23 | + persist-credentials: true |
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 26 | + with: |
| 27 | + python-version-file: ".python-version" |
| 28 | + - name: Setup uv |
| 29 | + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 |
| 30 | + with: |
| 31 | + # Before upgrading uv version, make sure astral-sh/setup-uv knows its checksum. |
| 32 | + # See: https://github.com/astral-sh/setup-uv/issues/851#issuecomment-4282017837 |
| 33 | + version: "0.11.18" |
| 34 | + cache-dependency-glob: | |
| 35 | + pyproject.toml |
| 36 | + uv.lock |
| 37 | + - name: Bump pre-commit hooks |
| 38 | + run: uv run prek auto-update --freeze --cooldown-days 7 |
| 39 | + - name: Create pull request |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ secrets.LATEST_CHANGES }} |
| 42 | + BASE_BRANCH: ${{ github.event.repository.default_branch }} |
| 43 | + run: | |
| 44 | + set -euo pipefail |
| 45 | + if git diff --quiet; then |
| 46 | + echo "No pre-commit hook updates available" |
| 47 | + exit 0 |
| 48 | + fi |
| 49 | + git config user.name "github-actions[bot]" |
| 50 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 51 | + branch="bump-pre-commit-hooks" |
| 52 | + git switch -C "$branch" |
| 53 | + git add .pre-commit-config.yaml |
| 54 | + git commit -m "⬆ Bump pre-commit hooks" |
| 55 | + git push --force origin "$branch" |
| 56 | + if [ -z "$(gh pr list --head "$branch" --state open --json number --jq '.[].number')" ]; then |
| 57 | + gh pr create \ |
| 58 | + --base "$BASE_BRANCH" \ |
| 59 | + --head "$branch" \ |
| 60 | + --title "⬆ Bump pre-commit hooks" \ |
| 61 | + --body "Bump pre-commit hook versions via \`prek auto-update --freeze --cooldown-days 7\`." \ |
| 62 | + --label internal \ |
| 63 | + --label dependencies \ |
| 64 | + --label pre-commit |
| 65 | + else |
| 66 | + echo "PR for \"$branch\" already open; branch updated in place." |
| 67 | + fi |
0 commit comments