Skip to content

Open-source skills for designing and reviewing software with AI agents

Fix cleanup after partial release build failure (#187)

Anmol Jauhar56cbdd1fdc59
diff --git a/scripts/prepare_release.py b/scripts/prepare_release.py
index 439648a..87489c0 100644
--- a/scripts/prepare_release.py
+++ b/scripts/prepare_release.py
@@ -6,6 +6,7 @@ import hashlib
import json
from pathlib import Path
import re
+import shutil
from pack_plugin import build
@@ -53,33 +54,37 @@ def prepare(root: Path, tag: str, output: Path, commit: str) -> None:
if len(commit) != 40 or any(char not in "0123456789abcdef" for char in commit):
raise ValueError("Source commit must be a full Git SHA")
output.mkdir(parents=True, exist_ok=False)
- checksums = []
- for target in ("claude", "openai"):
- _, archive = build(root, target, output / "build")
- destination = output / f"egm-{target}-{version}.zip"
- archive.rename(destination)
- digest = hashlib.sha256(destination.read_bytes()).hexdigest()
- checksums.append(f"{digest} {destination.name}\n")
- (output / "SHA256SUMS").write_text("".join(checksums), encoding="utf-8")
- (output / "RELEASE_NOTES.md").write_text(
- f"# EGM {version}\n\nDeclared source: `{commit}`\nTag: `{tag}`\n\n"
- "Local source identity is caller-supplied and is not verified by this script. "
- "Publish only workflow-built candidates after exact-artifact checks.\n\n"
- "Runtime archives: Claude and OpenAI. Verify downloads with "
- "`sha256sum -c SHA256SUMS`.\n\n"
- "For CI-built candidates, verify each ZIP with "
- "`gh attestation verify FILE --repo google/elephant-goldfish-model "
- "--signer-workflow google/elephant-goldfish-model/.github/workflows/release.yml "
- "--source-ref refs/heads/main`. "
- "Provenance identifies the main-branch workflow run; the tagged source "
- "commit is recorded above. Local builds have no attestation.\n\n"
- "## Changes\n\nMaintainer: summarize changes and migration steps before publishing.\n\n"
- "## Verification\n\nOffline unit tests and runtime packaging are checked by CI. "
- "Live installation, workflow execution, reviewer isolation, directory approval, "
- "and cloud-host support are not established by this build. "
- "Maintainer: attach exact-bundle host evidence and limitations before publishing.\n",
- encoding="utf-8",
- )
+ try:
+ checksums = []
+ for target in ("claude", "openai"):
+ _, archive = build(root, target, output / "build")
+ destination = output / f"egm-{target}-{version}.zip"
+ archive.rename(destination)
+ digest = hashlib.sha256(destination.read_bytes()).hexdigest()
+ checksums.append(f"{digest} {destination.name}\n")
+ (output / "SHA256SUMS").write_text("".join(checksums), encoding="utf-8")
+ (output / "RELEASE_NOTES.md").write_text(
+ f"# EGM {version}\n\nDeclared source: `{commit}`\nTag: `{tag}`\n\n"
+ "Local source identity is caller-supplied and is not verified by this script. "
+ "Publish only workflow-built candidates after exact-artifact checks.\n\n"
+ "Runtime archives: Claude and OpenAI. Verify downloads with "
+ "`sha256sum -c SHA256SUMS`.\n\n"
+ "For CI-built candidates, verify each ZIP with "
+ "`gh attestation verify FILE --repo google/elephant-goldfish-model "
+ "--signer-workflow google/elephant-goldfish-model/.github/workflows/release.yml "
+ "--source-ref refs/heads/main`. "
+ "Provenance identifies the main-branch workflow run; the tagged source "
+ "commit is recorded above. Local builds have no attestation.\n\n"
+ "## Changes\n\nMaintainer: summarize changes and migration steps before publishing.\n\n"
+ "## Verification\n\nOffline unit tests and runtime packaging are checked by CI. "
+ "Live installation, workflow execution, reviewer isolation, directory approval, "
+ "and cloud-host support are not established by this build. "
+ "Maintainer: attach exact-bundle host evidence and limitations before publishing.\n",
+ encoding="utf-8",
+ )
+ except Exception:
+ shutil.rmtree(output, ignore_errors=True)
+ raise
if __name__ == "__main__":
diff --git a/tests/unit/test_releases.py b/tests/unit/test_releases.py
index d55d4bb..1c07e90 100644
--- a/tests/unit/test_releases.py
+++ b/tests/unit/test_releases.py
@@ -72,3 +72,34 @@ def test_reject_invalid_commit_without_writing(
with pytest.raises(ValueError, match="Git SHA"):
release["prepare"](ROOT, f"v{version}", destination, commit)
assert not destination.exists()
+
+
+def test_prepare_cleans_partial_output_after_build_failure(
+ release: dict, tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ version = json.loads((ROOT / "plugin.json").read_text())["version"]
+ destination = tmp_path / "release"
+ prepare = release["prepare"]
+ original_build = prepare.__globals__["build"]
+ calls = 0
+
+ def fail_second_build(*args, **kwargs):
+ nonlocal calls
+ calls += 1
+ if calls == 2:
+ raise RuntimeError("Simulated second-build failure")
+ return original_build(*args, **kwargs)
+
+ monkeypatch.setitem(prepare.__globals__, "build", fail_second_build)
+
+ with pytest.raises(RuntimeError, match="Simulated second-build failure"):
+ release["prepare"](ROOT, f"v{version}", destination, "a" * 40)
+
+ assert not destination.exists()
+
+ monkeypatch.setitem(prepare.__globals__, "build", original_build)
+ release["prepare"](ROOT, f"v{version}", destination, "a" * 40)
+
+ assert (destination / f"egm-claude-{version}.zip").is_file()
+ assert (destination / f"egm-openai-{version}.zip").is_file()
+ assert (destination / "SHA256SUMS").is_file()