mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
## Summary Gate 1 only for desktop release caching: - replaces canary `rust-cache` use with explicit exact-key `actions/cache/restore` + `save` - computes keys after `cargo update --workspace`, including platform, target, Rust toolchain, Cargo manifests/locks, profile/features, and native-toolchain inputs - normalizes only the desktop package version so a trusted `main` canary can warm an otherwise identical release tag - excludes Tauri bundle directories, so installers and signed artifacts are never cached - adds a restore-only `cache-proof-*` tag workflow that fails unless tag scope sees the exact default-branch cache - adds contract tests that enforce no release-workflow cache change in Gate 1 `release.yml` is intentionally unchanged. A cache miss remains the current cold canary build; the release path cannot be affected by merging this PR. ## Validation - `scripts/test-desktop-release-cache-key.sh` - `scripts/test-desktop-release-cache-workflow.sh` - `scripts/test-release-ref-contract.sh` - Ruby YAML parse of all four changed workflows - `git diff --check` - pre-push `branch-skew` ## Post-merge proof plan 1. Run each canary cold on trusted `main`, recording cache size/save time and fresh artifact inventory. 2. Run each canary warm, requiring the exact-key hit and recording restore/build time. 3. Create a disposable `cache-proof-*` tag at that same trusted `main` SHA and dispatch **Desktop release cache tag-scope proof** from the tag. 4. Do not begin Gate 2 or modify `release.yml` unless the exact tag-scope restore succeeds and cache transfer economics are favorable. --------- Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Carl <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz>
86 lines
2.8 KiB
Python
Executable File
86 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Compute an exact, version-agnostic Cargo release cache key."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import pathlib
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
DESKTOP_MANIFEST = pathlib.Path("desktop/src-tauri/Cargo.toml")
|
|
DESKTOP_LOCK = pathlib.Path("desktop/src-tauri/Cargo.lock")
|
|
|
|
|
|
def normalized(path: pathlib.Path, data: bytes) -> bytes:
|
|
text = data.decode()
|
|
if path == DESKTOP_MANIFEST:
|
|
text, count = re.subn(
|
|
r'(?ms)(^\[package\].*?^version\s*=\s*)"[^"]+"',
|
|
r'\1"<desktop-version>"',
|
|
text,
|
|
count=1,
|
|
)
|
|
if count != 1:
|
|
raise ValueError(f"could not normalize package version in {path}")
|
|
elif path == DESKTOP_LOCK:
|
|
text, count = re.subn(
|
|
r'(?ms)(^name = "buzz-desktop"\nversion = )"[^"]+"',
|
|
r'\1"<desktop-version>"',
|
|
text,
|
|
count=1,
|
|
)
|
|
if count != 1:
|
|
raise ValueError(f"could not normalize package version in {path}")
|
|
return text.encode()
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--platform", required=True)
|
|
parser.add_argument("--target", required=True)
|
|
parser.add_argument("--features", default="default")
|
|
parser.add_argument("--native-inputs", required=True)
|
|
args = parser.parse_args()
|
|
|
|
manifest_output = subprocess.check_output(
|
|
["git", "ls-files", "*Cargo.toml"], cwd=ROOT, text=True
|
|
)
|
|
paths = [ROOT / path for path in manifest_output.splitlines()]
|
|
paths += [ROOT / "Cargo.lock", ROOT / DESKTOP_LOCK, ROOT / "rust-toolchain.toml"]
|
|
cargo_config = ROOT / ".cargo/config.toml"
|
|
if cargo_config.exists():
|
|
paths.append(cargo_config)
|
|
|
|
digest = hashlib.sha256()
|
|
descriptors = {
|
|
"schema": "desktop-rust-release-v1",
|
|
"platform": args.platform,
|
|
"target": args.target,
|
|
"profile": "release",
|
|
"features": args.features,
|
|
"native-inputs": args.native_inputs,
|
|
"rustc": subprocess.check_output(["rustc", "-Vv"], text=True).strip(),
|
|
}
|
|
for name, value in sorted(descriptors.items()):
|
|
digest.update(f"{name}\0{value}\0".encode())
|
|
|
|
for absolute in sorted(set(paths)):
|
|
relative = absolute.relative_to(ROOT)
|
|
digest.update(str(relative).encode() + b"\0")
|
|
digest.update(normalized(relative, absolute.read_bytes()) + b"\0")
|
|
|
|
print(f"desktop-rust-release-v1-{args.platform}-{args.target}-{digest.hexdigest()}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
raise SystemExit(main())
|
|
except (OSError, ValueError, subprocess.CalledProcessError) as error:
|
|
print(f"error: {error}", file=sys.stderr)
|
|
raise SystemExit(1)
|