Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track benchmarks in CI #2012

Merged
merged 20 commits into from
Jul 29, 2024
29 changes: 29 additions & 0 deletions .github/workflows/benchmark-master.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: benchmark master
on:
push:
branches: master
jobs:
benchmark-master:
name: benchmark master
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: cachix/install-nix-action@V27
name: "Installing Nix"
with:
extra_nix_config: |
experimental-features = nix-command flakes
accept-flake-config = true
nix_path: "nixpkgs=channel:nixos-unstable"
- uses: bencherdev/bencher@main
- name: Track benchmarks on master
run: |
bencher run \
--project nickel \
--token '${{ secrets.BENCHER_API_TOKEN }}' \
--branch master \
--testbed ubuntu-latest \
--adapter rust_criterion \
nix develop --command cargo bench --package nickel-lang-core --bench numeric
28 changes: 28 additions & 0 deletions .github/workflows/benchmark-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: benchmark pull requests
on:
pull_request:
types: [opened, reopened, edited, synchronize]

jobs:
benchmark-pr:
name: benchmark pr
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: cachix/install-nix-action@V27
name: "Installing Nix"
with:
extra_nix_config: |
experimental-features = nix-command flakes
accept-flake-config = true
nix_path: "nixpkgs=channel:nixos-unstable"
- name: run benchmarks
run: |
nix develop --command cargo bench --package nickel-lang-core --bench numeric > criterion-output.txt
- name: upload results
uses: actions/upload-artifact@v4
with:
name: criterion-output
path: criterion-output.txt
2 changes: 1 addition & 1 deletion .github/workflows/release-artifacts.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Upload release artifacts
name: Test Docker manifest
on:
release:
types: [published]
Expand Down
17 changes: 0 additions & 17 deletions .github/workflows/run-benchmark.yaml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/upload-pr-benchmarks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Track Benchmarks with Bencher

on:
workflow_run:
workflows: [benchmark pull requests]
types: [completed]

jobs:
track_fork_pr_branch:
name: track pr benchmarks
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
env:
BENCHMARK_RESULTS: criterion-output
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_BASE_SHA", prEvent.pull_request.base.sha);
core.exportVariable("PR_NUMBER", prEvent.number);
- uses: bencherdev/bencher@main
- name: Track Benchmarks with Bencher
run: |
bencher run \
--project nickel \
--token '${{ secrets.BENCHER_API_TOKEN }}' \
--branch '${{ env.PR_HEAD }}' \
--branch-start-point '${{ env.PR_BASE }}' \
--branch-start-point-hash '${{ env.PR_BASE_SHA }}' \
--testbed ubuntu-latest \
--adapter criterion_rust \
--err \
--github-actions '${{ secrets.GITHUB_TOKEN }}' \
--ci-number '${{ env.PR_NUMBER }}' \
--file "$BENCHMARK_RESULTS.txt"