Handle async validation errors #1429
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update PR leaderboard | |
| on: | |
| pull_request_target: | |
| types: | |
| - opened | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| concurrency: | |
| group: leaderboard-json-update | |
| cancel-in-progress: false | |
| jobs: | |
| update-leaderboard: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout default branch (trusted code only) | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.repository.default_branch }} | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Increment PR count in leaderboard.json | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| PR_USER: ${{ github.event.pull_request.user.login }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| run: | | |
| set -euo pipefail | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | |
| git checkout "${DEFAULT_BRANCH}" | |
| git pull --ff-only origin "${DEFAULT_BRANCH}" | |
| if git --no-pager log --format=%s --grep="^chore: update leaderboard for PR #${PR_NUMBER}$" -n 1 | grep -q .; then | |
| echo "PR #${PR_NUMBER} already counted." | |
| exit 0 | |
| fi | |
| if [ ! -f leaderboard.json ]; then | |
| printf '{}\n' > leaderboard.json | |
| fi | |
| tmp_file="$(mktemp)" | |
| jq --arg user "${PR_USER}" '.[$user] = ((.[$user] // 0) + 1)' leaderboard.json > "${tmp_file}" | |
| mv "${tmp_file}" leaderboard.json | |
| git add leaderboard.json | |
| if git diff --cached --quiet -- leaderboard.json; then | |
| echo "No leaderboard changes to commit." | |
| exit 0 | |
| fi | |
| git commit -m "chore: update leaderboard for PR #${PR_NUMBER}" | |
| git pull --rebase origin "${DEFAULT_BRANCH}" | |
| git push origin "HEAD:${DEFAULT_BRANCH}" |