🔒 Replace pre-commit PAT with PR Push (#1923)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by GitHub · parent 22e9b08 · Browse files · 2 files·+26 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+26 added−9 removed
- other:+26 added−9 removed
Provenance
- Commit
14116e4- Tree
202b164- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
22e9b08
2 files changed+26 added−9 removed
modified:.github/workflows/pre-commit.yml+24 added-9 removed
3 unmodified lines45678989101112131415161718192021222322242526272829302930313132333435353637383916 unmodified lines56575859606162636465666768697071726173747576777879808182838485868773888990919218 unmodified lines3 unmodified lines pull_request:permissions: {}
env: # Forks and Dependabot don't have access to secrets HAS_SECRETS: ${{ secrets.PRE_COMMIT != '' }} CAN_PUSH: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }}
jobs: pre-commit: runs-on: ubuntu-latest permissions: contents: read id-token: write timeout-minutes: 5 steps: - name: Dump GitHub context env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 name: Checkout PR for own repo if: env.HAS_SECRETS == 'true' if: env.CAN_PUSH == 'true' with: # To be able to commit it needs to fetch the head of the branch, not the # merge commit ref: ${{ github.head_ref }} # And it needs the full history to be able to compute diffs fetch-depth: 0 # A token other than the default GITHUB_TOKEN is needed to be able to trigger CI token: ${{ secrets.PRE_COMMIT }} # zizmor: ignore[secrets-outside-env] persist-credentials: true # Required for `git push` command persist-credentials: false # pre-commit lite ci needs the default checkout configs to work - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 name: Checkout PR for fork if: env.HAS_SECRETS == 'false' if: env.CAN_PUSH == 'false' with: # To be able to commit it needs the head branch of the PR, the remote one ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 016 unmodified lines - name: Run prek - pre-commit id: precommit run: uv run prek run --from-ref origin/${GITHUB_BASE_REF} --to-ref HEAD --show-diff-on-failure continue-on-error: true - name: Check for changes id: changes run: | if [[ -n "$(git status --porcelain)" ]]; then echo "changed=true" >> "$GITHUB_OUTPUT" else echo "changed=false" >> "$GITHUB_OUTPUT" fi - name: Get PR Push token id: pr-push if: env.CAN_PUSH == 'true' && steps.changes.outputs.changed == 'true' uses: tiangolo/pr-push@ff4e51a433de4c22bbf90597e069e8247b9203d2 # 0.0.1 - name: Commit and push changes if: env.HAS_SECRETS == 'true' if: env.CAN_PUSH == 'true' && steps.changes.outputs.changed == 'true' env: PR_PUSH_TOKEN: ${{ steps.pr-push.outputs.token }} run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git remote set-url origin "https://x-access-token:${PR_PUSH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" git add -A if git diff --staged --quiet; then echo "No changes to commit" else git commit -m "🎨 Auto format" git push fi - uses: pre-commit-ci/lite-action@5d6cc0eb514c891a40562a58a8e71576c5c7fb43 # v1.1.0 if: env.HAS_SECRETS == 'false' if: env.CAN_PUSH == 'false' with: msg: 🎨 Auto format - name: Error out on pre-commit errors if: steps.precommit.outcome == 'failure'18 unmodified linesadded:.github/pr-push.yml+2 added
12workflows: - .github/workflows/pre-commit.yml