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 release body: credit each commit's author and label the list as commit subjects (Fixes #2654) (#2723)

Beri8dc7b73fc85a
diff --git a/tools/nightly.py b/tools/nightly.py
index 31481462e..cfa36556d 100644
--- a/tools/nightly.py
+++ b/tools/nightly.py
@@ -702,10 +702,11 @@ def publish_night(night: Night, state: State, gh: GitHub, itch, zips: tuple[Path
if use_itch and itch is None: # before any store change: enabled means the push is part of this night
raise Refused("itch", "itch is enabled but there is no itch client")
since = prev_sha or prev_tag
- subjects = [ln for ln in _git(runner, night.cfg.clone, "log", "--format=%s", f"{since}..{night.sha}").splitlines()
- if ln]
+ # %aN is the author name after .mailmap, so a mailmap entry gives a contributor their credited name (#2654)
+ log = _git(runner, night.cfg.clone, "log", "--format=%s%x1f%aN", f"{since}..{night.sha}")
+ changes = [(s, a) for s, _, a in (ln.partition("\x1f") for ln in log.split("\n") if ln)]
notes = night.run_dir / "release-notes.md"
- notes.write_text(release_notes(version=night.version, sha=night.sha, since=since, subjects=subjects,
+ notes.write_text(release_notes(version=night.version, sha=night.sha, since=since, changes=changes,
sha256_lines=sha256_lines(list(zips))), encoding="utf-8")
gh.ensure_tag_available(night.tag) # again just before create: a release made since preflight is never ours
def created(release_id: int) -> None:
diff --git a/tools/nightly_publish.py b/tools/nightly_publish.py
index 0244014fa..48be6aaef 100644
--- a/tools/nightly_publish.py
+++ b/tools/nightly_publish.py
@@ -44,11 +44,20 @@ def sha256_lines(files: list[Path]) -> list[str]:
return [f"{sha256_of(f)} {Path(f).name}" for f in files]
-def release_notes(*, version: str, sha: str, since: str, subjects: list[str], sha256_lines: list[str]) -> str:
+def _plain_author(name: str) -> str:
+ """An author name is a GitHub profile name that nobody reviews. In a release body "@x" mentions and "[x](url)"
+ links, so a zero-width joiner breaks the mention, and the brackets and "<" (autolink, raw HTML) are escaped. A
+ backslash is escaped first so a name cannot pre-escape the escape (#2654)."""
+ return name.replace("\\", "\\\\").replace("@", "@\u200d").replace("[", "\\[").replace("]", "\\]").replace("<", "\\<")
+
+
+def release_notes(*, version: str, sha: str, since: str, changes: list[tuple[str, str]], sha256_lines: list[str]) -> str:
+ """`changes` is (commit subject, commit author) per commit. The heading says the lines are commit subjects, so an
+ agent-written subject such as "... is owner-approved" does not read as the owner's own words (#2654)."""
shown = since[:SHA_SHOWN] if len(since) == 40 and all(c in "0123456789abcdef" for c in since) else since
- lines = [f"Automated nightly build of `main` at {sha[:SHA_SHOWN]}.", "",
- f"Version {version}.", "", f"Changes since {shown}:", ""]
- lines += [f"- {s}" for s in subjects] or ["- (no commits)"]
+ lines = [f"Automated nightly build of `main` at {sha[:SHA_SHOWN]}.", "", f"Version {version}.", "",
+ f"Changes since {shown} (commit subjects with each commit's author; they are not quotes of anyone):", ""]
+ lines += [f"- {s} (by {_plain_author(a)})" for s, a in changes] or ["- (no commits)"]
lines += ["", "SHA-256:", "", "```", *sha256_lines, "```", ""]
return "\n".join(lines)
diff --git a/tools/tests/test_nightly.py b/tools/tests/test_nightly.py
index 9be2bed2f..749b96311 100644
--- a/tools/tests/test_nightly.py
+++ b/tools/tests/test_nightly.py
@@ -1151,7 +1151,7 @@ SIZES = {"data": 1000, "wasm": 90, "framework": 10}
def pub(night, env, tmp_path):
"""A night plus two zips, a git log answer and a fake demo check."""
clone = str(night.cfg.clone)
- env.runner.add(["git", "-C", clone, "log", "--format=%s"], out="Fix a thing\nAdd a thing\n")
+ env.runner.add(["git", "-C", clone, "log", "--format=%s%x1f%aN"], out="Fix a thing\x1fBeri\nAdd a thing\x1fmoshewe\n")
zips = (tmp_path / "web.zip", tmp_path / "pages.zip")
for z in zips:
z.write_bytes(b"zip")
@@ -1183,15 +1183,23 @@ def test_release_targets_the_preflight_commit(night, env, pub, served):
publish(night, st, gh, pub, env) # origin/main may move on after preflight: nothing may follow it
create = next(c for c in gh.calls if c[0] == "create_draft")
assert create[1:3] == (TAG, night.sha) and create[4] == list(pub)
- assert ["git", "-C", clone, "log", "--format=%s", f"{OLD}..{night.sha}"] in env.runner.calls
+ assert ["git", "-C", clone, "log", "--format=%s%x1f%aN", f"{OLD}..{night.sha}"] in env.runner.calls
assert not any("ls-remote" in c and "refs/heads/main" in c for c in env.runner.calls)
notes = (night.run_dir / "release-notes.md").read_text()
- assert "- Fix a thing" in notes and "- Add a thing" in notes and night.sha[:12] in notes
+ assert "- Fix a thing (by Beri)\n- Add a thing (by moshewe)" in notes and night.sha[:12] in notes
assert gh.names() == ["ensure_tag_available", "create_draft", "verify_draft", "latest_tag", "publish", "dispatch_site"]
assert gh.latest == TAG and "restore_latest" not in gh.names()
assert (night.run_dir / "latest-before-publish.txt").read_text() == "v0.3.1\n"
+def test_a_subject_with_a_unicode_line_break_stays_one_line_with_its_author(night, env, pub, served):
+ # str.splitlines() also breaks on U+0085 and U+2028, which would print the first half as "(by )" (#2654 review).
+ clone = str(night.cfg.clone)
+ env.runner.rules.insert(0, (("git", "-C", clone, "log", "--format=%s%x1f%aN"), 0, "Fix\x85a thing\x1fBeri\n", None))
+ publish(night, ns.State(last_published=last_published()), FakeGH(), pub, env)
+ assert "- Fix\x85a thing (by Beri)" in (night.run_dir / "release-notes.md").read_text()
+
+
def test_the_first_night_fetches_the_release_tag_before_resolving_it(night, env):
clone = str(night.cfg.clone)
env.runner.add(["git", "-C", clone, "fetch"])
@@ -1217,7 +1225,7 @@ def test_later_nights_use_the_published_commit_and_fetch_nothing(night, env):
def test_the_notes_log_runs_from_the_previous_commit_or_tag(night, env, pub, served):
clone = str(night.cfg.clone)
publish(night, ns.State(), FakeGH(), pub, env, previous=("v0.3.1", None))
- assert ["git", "-C", clone, "log", "--format=%s", f"v0.3.1..{night.sha}"] in env.runner.calls
+ assert ["git", "-C", clone, "log", "--format=%s%x1f%aN", f"v0.3.1..{night.sha}"] in env.runner.calls
def test_a_failed_draft_check_deletes_the_draft_and_refuses(night, env, pub, served):
@@ -1612,7 +1620,7 @@ def itch_night(night, env, tmp_path, served):
night.cfg = dataclasses.replace(night.cfg, itch_enabled=True, savetest_itch_target=TEST_TARGET,
itch_evidence=evidence_file(tmp_path, "PASS"))
clone = str(night.cfg.clone)
- env.runner.add(["git", "-C", clone, "log", "--format=%s"], out="Fix a thing\n")
+ env.runner.add(["git", "-C", clone, "log", "--format=%s%x1f%aN"], out="Fix a thing\x1fBeri\n")
zips = (zip_of(tmp_path / "web.zip", "tonight"), zip_of(tmp_path / "pages.zip", "pages"))
gh = FakeGH()
gh.baseline = zip_of(tmp_path / "previous-web.zip", "previous")
diff --git a/tools/tests/test_nightly_publish.py b/tools/tests/test_nightly_publish.py
index 3a646582c..84e5d7f04 100644
--- a/tools/tests/test_nightly_publish.py
+++ b/tools/tests/test_nightly_publish.py
@@ -530,20 +530,45 @@ def test_demo_serves_refuses_at_the_deadline_and_survives_fetch_errors():
# --- notes and unzip ------------------------------------------------------------------------------------------------------
def test_release_notes_list_commits_and_hashes_and_say_nightly():
- text = gp.release_notes(version=VERSION, sha=SHA, since="b" * 40, subjects=["Fix a thing", "Add a thing"],
+ text = gp.release_notes(version=VERSION, sha=SHA, since="b" * 40,
+ changes=[("Fix a thing", "Beri"), ("Add a thing", "Aviel Cohen")],
sha256_lines=["abc one.zip", "def two.zip"])
assert f"Automated nightly build of `main` at {SHA[:12]}." in text
assert "pre-release" not in text
- assert "- Fix a thing\n- Add a thing" in text and "abc one.zip\ndef two.zip" in text
+ assert "- Fix a thing (by Beri)\n- Add a thing (by Aviel Cohen)" in text and "abc one.zip\ndef two.zip" in text
assert VERSION in text and ("b" * 12) in text and ("b" * 40) not in text
assert "\u2014" not in text
def test_release_notes_with_no_commits_say_so():
- text = gp.release_notes(version=VERSION, sha=SHA, since="v0.3.1", subjects=[], sha256_lines=[])
+ text = gp.release_notes(version=VERSION, sha=SHA, since="v0.3.1", changes=[], sha256_lines=[])
assert "v0.3.1" in text and "no commits" in text.lower()
+def test_release_notes_label_the_list_as_commit_subjects_not_quotes():
+ # Agent-written subjects such as "... is owner-approved" must not read as the owner's own words (#2654).
+ text = gp.release_notes(version=VERSION, sha=SHA, since="v0.3.1",
+ changes=[("Content: housing_repair's Hebrew name is owner-approved (#2415)", "Beri")],
+ sha256_lines=[])
+ heading = "Changes since v0.3.1 (commit subjects with each commit's author; they are not quotes of anyone):"
+ assert f"{heading}\n\n- Content: housing_repair's Hebrew name is owner-approved (#2415) (by Beri)\n" in text
+
+
+def test_release_notes_neutralise_mentions_and_links_in_author_names():
+ # An author name is a GitHub profile name nobody reviews; in a public release body "@x" would mention and
+ # "[x](url)" would link (#2654 review, SHOULD 1).
+ text = gp.release_notes(version=VERSION, sha=SHA, since="v0.3.1",
+ changes=[("Fix a thing", "@someone"), ("Add a thing", "[x](https://example.com)")],
+ sha256_lines=[])
+ assert "(by @someone)" not in text and "@\u200dsomeone" in text
+ assert "[x](" not in text and "\\[x\\](https://example.com)" in text
+ tricky = gp.release_notes(version=VERSION, sha=SHA, since="v0.3.1", changes=[("Fix", "\\[x\\](https://example.com)")],
+ sha256_lines=[])
+ assert "(by \\\\\\[x\\\\\\](https://example.com))" in tricky # a name's own backslashes are escaped too
+ assert "(by \\<http://e.com>)" in gp.release_notes(version=VERSION, sha=SHA, since="v0.3.1",
+ changes=[("Fix", "<http://e.com>")], sha256_lines=[])
+
+
def test_unzip_extracts_into_the_folder(tmp_path):
z = make_zip(tmp_path / "a.zip")
out = gp.unzip_to(z, tmp_path / "out")