Skip to content

Commit 2f969ea

Browse files
authored
update bench workflows to support re-benching main (#69)
* update bench workflows to support re-benching main * fix issues
1 parent 8632b3b commit 2f969ea

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

.github/workflows/bench-mpmc.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
echo "runner_labels_list=[\"self-hosted\",\"bench\"${labels:+,\"$labels\"}]" >> "$GITHUB_OUTPUT"
3838
3939
benchmark:
40-
name: Bench PR #${{ inputs.pr_number }}
40+
name: ${{ inputs.pr_number == 0 && 'Bench main' || format('Bench PR {0}', inputs.pr_number) }}
4141
needs: prepare-runner-labels
4242
runs-on: ${{ fromJson(needs.prepare-runner-labels.outputs.runner_labels_list) }}
4343
outputs:
@@ -55,8 +55,18 @@ jobs:
5555
# Parse PR number as integer (handle float inputs like "10.0")
5656
pr_int=$(printf "%.0f" "${{ inputs.pr_number }}")
5757
echo "pr_number=${pr_int}" >> "$GITHUB_OUTPUT"
58+
if [ "$pr_int" -eq 0 ]; then
59+
echo "is_main_run=true" >> "$GITHUB_OUTPUT"
60+
echo "target_ref=main" >> "$GITHUB_OUTPUT"
61+
echo "run_label=main" >> "$GITHUB_OUTPUT"
62+
else
63+
echo "is_main_run=false" >> "$GITHUB_OUTPUT"
64+
echo "target_ref=refs/pull/${pr_int}/head" >> "$GITHUB_OUTPUT"
65+
echo "run_label=pr-${pr_int}" >> "$GITHUB_OUTPUT"
66+
fi
5867
5968
- name: Comment benchmark start on PR
69+
if: steps.parse-pr.outputs.is_main_run != 'true'
6070
id: progress-comment
6171
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
6272
with:
@@ -72,10 +82,10 @@ jobs:
7282
});
7383
core.setOutput('comment_id', comment.id);
7484
75-
- name: Checkout PR head
85+
- name: Checkout target
7686
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
7787
with:
78-
ref: refs/pull/${{ steps.parse-pr.outputs.pr_number }}/head
88+
ref: ${{ steps.parse-pr.outputs.target_ref }}
7989
fetch-depth: 0
8090

8191
- name: Checkout main for baseline
@@ -109,6 +119,8 @@ jobs:
109119
with:
110120
path: ${{ env.CARGO_TARGET_DIR }}/criterion
111121
key: criterion-main-${{ runner.name }}-${{ steps.main_sha.outputs.sha }}
122+
restore-keys: |
123+
criterion-main-${{ runner.name }}-
112124
113125
- name: Run baseline on main (only if missing)
114126
if: steps.baseline-cache.outputs.cache-hit != 'true'
@@ -125,7 +137,11 @@ jobs:
125137
- name: Run benchmarks for PR against main baseline
126138
id: bench-pr
127139
run: |
128-
cargo bench --bench mpmc-throughput -- --measurement-time 20 --sample-size 50 --baseline main 2>&1 | tee bench_output.txt
140+
save_flag=()
141+
if [ "${{ steps.parse-pr.outputs.is_main_run }}" = "true" ]; then
142+
save_flag=(--save-baseline main)
143+
fi
144+
cargo bench --bench mpmc-throughput -- --measurement-time 20 --sample-size 50 --baseline main "${save_flag[@]}" 2>&1 | tee bench_output.txt
129145
130146
- name: Upload criterion reports
131147
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
@@ -287,8 +303,12 @@ jobs:
287303
# Output for next step
288304
cat results.md
289305
290-
- name: Comment benchmark artifact on PR
306+
- name: Publish job summary
291307
if: success()
308+
run: cat results.md >> "$GITHUB_STEP_SUMMARY"
309+
310+
- name: Comment benchmark artifact on PR
311+
if: success() && steps.parse-pr.outputs.is_main_run != 'true'
292312
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
293313
with:
294314
script: |
@@ -335,7 +355,7 @@ jobs:
335355
}
336356
337357
- name: Comment benchmark failure on PR
338-
if: failure()
358+
if: failure() && steps.parse-pr.outputs.is_main_run != 'true'
339359
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
340360
with:
341361
script: |

