-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Per https://bencher.dev/docs/how-to/github-actions/#benchmark-fork-pr-and-upload-from-default-branch
- Loading branch information
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Track Benchmarks | ||
|
||
on: | ||
workflow_run: | ||
workflows: [Run and Cache Benchmarks] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
track_with_bencher: | ||
if: github.event.workflow_run.conclusion == 'success' | ||
runs-on: ubuntu-22.04 | ||
env: | ||
BENCHER_PROJECT: h264-reader | ||
BENCHER_ADAPTER: rust_iai_callgrind | ||
BENCHER_TESTBED: ubuntu-22.04 | ||
BENCHMARK_RESULTS: benchmark_results.txt | ||
PR_EVENT: event.json | ||
steps: | ||
- name: Download Benchmark Results | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
async function downloadArtifact(artifactName) { | ||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: context.payload.workflow_run.id, | ||
}); | ||
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == artifactName | ||
})[0]; | ||
if (!matchArtifact) { | ||
core.setFailed(`Failed to find artifact: ${artifactName}`); | ||
} | ||
let download = await github.rest.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
let fs = require('fs'); | ||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data)); | ||
} | ||
await downloadArtifact(process.env.BENCHMARK_RESULTS); | ||
await downloadArtifact(process.env.PR_EVENT); | ||
- name: Unzip Benchmark Results | ||
run: | | ||
unzip $BENCHMARK_RESULTS.zip | ||
unzip $PR_EVENT.zip | ||
- name: Export PR Event Data | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
let fs = require('fs'); | ||
let prEvent = JSON.parse(fs.readFileSync(process.env.PR_EVENT, {encoding: 'utf8'})); | ||
core.exportVariable("PR_HEAD", `${prEvent.number}/merge`); | ||
core.exportVariable("PR_BASE", prEvent.pull_request.base.ref); | ||
core.exportVariable("PR_DEFAULT", prEvent.pull_request.base.repo.default_branch); | ||
core.exportVariable("PR_NUMBER", prEvent.number); | ||
- uses: bencherdev/bencher@main | ||
- name: Track Benchmarks with Bencher | ||
run: | | ||
bencher run \ | ||
--if-branch '${{ env.PR_HEAD }}' \ | ||
--else-if-branch '${{ env.PR_BASE }}' \ | ||
--else-if-branch '${{ env.PR_DEFAULT }}' \ | ||
--ci-number '${{ env.PR_NUMBER }}' \ | ||
--github-actions "${{ secrets.GITHUB_TOKEN }}" \ | ||
--token "${{ secrets.BENCHER_API_TOKEN }}" \ | ||
--err \ | ||
--file "$BENCHMARK_RESULTS" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Run and Cache Benchmarks | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
|
||
jobs: | ||
benchmark: | ||
name: Run Benchmarks | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: cargo-bins/cargo-binstall@main | ||
|
||
- run: sudo apt-get install valgrind | ||
- run: cargo binstall --no-confirm [email protected] | ||
- run: | | ||
IAI_CALLGRIND_COLOR=never cargo bench --bench ci_bench > benchmark_results.txt | ||
- name: Upload Benchmark Results | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: benchmark_results.txt | ||
path: ./benchmark_results.txt | ||
- name: Upload GitHub Pull Request Event | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: event.json | ||
path: ${{ github.event_path }} |
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