@@ -23,9 +23,50 @@ defaults:
2323 shell : bash
2424
2525jobs :
26+ bench-matrix :
27+ name : Determine benchmark matrix
28+ runs-on : ubuntu-24.04
29+ outputs :
30+ benches : ${{ steps.benches.outputs.benches }}
31+ steps :
32+ - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
33+ with :
34+ sparse-checkout : Cargo.toml
35+ persist-credentials : false
36+ - id : benches
37+ run : |
38+ # Create a GitHub matrix where each entry is a bench with its
39+ # associated crate and benchmarking mode taken from the Cargo
40+ # metadata.
41+ echo "benches=[" > benches.json
42+ first=true
43+ while IFS=: read -r crate manifest_path; do
44+ dir=$(dirname "$manifest_path")
45+ if [ -e "$dir/benches" ]; then
46+ for bench in "$dir/benches"/*.rs; do
47+ bench=$(basename -s .rs "$bench")
48+ # Set measurement mode from Cargo.toml metadata, default to "instrumentation".
49+ mode=$(cargo metadata --no-deps --format-version 1 | jq -r --arg crate "$crate" --arg bench "$bench" '.packages[] | select(.name == $crate) | .metadata.bench[$bench].codspeed.mode // "instrumentation"')
50+ if [ "$first" = true ]; then
51+ first=false
52+ else
53+ echo "," >> benches.json
54+ fi
55+ echo "{\"crate\":\"$crate\",\"bench\":\"$bench\",\"mode\":\"$mode\"}" >> benches.json
56+ done
57+ fi
58+ done < <(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | .name + ":" + .manifest_path')
59+ echo "]" >> benches.json
60+ jq benches.json | tee >> "$GITHUB_OUTPUT"
61+
2662 benchmarks :
2763 name : Run benchmarks
28- runs-on : ubuntu-latest
64+ runs-on : ubuntu-24.04
65+ strategy :
66+ matrix :
67+ bench : ${{ fromJson(needs.bench-matrix.outputs.benches) }}
68+ needs : bench-matrix
69+
2970 steps :
3071 - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3172 with :
@@ -44,22 +85,17 @@ jobs:
4485 with :
4586 minimum-version : ${{ steps.nss-version.outputs.minimum }}
4687
47- - run : |
48- while IFS=: read -r crate manifest_path; do
49- dir=$(dirname "$manifest_path")
50- if [ -e "$dir/benches" ]; then
51- for bench in "$dir/benches"/*.rs; do
52- bench=$(basename -s .rs "$bench")
53- # Set measurement mode from Cargo.toml metadata, default to "instrumentation".
54- mode=$(cargo metadata --no-deps --format-version 1 | jq -r --arg crate "$crate" --arg bench "$bench" '.packages[] | select(.name == $crate) | .metadata.bench[$bench].codspeed.mode // "instrumentation"')
55- echo "Building benchmark '$bench' in crate '$crate' (dir '$dir') with measurement mode '$mode'"
56- cargo codspeed build --package "$crate" --locked --features bench --bench "$bench" --measurement-mode "$mode"
57- done
58- fi
59- done < <(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | .name + ":" + .manifest_path')
88+ - env :
89+ BENCH : ${{ matrix.bench.bench }}
90+ CRATE : ${{ matrix.bench.crate }}
91+ MODE : ${{ matrix.bench.mode }}
92+ run : |
93+ echo "Building benchmark '$BENCH' in crate '$CRATE' with measurement mode '$MODE'"
94+ cargo codspeed build --package "$CRATE" --locked --features bench --bench "$BENCH" --measurement-mode "$MODE"
6095
6196 - name : Run the benchmarks
6297 uses : CodSpeedHQ/action@4348f634fa7309fe23aac9502e88b999ec90a164 # v4.3.1
6398 with :
99+ mode : ${{ matrix.bench.mode }}
64100 run : cargo codspeed run
65101 token : ${{ secrets.CODSPEED_TOKEN }}
0 commit comments