From df091e06de88ffeaecdb60ff65482f750382e673 Mon Sep 17 00:00:00 2001 From: jerrykingxyz Date: Fri, 29 Dec 2023 15:26:15 +0800 Subject: [PATCH] chore: support bench commit --- .github/workflows/bench_rspack_commit.yml | 65 +++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/bench_rspack_commit.yml diff --git a/.github/workflows/bench_rspack_commit.yml b/.github/workflows/bench_rspack_commit.yml new file mode 100644 index 00000000..b344cd7b --- /dev/null +++ b/.github/workflows/bench_rspack_commit.yml @@ -0,0 +1,65 @@ +name: Bench Rspack Commit + +on: + workflow_dispatch: + inputs: + commit_sha: + description: "commit sha" + required: true + type: string + +jobs: + run-bench: + runs-on: [self-hosted, rspack-bench] + timeout-minutes: 30 + 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 ${{ inputs.commit_sha }} + - 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 + + create-comment: + runs-on: ubuntu-latest + needs: [run-bench] + steps: + - id: create-comment + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.RSPACK_BOT_ACCESS_TOKEN }} + result-encoding: string + 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.commits.createComment({ + commit_sha: context.payload.inputs.commit_sha, + owner: context.repo.owner, + repo: 'rspack', + body + })