seriesoftubes/.github/workflows/perf-comment.yml
Frederic Jung e7729d0a1e
Harden workflows and dev scripts against code-scanning findings
- auto-release: pass step outputs to run scripts through env, not ${{ }} interpolation
- perf-comment: download the PR's perf artifact to RUNNER_TEMP, outside the workspace
- dev server: log errors to the terminal instead of sending stack traces in the response
- i18n-add/i18n-check: escape every regex metacharacter when building patterns from labels
2026-11-05 21:04:21 +01:00

43 lines
2 KiB
YAML

name: Performance comment
# Posts the table from the Performance workflow on its pull request, and updates the same comment on every push.
# Runs in this repository's context with write access, so it only reads the uploaded text and never runs PR code.
on:
workflow_run:
workflows: [Performance]
types: [completed]
permissions:
pull-requests: write
issues: write
actions: read
jobs:
comment:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: perf
# Outside the workspace: the files come from a PR's run and are only ever read as text.
path: ${{ runner.temp }}/perf
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Post or update the comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
cd "$RUNNER_TEMP/perf"
pr=$(tr -cd '0-9' < pr-number.txt)
[ -n "$pr" ] || { echo "no PR number"; exit 0; }
# Trust the number only if that PR's head is the commit that was benchmarked.
head=$(gh api "repos/$REPO/pulls/$pr" --jq .head.sha)
[ "$head" = "$HEAD_SHA" ] || { echo "PR #$pr has moved on since this run"; exit 0; }
{ echo '<!-- perf-bench -->'; head -c 60000 perf.md; } > body.md
id=$(gh api "repos/$REPO/issues/$pr/comments" --paginate --jq '.[] | select(.user.login == "github-actions[bot]" and (.body | startswith("<!-- perf-bench -->"))) | .id' | head -n 1)
if [ -n "$id" ]; then gh api -X PATCH "repos/$REPO/issues/comments/$id" -F body=@body.md > /dev/null
else gh api -X POST "repos/$REPO/issues/$pr/comments" -F body=@body.md > /dev/null; fi
echo "Posted to #$pr"