Skip to content

ci: add automated binary builds for sails-cli #498

ci: add automated binary builds for sails-cli

ci: add automated binary builds for sails-cli #498

Workflow file for this run

name: '[rs] Benchmarks'
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
paths:
- 'benchmarks/**'
- 'rs/**'
- 'Cargo.lock'
- 'Cargo.toml'
- '.github/workflows/rs-bench.yml'
- 'examples/**'
push:
branches: [master]
paths:
- 'benchmarks/**'
- 'rs/**'
- 'Cargo.lock'
- 'Cargo.toml'
- '.github/workflows/rs-bench.yml'
- 'examples/**'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
benchmark:
if: (github.event_name == 'push') ||
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-benchmarks'))
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
- name: Free Disk Space
uses: ./.github/actions/free-disk-space
- name: Install wasm-opt
uses: ./.github/actions/install-wasm-utils
- name: Build bench-analyzer
run: |
make build-bench-analyzer
- name: Copy current benchmarks for a diff test
run: |
cp benchmarks/bench_data.json benchmarks/bench_data_before_bench_run.json
- name: Run benchmarks
run: |
make bench
# The check is done with a threshold test
- name: Check current branch has actual benchmark data
if: github.event_name == 'pull_request'
run: |
./target/debug/bench-analyzer --current=benchmarks/bench_data.json --other=benchmarks/bench_data_before_bench_run.json --threshold=1
# If diff check passes, compare with master baseline
# First copy baseline JSON from master branch
- name: Copy baseline benchmarks from master branch
if: github.event_name == 'pull_request'
run: |
git fetch origin master:refs/remotes/origin/master
git show origin/master:benchmarks/bench_data.json > benchmarks/baseline.json
# Now compare benchmarks and generate markdown table
- name: Compare Benchmarks vs Master
if: github.event_name == 'pull_request'
run: |
./target/debug/bench-analyzer --current=benchmarks/bench_data.json --other=benchmarks/baseline.json --output=benchmarks/comparison.md
# Read the comparison markdown for the comment
- name: Read Comparison Result
if: github.event_name == 'pull_request'
id: comparison
run: |
echo 'COMPARISON_TABLE<<EOF' >> $GITHUB_OUTPUT
cat benchmarks/comparison.md >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
# Comment the comparison table on the PR
- name: Comment PR with Benchmark Comparison
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const comparisonTable = `${{ steps.comparison.outputs.COMPARISON_TABLE }}`;
const commentBody = `${comparisonTable}
---
<sub>🤖 This comment was automatically generated by the benchmark comparison workflow at ${{ github.sha }}.</sub>`;
// Always create a new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});