Skip to content

Commit

Permalink
Split out run and upload
Browse files Browse the repository at this point in the history
  • Loading branch information
epompeii committed Dec 14, 2023
1 parent 03c5e3d commit d932de0
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/benches.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
push:
branches: master
branches: does_not_exist
pull_request_target:

name: Benchmarks
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/run_benches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
on:
push:
branches: test_master
pull_request:

name: Run and Cache Benchmarks

jobs:
run_benchmarks:
if: (github.event_name == 'push' && github.ref == 'refs/heads/test_master') || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-benchmarks'))
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
backend: ["postgres", "sqlite", "mysql"]
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install postgres (Linux)
if: matrix.backend == 'postgres'
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev postgresql
echo "host all all 127.0.0.1/32 md5" > sudo tee -a /etc/postgresql/10/main/pg_hba.conf
sudo service postgresql restart && sleep 3
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo service postgresql restart && sleep 3
echo 'DATABASE_URL=postgres://postgres:postgres@localhost/' >> $GITHUB_ENV
- name: Install sqlite (Linux)
if: matrix.backend == 'sqlite'
run: |
sudo apt-get update
sudo apt-get install -y libsqlite3-dev
echo 'DATABASE_URL=/tmp/test.db' >> $GITHUB_ENV
- name: Install mysql (Linux)
if: matrix.backend == 'mysql'
run: |
sudo systemctl start mysql.service
sudo apt-get update
sudo apt-get -y install libmysqlclient-dev
mysql -e "create database diesel_test; create database diesel_unit_test; grant all on \`diesel_%\`.* to 'root'@'localhost';" -uroot -proot
echo 'DATABASE_URL=mysql://root:root@localhost/diesel_test' >> $GITHUB_ENV
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Benchmark ${{ matrix.backend }}
run: cargo +stable bench --manifest-path diesel_bench/Cargo.toml --no-default-features --features "${{ matrix.backend }}" > ${{ matrix.backend }}.txt

- name: Upload ${{ matrix.backend }} Benchmark Results
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.backend }}.txt
path: ./${{ matrix.backend }}.txt

- name: Upload GitHub Event
uses: actions/upload-artifact@v3
with:
name: event.json
path: ${{ github.event_path }}
90 changes: 90 additions & 0 deletions .github/workflows/track_benches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
on:
workflow_run:
workflows: [Run and Cache Benchmarks]
types:
- completed

name: Track Benchmarks

jobs:
track_benchmarks:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
backend: ["postgres", "sqlite", "mysql"]
env:
BENCHER_PROJECT: diesel
BENCHER_ADAPTER: rust_criterion
BENCHER_TESTBED: ubuntu-latest-${{ matrix.backend }}
BENCHMARK_RESULTS: ${{ matrix.backend }}.txt
GITHUB_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.GITHUB_EVENT);
- name: Unzip Benchmark Results
run: |
unzip $BENCHMARK_RESULTS.zip
unzip $GITHUB_EVENT.zip
- name: Export GitHub Event Data
uses: actions/github-script@v6
with:
script: |
let fs = require('fs');
let githubEvent = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT, {encoding: 'utf8'}));
console.log(githubEvent);
if (githubEvent.push_id) {
core.exportVariable("EVENT_NAME", "push");
core.exportVariable("PUSH_REF", githubEvent.ref);
} else {
core.exportVariable("EVENT_NAME", "pull_request");
core.exportVariable("PR_HEAD", githubEvent.pull_request.head.ref);
core.exportVariable("PR_BASE", githubEvent.pull_request.base.ref);
core.exportVariable("PR_DEFAULT", githubEvent.pull_request.base.repo.default_branch);
core.exportVariable("PR_NUMBER", githubEvent.number);
}
- uses: bencherdev/bencher@main
- name: Track Benchmarks
run: |
(${{ env.EVENT_NAME == 'push' && env.PUSH_REF == 'refs/heads/test_master' }} && \
bencher run \
--branch "master" \
--token "${{ secrets.BENCHER_API_TOKEN }}" \
--err \
--file "$BENCHMARK_RESULTS") || \
(${{ env.EVENT_NAME == 'pull_request'}} && \
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")

0 comments on commit d932de0

Please sign in to comment.