Add commenting #357
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
on: | |
push: | |
branches: | |
- master | |
- drogus/benchmarks-improvements | |
workflow_dispatch: | |
inputs: | |
pr_number: | |
description: 'Pull Request Number' | |
required: false | |
default: '' | |
name: Benchmarks | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
benchmark: | |
name: run benchmarks | |
runs-on: benchmarks-runner | |
steps: | |
- name: Enable CPU boost | |
run: echo "1" | sudo tee /sys/devices/system/cpu/cpufreq/boost | |
- name: Checkout sources for a PR | |
if: ${{ github.event.inputs.ref }} | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.ref }} | |
fetch-depth: 0 | |
- name: Checkout sources | |
if: github.event.inputs.ref == '' | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 10 | |
- name: Set up for PR context | |
if: github.event.inputs.pr_number | |
run: | | |
echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_ENV | |
PR_DATA=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.inputs.pr_number }} --jq '{ baseRefName: .base.ref, headRefName: .head.ref }') | |
echo "PR_BASE_REF=$(echo $PR_DATA | jq -r '.baseRefName')" >> $GITHUB_ENV | |
echo "PR_HEAD_REF=$(echo $PR_DATA | jq -r '.headRefName')" >> $GITHUB_ENV | |
- name: Install stable toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
target: wasm32-unknown-unknown | |
override: true | |
- name: Extract branch name | |
shell: bash | |
run: echo "BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV | |
- name: Install clippy and critcmp | |
run: | | |
rustup component add clippy | |
cargo install critcmp | |
- name: Disable CPU boost | |
run: echo "0" | sudo tee /sys/devices/system/cpu/cpufreq/boost | |
- name: Run criterion | |
id: run-criterion | |
shell: bash | |
run: | | |
git fetch | |
CHANGES_ID="" | |
if [[ -n "$PR_NUMBER" ]]; then | |
CHANGES_ID="pr-$PR_NUMBER" | |
else | |
CHANGES_ID=$GITHUB_SHA | |
fi | |
pushd crates/bench | |
cargo bench -- --save-baseline $CHANGES_ID | |
popd | |
mkdir criterion-results | |
if [[ -z "$PR_NUMBER" ]]; then | |
# if we're not in a PR also export with the branch name | |
critcmp --export $CHANGES_ID > criterion-results/${BRANCH_NAME//\//-}.json | |
fi | |
critcmp --export $CHANGES_ID > criterion-results/$CHANGES_ID.json | |
echo "CHANGES_ID=$CHANGES_ID" >> $GITHUB_ENV | |
echo "BASE_ID=$BASE_ID" >> $GITHUB_ENV | |
- uses: actions/github-script@v5 | |
if: github.event.inputs.pr_number | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const {CHANGES_ID, BASE_ID} = process.env | |
github.rest.issues.createComment({ | |
issue_number: github.event.inputs.pr_number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `[Benchmarks compare](https://benchmarks.spacetimedb.com/compare/${CHANGES_ID},${BASE_ID})` | |
}) | |
- uses: actions/github-script@v5 | |
if: "! github.event.inputs.pr_number" | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const {CHANGES_ID, BASE_ID} = process.env | |
github.rest.repos.createCommitComment({ | |
commit_sha: context.sha, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `[Benchmarks compare](https://benchmarks.spacetimedb.com/compare/${CHANGES_ID},${BASE_ID})` | |
}) | |
- name: Upload criterion results to DO spaces | |
uses: shallwefootball/s3-upload-action@master | |
with: | |
aws_key_id: ${{ secrets.AWS_KEY_ID }} | |
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}} | |
aws_bucket: "spacetimedb-ci-benchmarks" | |
source_dir: criterion-results | |
endpoint: https://nyc3.digitaloceanspaces.com | |
destination_dir: benchmarks | |
- name: Clean up | |
if: always() | |
run: | | |
rm -fr /stdb/* |