|
17 | 17 | name: Run pre-commit checks |
18 | 18 | runs-on: ubuntu-slim |
19 | 19 | steps: |
| 20 | + - uses: actions/create-github-app-token@v2 |
| 21 | + id: app-token |
| 22 | + with: |
| 23 | + app-id: ${{ secrets.LLVM_UPDATER_ID }} |
| 24 | + private-key: ${{ secrets.LLVM_UPDATER_PRIVATE_KEY }} |
| 25 | + |
| 26 | + - name: Get GitHub App user ID |
| 27 | + id: get-user-id |
| 28 | + run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" |
| 29 | + env: |
| 30 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 31 | + |
| 32 | + - name: Configure git and environment |
| 33 | + run: | |
| 34 | + echo "GH_TOKEN=${{ steps.app-token.outputs.token }}" >> "$GITHUB_ENV" |
| 35 | + git config --global user.name "${{ steps.app-token.outputs.app-slug }}[bot]" |
| 36 | + git config --global user.email "${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com" |
| 37 | +
|
20 | 38 | - uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + ref: ${{ github.head_ref }} |
| 41 | + token: ${{ steps.app-token.outputs.token }} |
| 42 | + |
21 | 43 | - uses: actions/setup-python@v5 |
22 | 44 | - uses: astral-sh/setup-uv@v5 |
23 | | - - uses: pre-commit/action@v3.0.1 |
| 45 | + |
| 46 | + - name: Run pre-commit |
| 47 | + id: pre-commit |
| 48 | + uses: pre-commit/action@v3.0.1 |
| 49 | + |
| 50 | + - name: Push auto-fixes |
| 51 | + if: ${{ !cancelled() && steps.pre-commit.outcome == 'failure' }} |
| 52 | + run: | |
| 53 | + if git diff --quiet; then |
| 54 | + echo "::error::no auto-fixable changes; pre-commit failure requires manual attention." |
| 55 | + elif [ "$(git log -1 --format='%ae')" = "$(git config user.email)" ]; then |
| 56 | + echo "::error::pre-commit auto-fixes were not idempotent. Please fix manually." |
| 57 | + else |
| 58 | + git add -A |
| 59 | + git commit -m "Apply pre-commit auto-fixes" |
| 60 | + git push |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Annotate codespell errors |
| 64 | + if: ${{ !cancelled() && steps.pre-commit.outcome == 'failure' }} |
| 65 | + run: | |
| 66 | + pre-commit run --all-files codespell 2>&1 | |
| 67 | + awk -F: '/^[^:]*:[0-9]+: / { |
| 68 | + file=$1; line=$2; sub(/^[^:]*:[0-9]+: /, ""); msg=$0 |
| 69 | + key=file":"line |
| 70 | + if (key in msgs) msgs[key]=msgs[key]"%0A"msg |
| 71 | + else { msgs[key]=msg; files[key]=file; lines[key]=line; order[++n]=key } |
| 72 | + } END { |
| 73 | + for (i=1; i<=n; i++) |
| 74 | + printf "::error file=%s,line=%s::%s\n", files[order[i]], lines[order[i]], msgs[order[i]] |
| 75 | + }' |
0 commit comments