Skip to content

Bench PR

Bench PR #40

Workflow file for this run

name: Bench PR
on:
workflow_dispatch:
inputs:
prNumber:
description: 'PR number'
required: true
type: string
product:
description: 'product name of which to bench'
required: true
type: string
repo:
description: 'repo name of which to bench'
required: true
type: string
jobs:
create-comment:
runs-on: ubuntu-latest
outputs:
comment-id: ${{ steps.create-comment.outputs.result }}
steps:
- id: create-comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.RSPACK_BOT_ACCESS_TOKEN }}
result-encoding: string
script: |
const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const urlLink = `[Open](${url})`
const { data: comment } = await github.rest.issues.createComment({
issue_number: context.payload.inputs.prNumber,
owner: context.repo.owner,
repo: context.payload.inputs.repo,
body: `⏳ Triggered benchmark: ${urlLink}`
})
return comment.id
run-bench:
runs-on: ${{ fromJSON(vars.SELF_LINUX_LABELS || '"ubuntu-latest"') }}
timeout-minutes: 30
needs: create-comment
outputs:
diff-result: ${{ steps.print-results.outputs.diff-result }}
steps:
- name: Print runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
cache-dependency-path: pnpm-lock.yaml
- name: Install Pnpm
run: corepack enable && pnpm -v && pnpm store path
- name: Install Dependencies
run: pnpm run install:scripts
- name: 🚀 Run specified benchmark
run: cd scripts && PR_NUMBER=${{ inputs.prNumber }} GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} pnpm start:pr ${{ inputs.product }}
- id: print-results
name: Print results
run: |
result=$(cd scripts && node ./dist/compare.js ${{ inputs.product }})
echo "$result"
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT
if [[ $result =~ "Threshold exceeded" ]]; then
echo "Some benchmark metrics exceed the threshold, please visit the previous step for more information"
exit 1
fi
update-comment:
runs-on: ubuntu-latest
needs: [create-comment, run-bench]
if: always()
steps:
- uses: actions/github-script@v6
with:
github-token: ${{ secrets.RSPACK_BOT_ACCESS_TOKEN }}
script: |
const diffResult = `${{ needs.run-bench.outputs.diff-result }}`
let result = "task ${{ needs.run-bench.result }}"
if (diffResult) {
result = diffResult.replace(/@@/g, "\n");
}
const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const urlLink = `[Open](${url})`
const body = `
📝 Benchmark detail: ${urlLink}
${result}
`
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.payload.inputs.repo,
comment_id: `${{ needs.create-comment.outputs.comment-id }}`,
body
})