1+ name : Track Benchmarks
2+
3+ on :
4+ workflow_run :
5+ workflows : [Run and Cache Benchmarks]
6+ types :
7+ - completed
8+
9+ jobs :
10+ track_with_bencher :
11+ if : github.event.workflow_run.conclusion == 'success'
12+ runs-on : ubuntu-22.04
13+ env :
14+ BENCHER_PROJECT : h264-reader
15+ BENCHER_ADAPTER : rust_iai_callgrind
16+ BENCHER_TESTBED : ubuntu-22.04
17+ BENCHMARK_RESULTS : benchmark_results.txt
18+ PR_EVENT : event.json
19+ steps :
20+ - name : Download Benchmark Results
21+ uses : actions/github-script@v6
22+ with :
23+ script : |
24+ async function downloadArtifact(artifactName) {
25+ let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
26+ owner: context.repo.owner,
27+ repo: context.repo.repo,
28+ run_id: context.payload.workflow_run.id,
29+ });
30+ let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
31+ return artifact.name == artifactName
32+ })[0];
33+ if (!matchArtifact) {
34+ core.setFailed(`Failed to find artifact: ${artifactName}`);
35+ }
36+ let download = await github.rest.actions.downloadArtifact({
37+ owner: context.repo.owner,
38+ repo: context.repo.repo,
39+ artifact_id: matchArtifact.id,
40+ archive_format: 'zip',
41+ });
42+ let fs = require('fs');
43+ fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data));
44+ }
45+ await downloadArtifact(process.env.BENCHMARK_RESULTS);
46+ await downloadArtifact(process.env.PR_EVENT);
47+ - name : Unzip Benchmark Results
48+ run : |
49+ unzip $BENCHMARK_RESULTS.zip
50+ unzip $PR_EVENT.zip
51+ - name : Export PR Event Data
52+ uses : actions/github-script@v6
53+ with :
54+ script : |
55+ let fs = require('fs');
56+ let prEvent = JSON.parse(fs.readFileSync(process.env.PR_EVENT, {encoding: 'utf8'}));
57+ core.exportVariable("PR_HEAD", `${prEvent.number}/merge`);
58+ core.exportVariable("PR_BASE", prEvent.pull_request.base.ref);
59+ core.exportVariable("PR_DEFAULT", prEvent.pull_request.base.repo.default_branch);
60+ core.exportVariable("PR_NUMBER", prEvent.number);
61+ - uses : bencherdev/bencher@main
62+ - name : Track Benchmarks with Bencher
63+ run : |
64+ bencher run \
65+ --if-branch '${{ env.PR_HEAD }}' \
66+ --else-if-branch '${{ env.PR_BASE }}' \
67+ --else-if-branch '${{ env.PR_DEFAULT }}' \
68+ --ci-number '${{ env.PR_NUMBER }}' \
69+ --github-actions "${{ secrets.GITHUB_TOKEN }}" \
70+ --token "${{ secrets.BENCHER_API_TOKEN }}" \
71+ --err \
72+ --file "$BENCHMARK_RESULTS"
0 commit comments