Skip to content

Commit 1680dd1

Browse files
authored
ci(benchmarks): run nightly benchmark and create PR (#2915)
## Linked Issues/PRs <!-- List of related issues/PRs --> closes #2915 ## Description <!-- List of detailed changes --> This pull request introduces a new GitHub workflow to automate the nightly gas costs benchmark process. The workflow schedules a nightly benchmark run, processes the results, and optionally creates a pull request with the updated benchmark data. Key changes include: * **New Workflow Addition:** * Added a new GitHub Actions workflow named `Nightly Gas Costs Benchmark` to `.github/workflows/nightly-benchmark.yml`. This workflow is scheduled to run nightly and can be manually triggered. * **Environment Variables:** * Defined environment variables such as `GIT_REPO`, `GIT_REPO_NAME`, `CARGO_TERM_COLOR`, `RUST_VERSION`, and `CONSENSUS_PARAMETERS_VERSION` for use within the workflow. * **Benchmark Job:** * Created a `benchmark` job that runs on the `fuelcore-benchmark` runner, checks out the repository, installs the Rust toolchain, caches dependencies, and runs the benchmarks. The results are processed and stored in `nightly_benchmarks.json`. * **Pull Request Creation:** * Added a `create_pr` job that depends on the `benchmark` job. If triggered, it updates the `chain_config.json` file with the new benchmark results, commits the changes, and creates a pull request.
1 parent 6fcdd94 commit 1680dd1

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Nightly Gas Costs Benchmark
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
workflow_dispatch:
7+
inputs:
8+
create_pr:
9+
description: "Create a pull request with the benchmark results"
10+
required: true
11+
default: "false"
12+
13+
env:
14+
GIT_REPO: ${{ github.repository }}
15+
GIT_REPO_NAME: ${{ github.event.repository.name }}
16+
CARGO_TERM_COLOR: always
17+
RUST_VERSION: 1.81.0
18+
CONSENSUS_PARAMETERS_VERSION: V2
19+
20+
jobs:
21+
benchmark:
22+
runs-on:
23+
group: fuelcore-benchmark
24+
outputs:
25+
benchmark_results: ${{ steps.benchmarks.outputs.benchmark_results }}
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
- name: Install Rust Toolchain
30+
uses: dtolnay/rust-toolchain@master
31+
with:
32+
toolchain: ${{ env.RUST_VERSION }}
33+
targets: "wasm32-unknown-unknown"
34+
- name: Cache
35+
uses: Swatinem/rust-cache@v2
36+
- name: Run benchmarks
37+
id: benchmarks
38+
run: |
39+
cargo criterion -p fuel-core-benches --message-format json --bench vm > nightly_benchmarks.json
40+
cargo run -p fuel-core-benches --bin collect --release -- --input nightly_benchmarks.json --format consensus-parameters --output nightly_benchmarks.json
41+
echo "benchmark_results=$(cat nightly_benchmarks.json | tr -d '\n' | jq '.${{ env.CONSENSUS_PARAMETERS_VERSION }}.gas_costs')" >> "$GITHUB_OUTPUT" # this will fail when consensus parameters version changes
42+
create_pr:
43+
needs: benchmark
44+
runs-on: ubuntu-latest
45+
if: ${{ github.event.inputs.create_pr == 'true' }}
46+
steps:
47+
- uses: actions/checkout@v4
48+
- run: |
49+
jq --argjson benchmark_results "$benchmark_results" \
50+
'.consensus_parameters.${{ env.CONSENSUS_PARAMETERS_VERSION }}.gas_costs = $benchmark_results' \
51+
bin/fuel-core/chainspec/local-testnet/chain_config.json > \
52+
bin/fuel-core/chainspec/local-testnet/chain_config.json.tmp && \
53+
mv bin/fuel-core/chainspec/local-testnet/chain_config.json.tmp bin/fuel-core/chainspec/local-testnet/chain_config.json
54+
# create a new branch
55+
branch_name="chore/benchmark-update-$(date +%s)"
56+
git checkout -b "$branch_name"
57+
git add bin/fuel-core/chainspec/local-testnet/chain_config.json
58+
59+
git config user.name 'github-actions[bot]'
60+
git config user.email 'github-actions[bot]@users.noreply.github.com'
61+
git commit -m "Update benchmark results"
62+
# create a new PR
63+
gh pr create \
64+
--title "chore(gas_costs): update local chain config with nightly benchmark results" \
65+
--body "Updated benchmark results" \
66+
--base master \
67+
--head "$branch_name"
68+
env:
69+
benchmark_results: ${{ needs.benchmark.outputs.benchmark_results }}
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)