Skip to content

Commit 13436cc

Browse files
committed
fix(size-benchmark): stable worktree paths for cache hits, merge-base for base ref
1 parent a61cce3 commit 13436cc

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

.github/workflows/pr-binary-size.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ jobs:
2424
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
2525
with:
2626
cache-targets: true
27+
prefix-key: v0-rust-binary-size
2728

2829
- name: Compare binary size
2930
run: |
31+
BASE=$(git merge-base origin/main HEAD)
3032
bash size-benchmark/compare-size.sh \
31-
--base ${{ github.event.pull_request.base.sha }} \
33+
--base "$BASE" \
3234
--head ${{ github.sha }} \
3335
--output size-report.md
3436

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ examples/cxx/exporter_manager.exe
3232
examples/cxx/profiling
3333
examples/cxx/profiling.exe
3434
profile.pprof
35+
.worktree-size-*

size-benchmark/compare-size.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@ format_bytes() {
3838
fi
3939
}
4040

41-
# Build a ref in a temporary worktree, print byte count to stdout.
41+
# Build a ref in a worktree placed inside the repo root so that Cargo's
42+
# path-based fingerprints are stable across runs (no /tmp/tmp.xxx/ variance).
4243
build_ref() {
4344
local ref="$1"
4445
local label="$2"
45-
local worktree
46-
worktree="$(mktemp -d)"
46+
local short
47+
short="$(git -C "$REPO_ROOT" rev-parse --short "$ref")"
48+
local worktree="$REPO_ROOT/.worktree-size-$label"
4749

48-
echo "Building $label ($(git -C "$REPO_ROOT" rev-parse --short "$ref"))…" >&2
50+
echo "Building $label ($short)…" >&2
4951

5052
git -C "$REPO_ROOT" worktree add --detach "$worktree" "$ref" 2>&1 | sed 's/^/ /' >&2
5153

5254
# cargo writes to stderr; wc -c is the only stdout line.
5355
# Always use the script from the current checkout (base may not have it).
54-
# Override WORKSPACE_ROOT so the script builds the worktree, not itself.
55-
# Point CARGO_TARGET_DIR at the main worktree so both builds share the cache.
56-
# Redirect build stderr → our stderr so CI logs show progress.
56+
# Override WORKSPACE_ROOT so the script builds the worktree's sources.
57+
# CARGO_TARGET_DIR is fixed so both refs share the same build cache.
5758
CARGO_TARGET_DIR="$REPO_ROOT/target" \
5859
WORKSPACE_ROOT="$worktree" \
5960
bash "$BUILD_SCRIPT" 2>&3
60-
# (stdout = byte count, captured by the caller via $())
6161

6262
git -C "$REPO_ROOT" worktree remove --force "$worktree" 2>/dev/null || true
6363
rm -rf "$worktree"

0 commit comments

Comments
 (0)