Skip to content

Publish Nitro Performance #29

Publish Nitro Performance

Publish Nitro Performance #29

name: Publish Nitro Performance
on:
workflow_run:
workflows: [Nitro Performance]
types: [completed]
permissions:
actions: read
checks: write
contents: read
pull-requests: write
jobs:
publish:
# Same-repository PRs publish in a separate job of Nitro Performance, which
# also works before this workflow reaches the default branch.
if: >-
github.event.workflow_run.event != 'pull_request' ||
github.event.workflow_run.head_repository.full_name != github.repository
runs-on: ubuntu-24.04
steps:
- name: Checkout trusted reporting code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: 1.3.14
- name: Download performance report
id: download
continue-on-error: true
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
name: performance-report
path: untrusted-artifact
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Validate untrusted report
if: steps.download.outcome == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
EVENT_NAME=$(jq -r '.workflow_run.event' "$GITHUB_EVENT_PATH")
TRUSTED_PR_ARGUMENTS=()
if [[ "$EVENT_NAME" == 'pull_request' ]]; then
PR_NUMBER=$(jq -r '.pullRequestNumber' untrusted-artifact/performance-report.json)
if [[ ! "$PR_NUMBER" =~ ^[1-9][0-9]*$ ]]; then
echo 'Invalid pull request number in performance artifact.' >&2
exit 1
fi
gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" > trusted-pull-request.json
TRUSTED_PR_ARGUMENTS=(--trusted-pull-request trusted-pull-request.json)
fi
bun scripts/performance/validate-report.ts \
--artifact-directory untrusted-artifact \
--output-directory validated-report \
--expected-repository "$GITHUB_REPOSITORY" \
--trusted-workflow-event "$GITHUB_EVENT_PATH" \
"${TRUSTED_PR_ARGUMENTS[@]}"
- name: Post paired comparison to the PR
if: steps.download.outcome == 'success'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bun scripts/performance/github-report.ts --directory validated-report
- name: Install Bencher CLI
if: steps.download.outcome == 'success' && vars.NITRO_BENCHER_ENABLED == 'true'
uses: bencherdev/bencher@8d75325c3bc59403a2186a056b472c4f49d42838 # v0.6.12
with:
version: '0.6.12'
- name: Verify pinned Bencher binary
if: steps.download.outcome == 'success' && vars.NITRO_BENCHER_ENABLED == 'true'
run: |
printf '%s %s\n' 'c2d3a6a7fae654246134e5ced1408bdb9ba4e198b0ac3b903af17a06574a7e08' "$(command -v bencher)" | sha256sum --check -
- name: Publish to Bencher and GitHub
if: steps.download.outcome == 'success' && vars.NITRO_BENCHER_ENABLED == 'true'
env:
BENCHER_API_KEY: ${{ secrets.BENCHER_KEY }}
BENCHER_PROJECT: nitro
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bun scripts/performance/publish.ts --directory validated-report