A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix: align demo deployment with recovered Latest (#1993)
Eyal Golanb399ce5a8d5b
diff --git a/.github/workflows/site.yml b/.github/workflows/site.ymlindex c109e50df..4722e456e 100644--- a/.github/workflows/site.yml+++ b/.github/workflows/site.yml@@ -46,23 +46,41 @@ jobs:permissions:contents: readsteps:- - name: Unpack the latest release's Pages build at /demo/+ - name: Unpack the Latest release's Pages build at /demo/env:GH_TOKEN: ${{ github.token }}run: |set -euo pipefail# Every failure stops the run, so Pages keeps serving the last good deploy: no release, no# *-web-pages.zip in it, an empty or incomplete zip, or a lookup error never deploys an empty site.- # `gh release view/download` without a tag resolve the latest non-prerelease, so read the newest- # published (non-draft) release's tag from the list and pass it to both calls.- tag="$(gh release list --repo "$GITHUB_REPOSITORY" --limit 1 --exclude-drafts --json tagName --jq '.[0].tagName // empty')"- if [ -z "$tag" ]; then- echo "::error::No published release: nothing to deploy."+ # The demo follows GitHub's Latest release, the one tools/nightly.py restores after a failed night, so a+ # failed nightly that stays published is never deployed (the newest published release can be that one).+ # Only HTTP 404 (no Latest at all) falls back to the newest published prerelease, the historic case;+ # nightlies are created with prerelease=false, so the fallback cannot pick a failed nightly either. Any+ # other lookup error (auth, network, rate limit, 5xx) stops the run. The tag is passed to view and download.+ err="$(mktemp)"+ if tag="$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq '.tag_name' 2>"$err")"; then+ if [ -z "$tag" ] || [ "$tag" = "null" ]; then+ echo "::error::releases/latest returned no usable tag: nothing to deploy."+ exit 1+ fi+ from="Latest"+ elif grep -q 'HTTP 404' "$err"; then+ tag="$(gh release list --repo "$GITHUB_REPOSITORY" --limit 100 --exclude-drafts --json tagName,isPrerelease \+ --jq '[.[] | select(.isPrerelease)][0].tagName // empty')"+ from="newest prerelease (no Latest)"+ if [ -z "$tag" ]; then+ echo "::error::No Latest release and no published prerelease: nothing to deploy."+ exit 1+ fi+ else+ cat "$err" >&2+ echo "::error::The Latest release lookup failed (not a 404): nothing deployed."exit 1fiasset="$(gh release view "$tag" --repo "$GITHUB_REPOSITORY" --json assets --jq '[.assets[].name | select(endswith("-web-pages.zip"))] | first // empty')"if [ -z "$asset" ]; then- echo "::error::No *-web-pages.zip in the latest release ($tag): nothing to deploy."+ echo "::error::No *-web-pages.zip in the $from release ($tag): nothing to deploy."exit 1fimkdir -p "$RUNNER_TEMP/web-pages" dist/demo@@ -70,7 +88,7 @@ jobs:unzip -q -o "$RUNNER_TEMP/web-pages/$asset" -d dist/demotest -f dist/demo/index.htmljq -e '.shareable == true' dist/demo/event-photos.json > /dev/null- echo "Demo at /demo/ from $asset ($tag)"+ echo "Demo at /demo/ from $asset ($from $tag)"- name: Write the root page, a redirect to /demo/run: |set -euo pipefaildiff --git a/changelog.d/release-pages-latest-recovery.md b/changelog.d/release-pages-latest-recovery.mdnew file mode 100644index 000000000..633e8d65b--- /dev/null+++ b/changelog.d/release-pages-latest-recovery.md@@ -0,0 +1,3 @@+### Fixed++- Make the playable demo follow GitHub Latest after release recovery, preserving the historical prerelease fallback when no Latest exists. Report a failed post-publication demo check as unverified rather than claiming it stayed unchanged.diff --git a/docs/RELEASING.md b/docs/RELEASING.mdindex 15c698648..57f55cc65 100644--- a/docs/RELEASING.md+++ b/docs/RELEASING.md@@ -73,7 +73,7 @@ macOS IL2CPP parity check is not an MVP release gate.```Publishing a release starts the Pages deploy (`.github/workflows/site.yml`, on `main`; `gh workflow run site.yml`- starts one on demand). It unpacks the newest published release's `statecraft-israel-vX.Y.Z-web-pages.zip` at+ starts one on demand). It unpacks the Latest release's `statecraft-israel-vX.Y.Z-web-pages.zip` at`/demo/` (https://eyalgolan.github.io/statecraft-israel/demo/) and the root page redirects there. It fails, andPages keeps the last deploy, when that release has no such zip, the zip has no `index.html`, or its`event-photos.json` is not `shareable`. The demo is never in git (no file in the repository may pass 10 MB).@@ -175,6 +175,8 @@ macOS IL2CPP parity check is not an MVP release gate.## Nightly builds+`site.yml` selects GitHub Latest for `/demo/`, matching the release chosen by nightly recovery. Only when the Latest lookup returns HTTP 404 does it fall back to the newest published prerelease, and with neither it deploys nothing. Other lookup failures stop deployment. A post-publication site failure leaves the served demo unverified; it must not be reported as unchanged without readback.+Every night at 03:00 (Israel time) the newest `main` is built and, only if every gate passes, becomes the public webgame: a normal GitHub release marked **Latest**, tagged `vX.Y.Z`, which GitHub Pages' `/demo/` serves, and, once itchpushes are enabled, the itch.io page. X.Y.Z is one patch above the numerically highest published release tag matchingdiff --git a/tools/nightly.py b/tools/nightly.pyindex 9fe1e5a53..6c9216962 100644--- a/tools/nightly.py+++ b/tools/nightly.py@@ -180,6 +180,11 @@ def preflight(cfg: Config, state: State, runner: Runner, gh: GitHub, *, job: Patdetail = f"main unchanged since {last.tag}"if state.site_pending and not no_publish: # a deploy is a public change, so --no-publish never starts onetry:+ latest = gh.latest_tag()+ if latest is None:+ raise Refused("site", "no Latest target; pending demo verification remains open")+ # The workflow follows Latest, including after recovery; never wait for a rolled-back version.+ state.site_pending = latest[1:] if latest.startswith("v") else latestgh.dispatch_site(time.monotonic() + SITE_WAIT_SECONDS)demo_serves(cfg.site_demo_url, state.site_pending,deadline=time.monotonic() + SITE_WAIT_SECONDS)@@ -746,7 +751,8 @@ def publish_night(night: Night, state: State, gh: GitHub, itch, zips: tuple[Pathreturnexcept Exception as e:failure = _detail(e)- raise Refused("site", f"{night.tag} is public and the demo is unchanged: {failure}")+ raise Refused("site", f"{night.tag} is public; the demo was not verified to serve {night.version} "+ f"and may have changed (unverified): {failure}")except BaseException as e:detail = _detail(e)if publish_started:diff --git a/tools/tests/test_nightly.py b/tools/tests/test_nightly.pyindex 3cf2c7773..4260f1c31 100644--- a/tools/tests/test_nightly.py+++ b/tools/tests/test_nightly.py@@ -397,8 +397,9 @@ def test_site_pending_is_retried_before_skipping(env, monkeypatch):served = []monkeypatch.setattr(nightly, "demo_serves", lambda url, version, *, deadline: served.append((url, version, deadline)))gh = FakeGH()+ gh.latest = "v0.3.0-nightly.20261027"assert env.night(pending_state(), gh) == "SKIPPED"- assert gh.names() == ["dispatch_site"] and gh.calls[0][1] > time.monotonic()+ assert gh.names() == ["latest_tag", "dispatch_site"] and gh.calls[1][1] > time.monotonic()assert [s[:2] for s in served] == [(env.cfg.site_demo_url, "0.3.0-nightly.20261027")]assert ns.load_state(env.state_path).site_pending is None # the retry worked, so nothing is pendingassert "SKIPPED" in env.log() and "now serves" in env.log()@@ -411,8 +412,9 @@ def test_a_failing_site_retry_stays_pending_and_the_night_stays_skipped(env, monraise ns.Refused("site", "still serves 0.3.0")monkeypatch.setattr(nightly, "demo_serves", demo)gh = FakeGH(fail={"dispatch_site": ns.Refused("site", "run failed")} if where == "dispatch" else None)+ gh.latest = "v0.3.1"assert env.night(pending_state(), gh) == "SKIPPED"- assert ns.load_state(env.state_path).site_pending == "0.3.0-nightly.20261027"+ assert ns.load_state(env.state_path).site_pending == "0.3.1"assert "SKIPPED" in env.log() and "still failed" in env.log() and env_notes == []@@ -423,8 +425,9 @@ def test_a_non_refusal_error_in_the_site_retry_keeps_the_night_skipped_and_pendiraise KeyError("databaseId")monkeypatch.setattr(nightly, "demo_serves", demo)gh = FakeGH(fail={"dispatch_site": KeyError("databaseId")} if where == "dispatch" else None)+ gh.latest = "v0.3.1"assert env.night(pending_state(), gh) == "SKIPPED"- assert ns.load_state(env.state_path).site_pending == "0.3.0-nightly.20261027"+ assert ns.load_state(env.state_path).site_pending == "0.3.1"assert "KeyError" in env.log() and "still failed" in env.log()@@ -1329,7 +1332,9 @@ def test_a_site_failure_after_publish_retries_once_then_refuses_and_marks_site_pst = ns.State(last_published=last_published())with pytest.raises(ns.Refused) as e:publish(night, st, gh, pub, env)- assert e.value.gate == "site" and "public" in e.value.detail and "unchanged" in e.value.detail+ assert e.value.gate == "site" and "public" in e.value.detail+ assert "unchanged" not in e.value.detail+ assert "unverified" in e.value.detail and "may have changed" in e.value.detailassert gh.names().count("dispatch_site") == 2 and "delete_draft" not in gh.names()assert st.last_published.tag == TAG and st.last_published.sha == night.sha # the release is publicassert st.site_pending == night.version and st.open_draft is None@@ -2634,7 +2639,7 @@ def test_failed_recovery_is_persisted_then_retried_before_next_preflight(night,gh.fail.clear()gh.calls.clear()assert env.night(gh=gh) == "SKIPPED"- assert gh.names() == ["restore_latest", "dispatch_site"]+ assert gh.names() == ["restore_latest", "latest_tag", "dispatch_site"]assert gh.latest == "v0.3.1"assert ns.load_state(env.state_path).latest_recovery_pending is Noneassert "restored previous Latest v0.3.1" in env.log()@@ -2679,7 +2684,7 @@ def test_pending_recovery_precedes_unchanged_main_and_site_retry(env, monkeypatcgh.dispatch_site = dispatchmonkeypatch.setattr(nightly, "demo_serves", lambda *a, **k: None)assert env.night(gh=gh) == "SKIPPED"- assert gh.names() == ["restore_latest"] + (["dispatch_site"] if site_pending else [])+ assert gh.names() == ["restore_latest"] + (["latest_tag", "dispatch_site"] if site_pending else [])assert observations == ([("v0.3.1", None)] if site_pending else [])assert json.loads(env.state_path.read_text()).get("latest_recovery_pending") is Nonegh.calls.clear()@@ -2816,3 +2821,24 @@ def test_raising_recovery_save_still_repairs_latest_and_returns_refusal(env, faiassert err is Noneassert saves == ["checkpoint", "result"] and not recoveredassert "could not be saved" in detail and "check by hand" in detail+[email protected]("latest", ["v0.3.1", "v0.4.0"])+def test_pending_demo_verifies_current_latest_after_rollback(env, monkeypatch, latest):+ gh = FakeGH(); gh.latest = latest+ served = []+ monkeypatch.setattr(nightly, "demo_serves", lambda url, version, *, deadline: served.append(version))+ assert env.night(ns.State(last_published=ns.Published(TAG, SHA, "0.3.2", {}, None), site_pending="0.3.2"), gh) == "SKIPPED"+ assert served == [latest[1:]]+ assert gh.latest == latest and gh.names() == ["latest_tag", "dispatch_site"]+ assert ns.load_state(env.state_path).site_pending is None+ gh.calls.clear()+ assert env.night(gh=gh) == "SKIPPED" and gh.calls == []+[email protected]("missing", [True, False])+def test_pending_demo_without_verified_latest_preserves_hold_and_never_dispatches(env, monkeypatch, missing):+ gh = FakeGH(fail={} if missing else {"latest_tag": OSError("offline")})+ if missing: gh.latest = None+ monkeypatch.setattr(nightly, "demo_serves", lambda *a, **k: pytest.fail("unverified Latest must not be served"))+ assert env.night(ns.State(last_published=ns.Published(TAG, SHA, "0.3.2", {}, None), site_pending="0.3.2"), gh) == "SKIPPED"+ assert gh.names() == ["latest_tag"]+ assert ns.load_state(env.state_path).site_pending == "0.3.2"diff --git a/tools/tests/test_site_demo_selection.py b/tools/tests/test_site_demo_selection.pynew file mode 100644index 000000000..1117e5689--- /dev/null+++ b/tools/tests/test_site_demo_selection.py@@ -0,0 +1,82 @@+import os, stat, subprocess, sys, textwrap+from pathlib import Path+import pytest++WORKFLOW = Path(__file__).resolve().parents[2] / ".github/workflows/site.yml"+STEP = "- name: Unpack the Latest release's Pages build at /demo/"++def step_script() -> str:+ lines = WORKFLOW.read_text(encoding="utf-8").splitlines()+ i = next(n for n, l in enumerate(lines) if STEP in l)+ j = next(n for n in range(i, len(lines)) if lines[n].strip() == "run: |")+ indent = len(lines[j]) - len(lines[j].lstrip())+ body = []+ for l in lines[j + 1:]:+ if l.strip() and len(l) - len(l.lstrip()) <= indent:+ break+ body.append(l)+ return textwrap.dedent("\n".join(body))++FAKE_GH = r'''#!/usr/bin/env python3+import json, os, sys, subprocess+a = sys.argv[1:]+open(os.environ["GH_LOG"], "a").write(" ".join(a) + "\n")+latest = os.environ["LATEST"] # a tag, "404", or "403"+rows = json.loads(os.environ["RELEASES"]) # newest first: [{"tagName":..,"isPrerelease":..}]+if a[:1] == ["api"]:+ assert a[1] == "repos/maintainer/statecraft-israel/releases/latest"+ if latest in ("404", "403", "500"):+ sys.stderr.write(f"gh: HTTP {latest}\n"); sys.exit(1)+ data = {"tag_name": latest}+ result = subprocess.run(["jq", "-r", a[a.index("--jq") + 1]], input=json.dumps(data), text=True)+ sys.exit(result.returncode)+if a[:2] == ["release", "list"]:+ if os.environ.get("LIST_FAIL") == "1": sys.stderr.write("gh: offline\n"); sys.exit(1)+ result = subprocess.run(["jq", "-r", a[a.index("--jq") + 1]], input=json.dumps(rows), text=True)+ sys.exit(result.returncode)+if a[:2] == ["release", "view"]:+ print(""); sys.exit(0) # no pages zip: the step stops (exit 1) after naming the tag+sys.exit(99)+'''++def run(tmp_path, latest, releases, *, list_fail=False):+ bin_ = tmp_path / "bin"; bin_.mkdir()+ gh = bin_ / "gh"; gh.write_text(FAKE_GH); gh.chmod(gh.stat().st_mode | stat.S_IEXEC)+ log = tmp_path / "gh.log"; log.write_text("")+ env = {**os.environ, "PATH": f"{bin_}:{os.environ['PATH']}", "GH_LOG": str(log),+ "LATEST": latest, "RELEASES": __import__("json").dumps(releases),+ "GITHUB_REPOSITORY": "maintainer/statecraft-israel", "LIST_FAIL": str(int(list_fail))}+ p = subprocess.run(["bash", "-c", step_script()], cwd=tmp_path, env=env, capture_output=True, text=True)+ return p, log.read_text()++FAILED = {"tagName": "v0.3.2", "isPrerelease": False} # failed nightly, still published, no longer Latest+GOOD = {"tagName": "v0.3.1", "isPrerelease": False}+HIST = {"tagName": "v0.1.0-pre", "isPrerelease": True}++def test_demo_follows_restored_latest_not_newest_published(tmp_path):+ p, log = run(tmp_path, "v0.3.1", [FAILED, GOOD, HIST])+ assert "release view v0.3.1" in log and "v0.3.2" not in log+ assert p.returncode == 1 and "No *-web-pages.zip in the Latest release (v0.3.1)" in p.stdout++def test_no_latest_falls_back_to_newest_prerelease_only(tmp_path):+ p, log = run(tmp_path, "404", [FAILED, HIST, {"tagName": "v0.0.1-pre", "isPrerelease": True}])+ assert "release view v0.1.0-pre" in log and "release view v0.3.2" not in log+ assert p.returncode == 1 and "newest prerelease (no Latest) release (v0.1.0-pre)" in p.stdout+[email protected]("latest", ["403", "500"])+def test_a_non_404_lookup_error_fails_instead_of_deploying(tmp_path, latest):+ p, log = run(tmp_path, latest, [FAILED, GOOD])+ assert p.returncode != 0 and "not a 404" in p.stdout and "release view" not in log++def test_no_latest_and_no_prerelease_deploys_nothing(tmp_path):+ p, log = run(tmp_path, "404", [FAILED])+ assert p.returncode == 1 and "nothing to deploy" in p.stdout and "release view" not in log+[email protected]("latest", ["", "null"])+def test_a_latest_response_without_a_tag_refuses(tmp_path, latest):+ p, log = run(tmp_path, latest, [FAILED, HIST])+ assert p.returncode != 0 and "release view" not in log and "release list" not in log++def test_a_fallback_lookup_failure_refuses(tmp_path):+ p, log = run(tmp_path, "404", [HIST], list_fail=True)+ assert p.returncode != 0 and "release view" not in log