Skip to content

Bench Rspack PR

Bench Rspack PR #47

name: Bench Rspack PR
on:
workflow_dispatch:
inputs:
prNumber:
description: "PR number (e.g. 9887)"
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: 'rspack',
body: `⏳ Triggered benchmark: ${urlLink}`
})
return comment.id
run-bench:
runs-on: [self-hosted, rspack-bench]
timeout-minutes: 30
needs: create-comment
outputs:
diff-result: ${{ steps.print-results.outputs.diff-result }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Init env
uses: ./.github/actions/env
- name: Build rspack
run: node bin/build-rspack.js origin pull/${{ inputs.prNumber }}/head
- name: Run benchmark
run: node bin/bench.js
- id: print-results
name: Print results
run: |
result=$(node bin/compare-bench.js latest current)
echo "$result"
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT
if [[ $result =~ "Threshold exceeded" ]]; then
echo "Some benchmark cases 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: 'rspack',
comment_id: `${{ needs.create-comment.outputs.comment-id }}`,
body
})