Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Release tools: nested stale build files, the boot baseline, index.html and the photo manifest (Refs #2694) (#2695)

Eyal Golan06f4ae6b82ec
diff --git a/tools/nightly.py b/tools/nightly.py
index 8e2ceef08..31481462e 100644
--- a/tools/nightly.py
+++ b/tools/nightly.py
@@ -765,8 +765,6 @@ def publish_night(night: Night, state: State, gh: GitHub, itch, zips: tuple[Path
state.open_draft = None
state.open_draft_id = None
state.last_published = Published(night.tag, night.sha, night.version, sizes, boot)
- if len(state.boot_baseline) < BASELINE_NIGHTS:
- state.boot_baseline.append(boot)
state.site_pending = night.version # until the demo serves this version, a later night retries the deploy
save()
if not use_itch:
@@ -778,6 +776,8 @@ def publish_night(night: Night, state: State, gh: GitHub, itch, zips: tuple[Path
try:
gh.dispatch_site(time.monotonic() + SITE_WAIT_SECONDS)
demo_serves(night.cfg.site_demo_url, night.version, deadline=time.monotonic() + SITE_WAIT_SECONDS)
+ if len(state.boot_baseline) < BASELINE_NIGHTS:
+ state.boot_baseline.append(boot)
state.site_pending = None
return
except Exception as e:
diff --git a/tools/package_release.py b/tools/package_release.py
index fdc870190..aee61885b 100644
--- a/tools/package_release.py
+++ b/tools/package_release.py
@@ -104,7 +104,7 @@ def translation_refusal(build: Path):
return None
-BUILD_FILE = re.compile(r'"Build/([^"/]+)"') # as the WebGL template writes them (src="Build/..", dataUrl: "Build/..")
+BUILD_FILE = re.compile(r'"Build/([^"]+)"') # as the WebGL template writes them (src="Build/..", dataUrl: "Build/..")
def build_files(build: Path) -> list[str]:
@@ -120,14 +120,20 @@ def package(build: Path, zip_path: Path) -> int:
if not content.is_dir():
print(f"PACKAGE REFUSED: {build} has no StreamingAssets/content")
return 1
- named = build_files(build)
+ try:
+ named = build_files(build)
+ except (OSError, UnicodeDecodeError) as e:
+ print(f"PACKAGE REFUSED: {build / 'index.html'} cannot be read as UTF-8 ({e})")
+ return 1
if not named:
print("PACKAGE REFUSED: index.html names no Build/ files (not a usable WebGL build)")
return 1
if missing := [n for n in named if not (build / "Build" / n).is_file()]:
print("PACKAGE REFUSED: index.html names files that are not in the build: " + ", ".join("Build/" + n for n in missing))
return 1
- stale = {p for p in (build / "Build").glob("*") if p.is_file() and p.name not in named}
+ build_dir = build / "Build"
+ stale = {p for p in build_dir.rglob("*")
+ if p.is_file() and p.relative_to(build_dir).as_posix() not in named}
if (photos := photo_refusal(build)) is not None:
print(f"PACKAGE REFUSED: {photos}")
return 1
@@ -144,7 +150,8 @@ def package(build: Path, zip_path: Path) -> int:
for f in sorted(p for p in build.rglob("*") if p.is_file() and p not in stale):
z.write(f, f.relative_to(build).as_posix())
for f in sorted(stale):
- print(f"LEFT OUT Build/{f.name} (index.html does not name it: a file of an earlier build)")
+ print(f"LEFT OUT Build/{f.relative_to(build_dir).as_posix()} "
+ "(index.html does not name it: a file of an earlier build)")
print(f"PACKAGED {zip_path} {zip_path.stat().st_size} bytes")
return 0
diff --git a/tools/release_build.py b/tools/release_build.py
index 6b8dc5158..25f89668a 100644
--- a/tools/release_build.py
+++ b/tools/release_build.py
@@ -651,6 +651,9 @@ def main(argv: list[str] | None = None) -> int:
print(f"FAILED: the {p.name} build (exit {code}); see {log}", file=sys.stderr)
return 1
folder = target.parent
+ if not (folder / PHOTOS).is_file():
+ print(f"FAILED: the {p.name} build has no {PHOTOS}", file=sys.stderr)
+ return 1
if a.steam and (problem := steam_folder_problem(folder, p.name)):
print(f"FAILED: {problem}", file=sys.stderr)
return 1
@@ -658,11 +661,9 @@ def main(argv: list[str] | None = None) -> int:
text, files, size = tree_manifest(folder, mac=p.name == "mac")
listing = out / f"files-{p.name}.sha256"
listing.write_text(text)
- photos = None
- if (folder / PHOTOS).is_file():
- copy = out / f"event-photos-{p.name}.json"
- copy.write_bytes((folder / PHOTOS).read_bytes())
- photos = {"file": copy.name, "sha256": file_sha256(copy)}
+ copy = out / f"event-photos-{p.name}.json"
+ copy.write_bytes((folder / PHOTOS).read_bytes())
+ photos = {"file": copy.name, "sha256": file_sha256(copy)}
if problem := player_problem(p, folder):
print(f"FAILED: {problem}", file=sys.stderr)
return 1
diff --git a/tools/tests/test_nightly.py b/tools/tests/test_nightly.py
index 55cd69a39..9be2bed2f 100644
--- a/tools/tests/test_nightly.py
+++ b/tools/tests/test_nightly.py
@@ -1365,6 +1365,26 @@ def test_a_site_failure_after_publish_retries_once_then_refuses_and_marks_site_p
assert "restored previous Latest v0.3.1" in e.value.detail
+def test_a_site_refusal_does_not_enter_the_boot_baseline_through_run_night(env, pub, monkeypatch):
+ err = ns.Refused("site", "run failed")
+ gh = FakeGH(fail={"dispatch_site": [err, err]})
+ baseline = [8000.0, 8100.0]
+ state = ns.State(last_published=last_published(), boot_baseline=list(baseline))
+ monkeypatch.setattr(nightly, "run_gates", lambda night, runner: None)
+ monkeypatch.setattr(nightly, "run_editmode", lambda night, runner: None)
+ monkeypatch.setattr(nightly, "_build_both", lambda night, runner, free_gb: pub)
+ monkeypatch.setattr(nightly, "package_zip", lambda night, runner, build, pages: pub[1 if pages else 0])
+ monkeypatch.setattr(nightly, "run_web_checks", lambda night, runner, build: None)
+ monkeypatch.setattr(nightly, "previous_build", lambda night, state, client, runner: PREVIOUS)
+ monkeypatch.setattr(nightly, "check_sizes", lambda *args, **kwargs: SIZES)
+ monkeypatch.setattr(nightly, "measure_boot", lambda night, runner, build: BOOT_MS)
+ monkeypatch.setattr(nightly, "run_steam", lambda night, runner: None)
+ assert env.night(state, gh) == "REFUSED"
+ saved = ns.load_state(env.state_path)
+ assert saved.boot_baseline == baseline
+ assert "REFUSED" in env.log()
+
+
def test_a_site_refusal_records_the_restored_latest_in_the_nightly_log(env, pub, served, monkeypatch):
err = ns.Refused("site", "run failed")
gh = FakeGH(fail={"dispatch_site": [err, err]})
diff --git a/tools/tests/test_package_release.py b/tools/tests/test_package_release.py
index fc38d4f65..3bdf03bf9 100644
--- a/tools/tests/test_package_release.py
+++ b/tools/tests/test_package_release.py
@@ -202,6 +202,58 @@ def test_files_of_an_earlier_build_are_left_out_of_the_zip(tmp_path, capsys):
assert "LEFT OUT Build/ffffffffffffffffffffffffffffffff.data.br" in capsys.readouterr().out
+def test_nested_files_of_an_earlier_build_are_left_out_of_the_zip(tmp_path, capsys):
+ build, zip_path = hashed_build(tmp_path), tmp_path / "out.zip"
+ stale = build / "Build" / "old" / "files" / "earlier.data.br"
+ stale.parent.mkdir(parents=True)
+ stale.write_bytes(b"old")
+ assert package_release.main(["--build", str(build), "--zip", str(zip_path)]) == 0
+ with zipfile.ZipFile(zip_path) as z:
+ assert "Build/old/files/earlier.data.br" not in z.namelist()
+ assert "LEFT OUT Build/old/files/earlier.data.br" in capsys.readouterr().out
+
+
+def test_a_nested_file_the_index_names_is_kept(tmp_path, capsys):
+ """#2695 review: only unnamed files are stale; a nested path index.html names still ships."""
+ build, zip_path = hashed_build(tmp_path), tmp_path / "out.zip"
+ named = build / "Build" / "extra" / "module.js"
+ named.parent.mkdir(parents=True)
+ named.write_bytes(b"kept")
+ index = build / "index.html"
+ index.write_text(index.read_text(encoding="utf-8") + '<script src="Build/extra/module.js"></script>\n',
+ encoding="utf-8")
+ assert package_release.main(["--build", str(build), "--zip", str(zip_path)]) == 0
+ with zipfile.ZipFile(zip_path) as z:
+ assert "Build/extra/module.js" in z.namelist()
+ assert "LEFT OUT Build/extra/module.js" not in capsys.readouterr().out
+
+
+def test_an_index_that_is_not_utf8_is_refused_without_a_zip(tmp_path, capsys):
+ build, zip_path = fake_build(tmp_path, reviewed=True), tmp_path / "out.zip"
+ (build / "index.html").write_bytes(b"<html>\xff</html>")
+ assert package_release.main(["--build", str(build), "--zip", str(zip_path)]) == 1
+ assert not zip_path.exists()
+ out = capsys.readouterr().out
+ assert "PACKAGE REFUSED" in out and "index.html" in out and "UTF-8" in out
+
+
+def test_an_index_that_cannot_be_read_is_refused_without_a_zip(tmp_path, capsys, monkeypatch):
+ build, zip_path = fake_build(tmp_path, reviewed=True), tmp_path / "out.zip"
+ index = build / "index.html"
+ read_text = Path.read_text
+
+ def fail_index(path, *args, **kwargs):
+ if path == index:
+ raise OSError("read failed")
+ return read_text(path, *args, **kwargs)
+
+ monkeypatch.setattr(package_release.Path, "read_text", fail_index)
+ assert package_release.main(["--build", str(build), "--zip", str(zip_path)]) == 1
+ assert not zip_path.exists()
+ out = capsys.readouterr().out
+ assert "PACKAGE REFUSED" in out and "index.html" in out and "UTF-8" in out
+
+
def test_a_build_missing_a_file_index_html_names_is_refused(tmp_path, capsys):
build = hashed_build(tmp_path)
(build / "Build" / HASHED[3]).unlink()
diff --git a/tools/tests/test_release_build.py b/tools/tests/test_release_build.py
index 90687a3b2..af3f94170 100644
--- a/tools/tests/test_release_build.py
+++ b/tools/tests/test_release_build.py
@@ -68,7 +68,7 @@ class Fake:
def __init__(self, dirty="", golden_ok=True, build_ok=True, branch="main", tags=("v0.1.0",), worktrees=None,
build_raises=None, dirty_after="", on_origin_main=True, fail_status=False,
fail_status_after=False, fail_worktree_list=False, sim_ok=True, sim_output="", fail_checkout=False,
- lipo_code=0, lipo_out="x86_64 arm64\n"):
+ lipo_code=0, lipo_out="x86_64 arm64\n", photo_manifest=True):
self.calls: list[list[str]] = []
self.dirty, self.golden_ok, self.build_ok = dirty, golden_ok, build_ok
self.branch, self.tags, self.worktrees = branch, tags, worktrees
@@ -81,6 +81,7 @@ class Fake:
self.fail_checkout = fail_checkout
self.lipo_code = lipo_code
self.lipo_out = lipo_out
+ self.photo_manifest = photo_manifest
def __call__(self, cmd, **kw):
cmd = [str(c) for c in cmd]
@@ -128,7 +129,8 @@ class Fake:
else:
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(b"player " + target.name.encode())
- (target.parent / "event-photos.json").write_text("{}\n")
+ if self.photo_manifest:
+ (target.parent / "event-photos.json").write_text("{}\n")
if "-steam" in cmd and self.steam_library: # #2154's Build.cs ships Valve's plugin only in -steam builds
lib = {".app": "Contents/PlugIns/steam_api.bundle/Contents/MacOS/libsteam_api.dylib",
".exe": "../Statecraft_Data/Plugins/x86_64/steam_api64.dll",
@@ -580,6 +582,19 @@ def test_a_failed_build_stops_with_no_record(repo, editor, monkeypatch, tmp_path
assert [c for c in fake.calls if c[:2] == ["git", "checkout"]], "the settings are restored even after a failure"
+def test_a_build_without_its_photo_manifest_stops_before_archive_and_record(repo, editor, monkeypatch, tmp_path, capsys):
+ fake = Fake(photo_manifest=False)
+ out = tmp_path / "out"
+ assert run_main(["--platform", "mac", "--out", str(out)], repo, editor, fake, monkeypatch) == 1
+ assert not (out / "players/mac/LICENSE").exists()
+ assert not (out / "event-photos-mac.json").exists()
+ assert not (out / "files-mac.sha256").exists()
+ assert not (out / "statecraft-israel-v0.1.0-macos-universal.zip").exists()
+ assert not (out / "build-record.json").exists()
+ err = capsys.readouterr().err
+ assert "FAILED" in err and "mac" in err and "event-photos.json" in err
+
+
# --- the record ----------------------------------------------------------------------------------------------------------
def test_the_record_holds_commit_unity_date_hashes_sizes_and_goldens(repo, editor, monkeypatch, tmp_path, capsys):