Bench Rspack PR #545
This file contains 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: 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 | |
prepare-binding: | |
name: Prepare Rspack Binding | |
runs-on: [self-hosted, benchmark] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Init env | |
uses: ./.github/actions/env | |
- uses: ./.github/actions/prepare-rspack-binding | |
with: | |
path: ${{ env.RSPACK_DIR }} | |
ref: pull/${{ inputs.prNumber }}/head | |
bench: | |
runs-on: [self-hosted, benchmark] | |
needs: [create-comment, prepare-binding] | |
timeout-minutes: 30 | |
strategy: | |
matrix: | |
shardIndex: [1] | |
shardTotal: [1] | |
fail-fast: false | |
outputs: | |
diff-result: ${{ steps.print-results.outputs.diff-result }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Init env | |
uses: ./.github/actions/env | |
- uses: ./.github/actions/build-rspack | |
with: | |
path: ${{ env.RSPACK_DIR }} | |
ref: pull/${{ inputs.prNumber }}/head | |
- name: Run benchmark | |
run: node bin/cli.js bench --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: benchmark-artifacts-${{ matrix.shardIndex }}-${{ matrix.shardTotal }} | |
path: output | |
comment-compare-results: | |
runs-on: ubuntu-latest | |
needs: [create-comment, bench] | |
if: always() | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Init env | |
uses: ./.github/actions/env | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: benchmark-artifacts-* | |
path: output | |
merge-multiple: true | |
- id: print-results | |
name: Print results | |
run: | | |
result=$(node bin/cli.js compare --base latest --current current) | |
echo "$result" | |
echo "diff-result=${result//$'\n'/'@@'}" >> $GITHUB_OUTPUT | |
- uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.RSPACK_BOT_ACCESS_TOKEN }} | |
script: | | |
const diffResult = `${{ steps.print-results.outputs.diff-result }}` | |
let result = "task ${{ needs.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 | |
}) | |
if (result.includes("Threshold exceeded")) { | |
console.log("Some benchmark cases exceed the threshold, please visit the previous step for more information"); | |
process.exit(1); | |
} |