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.

Nightly: a manual-only --version override for the release version (#2983)

Eyal Golancb09a8d63e2d
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index 1972f6dfc..df16260d2 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -206,7 +206,8 @@ Every night at 03:00 (Israel time) the newest `main` is built and, only if every
game: a normal GitHub release marked **Latest**, tagged `vX.Y.Z`, which GitHub Pages' `/demo/` serves, and, once itch
pushes are enabled, the itch.io page. X.Y.Z is one patch above the numerically highest published release tag matching
`^v[0-9]+\.[0-9]+\.[0-9]+$`; drafts, `-nightly` tags and other names do not choose the version. With v0.3.1 and
-v0.3.1-nightly.20261028 published, the next nightly is v0.3.2. The job is
+v0.3.1-nightly.20261028 published, the next nightly is v0.3.2. A by-hand run can choose a higher version instead
+(`--manual --version X.Y.Z`, `tools/README.md`, "Nightly release"); the 03:00 night never does. The job is
`tools/nightly.py` under launchd; the install steps are in `tools/README.md`, "Nightly release". Nothing here changes
the owner-run release steps above (steps 1-7). Published nightlies are never deleted.
diff --git a/tools/README.md b/tools/README.md
index 0d922e009..cda8229b8 100644
--- a/tools/README.md
+++ b/tools/README.md
@@ -273,6 +273,13 @@ run it again. Then:
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.statecraft.nightly.plist
```
+A by-hand night can choose its version instead of the next patch, for a minor bump such as
+`uv run tools/nightly.py run --manual --version 0.4.0` from the clone. `--version` is refused without `--manual`, when
+it is not plain X.Y.Z, and when it is not above every published vX.Y.Z; the launchd job never passes it, so the next
+scheduled night is one patch above whatever was published last (v0.4.1 after v0.4.0). It is also refused while the
+job's own draft of another version from an earlier night is open (`open_draft` in `state.json`): delete that draft
+release by hand, then set `open_draft` and `open_draft_id` to `null` in `state.json`.
+
A change to `nightly_launch.py` or `nightly_state.py` needs the `cp` again; a change to `nightly.py` does not.
Uninstall: `launchctl bootout gui/$(id -u)/com.statecraft.nightly`, then delete the plist. To remove the clone too,
diff --git a/tools/nightly.py b/tools/nightly.py
index 5d911e6cb..9cb5f7992 100644
--- a/tools/nightly.py
+++ b/tools/nightly.py
@@ -33,8 +33,9 @@ import unity_postmerge
from nightly_publish import (GitHub, Itch, demo_serves, itch_build_frame_url, release_notes, sha256_lines, sha256_of,
unzip_to)
from nightly_state import (JOB, TZ, Config, LatestRecovery, Missed, Published, Refused, Runner, Skipped, State, Stop,
- enable_itch, late_start, load_config, load_state, log_line, missed_days, night_of,
- notify, record, run_lock, save_state, savetest_lock, tag_for, write_refusal_log)
+ check_version_form, enable_itch, late_start, load_config, load_state, log_line,
+ missed_days, night_of, notify, record, run_lock, save_state, savetest_lock, tag_for,
+ write_refusal_log)
from web_check import find_chrome
HOLDER_ENV = unity_postmerge.machine_lock.HOLDER_ENV
@@ -169,7 +170,9 @@ BASELINE_NIGHTS = 5
def preflight(cfg: Config, state: State, runner: Runner, gh: GitHub, *, job: Path, now: datetime, manual: bool,
- free_gb: Callable[[Path], float], no_publish: bool = False) -> Night:
+ free_gb: Callable[[Path], float], no_publish: bool = False, version: str | None = None) -> Night:
+ if version is not None and not manual: # main refuses this too; the 03:00 job never passes a version
+ raise Refused("version", "a version given by hand needs a --manual run")
day = night_of(now)
if late_start(now, cfg.window_end) and not manual:
raise Missed(f"started after {cfg.window_end}")
@@ -206,7 +209,14 @@ def preflight(cfg: Config, state: State, runner: Runner, gh: GitHub, *, job: Pat
raise Refused("unity-editor", f"{editor} is missing")
if not cfg.unity_slots.is_file():
raise Refused("unity-slots", f"{cfg.unity_slots} is missing")
- version = gh.next_version()
+ if version is None:
+ version = gh.next_version()
+ else: # checked against the same release list: above every published vX.Y.Z
+ version = gh.next_version(version)
+ if state.open_draft is not None and state.open_draft != tag_for(version):
+ raise Refused("version", f"the job's own draft {state.open_draft} from an earlier night is still open; "
+ f"remove it first, before choosing {version} (tools/README.md, "
+ f"\"Nightly release\")")
tag = tag_for(version)
if gh.release_state(tag) == "draft" and state.open_draft == tag:
if not no_publish: # --no-publish makes no store write, not even this cleanup
@@ -1015,7 +1025,7 @@ def _try_save(state_path: Path, state: State) -> bool:
def run_night(cfg: Config, state_path: Path, job: Path, runner: Runner, gh: GitHub | None, itch, *, now: datetime,
manual: bool, no_publish: bool, client_error: Refused | None = None,
free_gb: Callable[[Path], float] = lambda p: shutil.disk_usage(p).free / 1e9,
- no_steam: bool = False) -> str:
+ no_steam: bool = False, version: str | None = None) -> str:
outcome, gate, detail = "REFUSED", "internal", ""
state: State | None = None
night: Night | None = None
@@ -1042,7 +1052,7 @@ def run_night(cfg: Config, state_path: Path, job: Path, runner: Runner, gh: GitH
if not recovered:
raise Refused("github-latest", recovery_note)
night = preflight(cfg, state, runner, gh, job=job, now=now, manual=manual, free_gb=free_gb,
- no_publish=no_publish)
+ no_publish=no_publish, version=version)
published = run_stages(night, state, runner, gh, itch, no_publish=no_publish, free_gb=free_gb,
save=lambda: _try_save(state_path, state), no_steam=no_steam)
outcome, gate = ("PUBLISHED" if published else "NO-PUBLISH"), "-"
@@ -1364,9 +1374,19 @@ def main(argv: list[str] | None = None) -> int:
run.add_argument("--manual", action="store_true")
run.add_argument("--no-publish", action="store_true")
run.add_argument("--no-steam", action="store_true", help="skip the Steam stage after the web publish")
+ run.add_argument("--version", dest="release_version", metavar="X.Y.Z",
+ help="with --manual only: tonight's version instead of the next patch; it must be above "
+ "every published vX.Y.Z")
test = sub.add_parser("savetest", help="the two-upload itch.io save test: pushes twice to the separate test page, never the public one")
test.add_argument("--tag", required=True, help="a published nightly release tag")
args = parser.parse_args(argv)
+ if getattr(args, "release_version", None) is not None: # refused before any work, lock or record
+ if not args.manual:
+ parser.error("--version needs --manual (the 03:00 job always takes the next patch)")
+ try:
+ check_version_form(args.release_version)
+ except Refused as e:
+ parser.error(f"--version: {e.detail}")
job = JOB
now = datetime.now(TZ)
try:
@@ -1406,7 +1426,7 @@ def main(argv: list[str] | None = None) -> int:
client_error = e
outcome = run_night(cfg, job / "state.json", job, ProcRunner(), gh, itch, now=now,
manual=args.manual, no_publish=args.no_publish, client_error=client_error,
- no_steam=args.no_steam)
+ no_steam=args.no_steam, version=args.release_version)
operation_finished = True
except Refused as e:
if operation_finished:
diff --git a/tools/nightly_publish.py b/tools/nightly_publish.py
index 48be6aaef..146de663e 100644
--- a/tools/nightly_publish.py
+++ b/tools/nightly_publish.py
@@ -244,13 +244,14 @@ class GitHub:
# --- release state ---------------------------------------------------------------------------------------------
- def next_version(self) -> str:
- """Read every release page through gh; drafts and non-version tags cannot choose the version."""
+ def next_version(self, override: str | None = None) -> str:
+ """Read every release page through gh; drafts and non-version tags cannot choose the version. `override` is
+ checked against the same pages (see nightly_state.next_version)."""
pages = self._json("version", ["gh", "api", f"repos/{self.slug}/releases?per_page=100",
"--paginate", "--slurp"], list)
if not all(isinstance(page, list) for page in pages):
raise Refused("version", "gh returned release pages of the wrong shape")
- return next_version([row for page in pages for row in page])
+ return next_version([row for page in pages for row in page], override)
def ensure_tag_available(self, tag: str) -> None:
"""Refuse every remaining release or local/remote tag after owned-draft cleanup."""
diff --git a/tools/nightly_state.py b/tools/nightly_state.py
index 43a657e5d..99c017dab 100644
--- a/tools/nightly_state.py
+++ b/tools/nightly_state.py
@@ -279,8 +279,19 @@ def save_state(path: Path, state: State) -> None:
# --- naming and dates -------------------------------------------------------------------------------------------
-def next_version(releases: list[dict]) -> str:
- """One patch above the numerically highest published exact vX.Y.Z tag, regardless of release type."""
+VERSION_FORM = re.compile(r"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)")
+
+
+def check_version_form(version: str) -> None:
+ """A version given by hand is plain X.Y.Z without leading zeros, so its tag can never be a second spelling of a
+ published one (v0.04.0 beside v0.4.0)."""
+ if not isinstance(version, str) or not VERSION_FORM.fullmatch(version):
+ raise Refused("version", f"{version!r} is not a version of the form X.Y.Z (for example 0.4.0)")
+
+
+def next_version(releases: list[dict], override: str | None = None) -> str:
+ """One patch above the numerically highest published exact vX.Y.Z tag, regardless of release type. `override`
+ (nightly.py run --manual --version) replaces that choice, and only when it is above every published version."""
versions = []
for row in releases:
if (not isinstance(row, dict) or not isinstance(row.get("tag_name"), str)
@@ -289,10 +300,16 @@ def next_version(releases: list[dict]) -> str:
match = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.([0-9]+)", row["tag_name"])
if match and not row["draft"]:
versions.append(tuple(int(part) for part in match.groups()))
+ if override is not None:
+ check_version_form(override)
if not versions:
raise Refused("version", "no published vX.Y.Z release to increment")
major, minor, patch = max(versions)
- return f"{major}.{minor}.{patch + 1}"
+ if override is None:
+ return f"{major}.{minor}.{patch + 1}"
+ if tuple(int(part) for part in override.split(".")) <= (major, minor, patch):
+ raise Refused("version", f"{override} is not above the highest published release v{major}.{minor}.{patch}")
+ return override
def tag_for(version: str) -> str:
diff --git a/tools/tests/test_nightly.py b/tools/tests/test_nightly.py
index fc3c5ac4b..d5fb7775a 100644
--- a/tools/tests/test_nightly.py
+++ b/tools/tests/test_nightly.py
@@ -71,9 +71,12 @@ class FakeGH:
row = self.at_tag(tag)
return row[2] if row else None
- def next_version(self):
- self.calls.append(("next_version",))
- return "0.3.2"
+ def next_version(self, override=None):
+ if override is None:
+ self.calls.append(("next_version",))
+ return "0.3.2"
+ self.calls.append(("next_version", override))
+ return ns.next_version([{"tag_name": "v0.3.1", "draft": False}], override=override)
def ensure_tag_available(self, tag):
self.calls.append(("ensure_tag_available", tag))
@@ -185,15 +188,15 @@ class Env:
setattr(self, k, v)
self._rules()
- def pre(self, state=None, gh=None, *, now=NOW, manual=False, free=100.0, no_publish=False):
+ def pre(self, state=None, gh=None, *, now=NOW, manual=False, free=100.0, no_publish=False, **kw):
return nightly.preflight(self.cfg, state or ns.State(), self.runner, gh or FakeGH(), job=self.job, now=now,
- manual=manual, free_gb=lambda p: free, no_publish=no_publish)
+ manual=manual, free_gb=lambda p: free, no_publish=no_publish, **kw)
- def night(self, state=None, gh=None, *, now=NOW, manual=False, free=100.0, no_publish=False):
+ def night(self, state=None, gh=None, *, now=NOW, manual=False, free=100.0, no_publish=False, **kw):
if state is not None:
ns.save_state(self.state_path, state)
return nightly.run_night(self.cfg, self.state_path, self.job, self.runner, gh or FakeGH(), None, now=now,
- manual=manual, no_publish=no_publish, free_gb=lambda p: free)
+ manual=manual, no_publish=no_publish, free_gb=lambda p: free, **kw)
def log(self):
p = self.job / "LOG.md"
@@ -289,6 +292,45 @@ def test_changed_sha_builds_even_when_the_saved_tag_matches(env):
assert gh.calls == [("next_version",), ("release_state", TAG), ("ensure_tag_available", TAG)]
+def test_a_manual_version_replaces_the_next_patch_and_flows_into_the_tag(env):
+ gh = FakeGH()
+ n = env.pre(ns.State(), gh, manual=True, version="0.4.0")
+ assert (n.version, n.tag) == ("0.4.0", "v0.4.0")
+ assert gh.calls == [("next_version", "0.4.0"), ("release_state", "v0.4.0"), ("ensure_tag_available", "v0.4.0")]
+
+
+def test_without_a_manual_version_the_night_takes_the_next_patch(env):
+ gh = FakeGH()
+ n = env.pre(ns.State(), gh, manual=True)
+ assert (n.version, n.tag) == ("0.3.2", TAG)
+ assert gh.calls == [("next_version",), ("release_state", TAG), ("ensure_tag_available", TAG)]
+
+
+def test_a_manual_version_needs_a_manual_run(env):
+ gh = FakeGH()
+ with pytest.raises(ns.Refused) as e:
+ env.pre(ns.State(), gh, version="0.4.0")
+ assert e.value.gate == "version" and gh.calls == []
+
+
+def test_a_manual_version_at_or_below_the_latest_is_a_refused_night(env):
+ gh = FakeGH()
+ assert env.night(ns.State(), gh, manual=True, version="0.3.1") == "REFUSED"
+ assert gh.calls == [("next_version", "0.3.1")]
+ assert "REFUSED" in env.log() and "version" in env.log()
+
+
+def test_a_manual_version_refuses_while_an_own_draft_of_another_tag_is_open(env):
+ gh = FakeGH()
+ st = ns.State(open_draft=TAG)
+ st.open_draft_id = 101
+ with pytest.raises(ns.Refused) as e:
+ env.pre(st, gh, manual=True, version="0.4.0")
+ assert e.value.gate == "version" and TAG in e.value.detail and "Nightly release" in e.value.detail
+ assert "without --version" not in e.value.detail # a run without it would publish the next patch
+ assert "delete_draft" not in [c[0] for c in gh.calls] and st.open_draft == TAG
+
+
def test_a_late_start_is_missed_and_earlier_gaps_are_reported(env):
late = datetime(2026, 10, 28, 9, 10, tzinfo=ns.TZ)
assert env.night(ns.State(last_run_day="2026-10-25"), now=late) == "MISSED"
@@ -3388,6 +3430,27 @@ def test_the_steam_stage_is_skipped_while_ids_are_null(night, env, stages, monke
assert steam_calls(env) == []
+def test_version_reaches_the_night_only_with_manual(env, monkeypatch, capsys):
+ seen = {}
+ loaded = []
+ monkeypatch.setattr(nightly, "load_config", lambda path: loaded.append(path) or env.cfg)
+ monkeypatch.setattr(nightly, "_clients", lambda cfg: (FakeGH(), None))
+ monkeypatch.setattr(nightly, "JOB", env.job)
+ monkeypatch.setattr(nightly, "run_night", lambda *a, **k: seen.update(k) or "PUBLISHED")
+ assert nightly.main(["run", "--manual", "--version", "0.4.0"]) == 0 and seen["version"] == "0.4.0"
+ assert nightly.main(["run"]) == 0 and seen["version"] is None # the launchd command line
+ seen.clear()
+ loaded.clear()
+ for argv in (["run", "--version", "0.4.0"], ["run", "--manual", "--version", "v0.4.0"],
+ ["run", "--manual", "--version", "0.4"]):
+ with pytest.raises(SystemExit) as e:
+ nightly.main(argv)
+ assert e.value.code == 2
+ assert seen == {} and loaded == [] and not (env.job / "LOG.md").exists() # refused before any work or record
+ err = capsys.readouterr().err
+ assert "--version needs --manual" in err and "X.Y.Z" in err
+
+
def test_no_steam_reaches_the_stage_from_the_command_line(env, monkeypatch):
seen = {}
monkeypatch.setattr(nightly, "load_config", lambda path: env.cfg)
diff --git a/tools/tests/test_nightly_publish.py b/tools/tests/test_nightly_publish.py
index 84e5d7f04..85c43f21e 100644
--- a/tools/tests/test_nightly_publish.py
+++ b/tools/tests/test_nightly_publish.py
@@ -124,6 +124,16 @@ def test_next_version_reads_all_release_pages_through_the_runner(gh, runner):
assert runner.calls == [cmd]
+def test_a_manual_version_is_checked_against_the_same_release_pages(gh, runner):
+ cmd = ["gh", "api", f"repos/{SLUG}/releases?per_page=100", "--paginate", "--slurp"]
+ runner.on(cmd, json.dumps([[{"tag_name": "v0.3.9", "draft": False}], [{"tag_name": "v0.3.1", "draft": False}]]))
+ assert gh.next_version("0.4.0") == "0.4.0"
+ with pytest.raises(Refused) as e:
+ gh.next_version("0.3.9")
+ assert e.value.gate == "version"
+ assert runner.calls == [cmd, cmd]
+
+
@pytest.mark.parametrize("answer", ["not json", "{}", "[{}]", "[[{}]]", "[]"])
def test_next_version_refuses_unknown_release_data(gh, runner, answer):
runner.on(["gh", "api"], answer)
diff --git a/tools/tests/test_nightly_state.py b/tools/tests/test_nightly_state.py
index 915e7de05..6df3fc43e 100644
--- a/tools/tests/test_nightly_state.py
+++ b/tools/tests/test_nightly_state.py
@@ -31,6 +31,42 @@ def test_next_version_compares_only_exact_release_tags_numerically(tags, expecte
assert ns.next_version(rows) == expected
[email protected]("tags,version", [
+ (["v0.3.9", "v0.3.1"], "0.4.0"),
+ (["v0.3.9"], "0.3.10"),
+ (["v0.3.9"], "1.0.0"),
+ (["v0.03.9"], "0.4.0"),
+])
+def test_a_manual_version_above_every_published_tag_is_accepted(tags, version):
+ rows = [{"tag_name": tag, "draft": False} for tag in tags]
+ rows.append({"tag_name": "v99.99.99", "draft": True}) # a draft never blocks a version
+ assert ns.next_version(rows, override=version) == version
+
+
[email protected]("version", ["0.3.9", "0.3.8", "0.2.99", "0.3.0", "0.0.0"])
+def test_a_manual_version_at_or_below_the_highest_published_tag_is_refused(version):
+ rows = [{"tag_name": "v0.3.9", "draft": False}, {"tag_name": "v0.3.1", "draft": False}]
+ with pytest.raises(ns.Refused) as e:
+ ns.next_version(rows, override=version)
+ assert e.value.gate == "version" and "v0.3.9" in e.value.detail
+
+
[email protected]("version", ["v0.4.0", "0.4", "0.4.0.1", "0.4.0-rc1", "0.4.0\n", " 0.4.0", "", "a.b.c",
+ "0.04.0", "00.4.0"])
+def test_a_manual_version_in_the_wrong_form_is_refused(version):
+ with pytest.raises(ns.Refused) as e:
+ ns.check_version_form(version)
+ assert e.value.gate == "version"
+ with pytest.raises(ns.Refused):
+ ns.next_version([{"tag_name": "v0.3.9", "draft": False}], override=version)
+
+
+def test_a_manual_version_still_needs_a_published_tag_to_compare_with():
+ with pytest.raises(ns.Refused) as e:
+ ns.next_version([{"tag_name": "v0.3.9", "draft": True}], override="0.4.0")
+ assert e.value.gate == "version"
+
+
@pytest.mark.parametrize("rows", [[], [{"tag_name": "v0.3.1-nightly.20261028", "draft": False}],
[{"tag_name": "v0.3.1", "draft": True}]])
def test_next_version_refuses_without_a_published_exact_tag(rows):