.github/workflows/bench-spsc.yml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
echo "runner_labels_list=[\"self-hosted\",\"bench\"${labels:+,\"$labels\"}]" >> "$GITHUB_OUTPUT"
3838
3939
benchmark:
40-
name: Bench PR #${{ inputs.pr_number }}
40+
name: ${{ inputs.pr_number == 0 && 'Bench main' || format('Bench PR {0}', inputs.pr_number) }}
4141
needs: prepare-runner-labels
4242
runs-on: ${{ fromJson(needs.prepare-runner-labels.outputs.runner_labels_list) }}
4343
outputs:
@@ -55,8 +55,18 @@ jobs:
5555
# Parse PR number as integer (handle float inputs like "10.0")
5656
pr_int=$(printf "%.0f" "${{ inputs.pr_number }}")
5757
echo "pr_number=${pr_int}" >> "$GITHUB_OUTPUT"
58+
if [ "$pr_int" -eq 0 ]; then
59+
echo "is_main_run=true" >> "$GITHUB_OUTPUT"
60+
echo "target_ref=main" >> "$GITHUB_OUTPUT"
61+
echo "run_label=main" >> "$GITHUB_OUTPUT"
62+
else
63+
echo "is_main_run=false" >> "$GITHUB_OUTPUT"
64+
echo "target_ref=refs/pull/${pr_int}/head" >> "$GITHUB_OUTPUT"
65+
echo "run_label=pr-${pr_int}" >> "$GITHUB_OUTPUT"
66+
fi
5867
5968
- name: Comment benchmark start on PR
69+
if: steps.parse-pr.outputs.is_main_run != 'true'
6070
id: progress-comment
6171
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
6272
with:
@@ -72,10 +82,10 @@ jobs:
7282
});
7383
core.setOutput('comment_id', comment.id);
7484
75-
- name: Checkout PR head
85+
- name: Checkout target
7686
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
7787
with:
78-
ref: refs/pull/${{ steps.parse-pr.outputs.pr_number }}/head
88+
ref: ${{ steps.parse-pr.outputs.target_ref }}
7989
fetch-depth: 0
8090

8191
- name: Checkout main for baseline
@@ -109,6 +119,8 @@ jobs:
109119
with:
110120
path: ${{ env.CARGO_TARGET_DIR }}/criterion
111121
key: criterion-main-${{ runner.name }}-${{ steps.main_sha.outputs.sha }}
122+
restore-keys: |
123+
criterion-main-${{ runner.name }}-
112124
113125
- name: Run baseline on main (only if missing)
114126
if: steps.baseline-cache.outputs.cache-hit != 'true'
@@ -125,7 +137,12 @@ jobs:
125137
- name: Run benchmarks for PR against main baseline
126138
id: bench-pr
127139
run: |
128-
cargo bench --bench spsc-throughput -- --measurement-time 20 --sample-size 50 --baseline main 2>&1 | tee bench_output.txt
140+
save_flag=()
141+
if [ "${{ steps.parse-pr.outputs.is_main_run }}" = "true" ]; then
142+
# Refresh baseline for next main run while comparing against the previous one.
143+
save_flag=(--save-baseline main)
144+
fi
145+
cargo bench --bench spsc-throughput -- --measurement-time 20 --sample-size 50 --baseline main "${save_flag[@]}" 2>&1 | tee bench_output.txt
129146
130147
- name: Upload criterion reports
131148
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
@@ -287,8 +304,12 @@ jobs:
287304
# Output for next step
288305
cat results.md
289306
290-
- name: Comment benchmark artifact on PR
307+
- name: Publish job summary
291308
if: success()
309+
run: cat results.md >> "$GITHUB_STEP_SUMMARY"
310+
311+
- name: Comment benchmark artifact on PR
312+
if: success() && steps.parse-pr.outputs.is_main_run != 'true'
292313
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
293314
with:
294315
script: |
@@ -335,7 +356,7 @@ jobs:
335356
}
336357
337358
- name: Comment benchmark failure on PR
338-
if: failure()
359+
if: failure() && steps.parse-pr.outputs.is_main_run != 'true'
339360
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
340361
with:
341362
script: |

0 commit comments

Comments
 (0)