Skip to content

Commit b155ef4

Browse files
[ci] Fix Benchmarks (#3738)
1 parent 18bae6f commit b155ef4

1 file changed

Lines changed: 58 additions & 12 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,32 @@ jobs:
2727
exit 1
2828
fi
2929
30-
publish:
31-
name: Publish
30+
benchmark:
31+
name: Run
3232
needs: has-new-commit # Only run if there are new commits
3333
runs-on: ubuntu-latest-8
3434
timeout-minutes: 720
3535
strategy:
36-
max-parallel: 1 # Run one package at a time
36+
fail-fast: false
3737
matrix:
3838
include:
3939
- package: commonware-cryptography
4040
cargo_flags: ""
41-
file_suffix: ""
4241
benchmark_name: "commonware-cryptography"
4342
- package: commonware-storage
4443
cargo_flags: "--features test-traits"
45-
file_suffix: ""
4644
benchmark_name: "commonware-storage"
4745
- package: commonware-storage
4846
cargo_flags: "--features commonware-runtime/iouring-storage,test-traits"
49-
file_suffix: "-features"
5047
benchmark_name: "commonware-storage --features"
5148
- package: commonware-coding
5249
cargo_flags: ""
53-
file_suffix: ""
5450
benchmark_name: "commonware-coding"
5551
- package: commonware-formatting
5652
cargo_flags: ""
57-
file_suffix: ""
5853
benchmark_name: "commonware-formatting"
5954
- package: commonware-utils
6055
cargo_flags: ""
61-
file_suffix: ""
6256
benchmark_name: "commonware-utils"
6357
steps:
6458
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
@@ -67,21 +61,73 @@ jobs:
6761
- name: Run setup
6862
uses: ./.github/actions/setup
6963
- name: Compile benchmarks
70-
run: cargo bench ${{ matrix.cargo_flags }} --no-run
64+
env:
65+
RUSTFLAGS: "--cfg full_bench"
66+
run: cargo bench ${{ matrix.cargo_flags }} --benches -p ${{ matrix.package }} --no-run
7167
- name: Run benchmarks
7268
env:
7369
RUSTFLAGS: "--cfg full_bench"
7470
run: |
7571
cargo bench ${{ matrix.cargo_flags }} \
7672
--benches -p ${{ matrix.package }} \
7773
-- --output-format bencher \
78-
| tee "${{ matrix.package }}${{ matrix.file_suffix }}.txt"
74+
| tee "${{ matrix.benchmark_name }}.txt"
75+
- name: Upload benchmark result
76+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
77+
with:
78+
name: benchmark-${{ matrix.benchmark_name }}
79+
path: "${{ matrix.benchmark_name }}.txt"
80+
if-no-files-found: error
81+
82+
publish:
83+
name: Publish
84+
needs: benchmark
85+
if: ${{ always() && needs.benchmark.result != 'skipped' }}
86+
runs-on: ubuntu-latest
87+
timeout-minutes: 60
88+
strategy:
89+
fail-fast: false
90+
max-parallel: 1 # Push benchmark results one package at a time.
91+
matrix:
92+
include:
93+
- package: commonware-cryptography
94+
benchmark_name: "commonware-cryptography"
95+
- package: commonware-storage
96+
benchmark_name: "commonware-storage"
97+
- package: commonware-storage
98+
benchmark_name: "commonware-storage --features"
99+
- package: commonware-coding
100+
benchmark_name: "commonware-coding"
101+
- package: commonware-formatting
102+
benchmark_name: "commonware-formatting"
103+
- package: commonware-utils
104+
benchmark_name: "commonware-utils"
105+
steps:
106+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
107+
- name: Download benchmark result
108+
continue-on-error: ${{ needs.benchmark.result != 'success' }}
109+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
110+
with:
111+
name: benchmark-${{ matrix.benchmark_name }}
112+
- name: Validate benchmark result
113+
id: result
114+
run: |
115+
output="${{ matrix.benchmark_name }}.txt"
116+
if [ ! -f "$output" ]; then
117+
echo "found=false" >> "$GITHUB_OUTPUT"
118+
echo "No benchmark result found for ${{ matrix.benchmark_name }}; skipping publish"
119+
exit 0
120+
fi
121+
test -s "$output"
122+
grep -Eq '^test .+ \.\.\. bench:' "$output"
123+
echo "found=true" >> "$GITHUB_OUTPUT"
79124
- name: Publish benchmark result
125+
if: steps.result.outputs.found == 'true'
80126
uses: benchmark-action/github-action-benchmark@4bdcce38c94cec68da58d012ac24b7b1155efe8b # v1.20.7
81127
with:
82128
name: ${{ matrix.benchmark_name }}
83129
tool: 'cargo'
84-
output-file-path: "${{ matrix.package }}${{ matrix.file_suffix }}.txt"
130+
output-file-path: "${{ matrix.benchmark_name }}.txt"
85131
github-token: ${{ secrets.BENCHMARKS_SECRET }}
86132
gh-repository: github.com/commonwarexyz/benchmarks
87133
gh-pages-branch: main

0 commit comments

Comments
 (0)