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.

ci: merge approved pull requests when CI finishes or a review lands, not only on the timer (#173)

Eyal Golan88d1ffaa69ad
diff --git a/.github/workflows/merge-approved.yml b/.github/workflows/merge-approved.yml
index 8ec5837ac..674480d7f 100644
--- a/.github/workflows/merge-approved.yml
+++ b/.github/workflows/merge-approved.yml
@@ -2,8 +2,11 @@ name: Merge approved
# Squash-merges an open pull request into main once the maintainer has approved its latest commit and every check
# on that commit has passed (owner ruling, 2026-10-11). Outside contributors get no write access; this job merges for
-# them. It runs on a timer from main's copy of this file and never checks out, builds or runs pull-request code, so
-# the write token never meets outside code. It reads only numbers, SHAs and states from the API, never titles or
+# them. It runs from main's copy of this file and never checks out, builds or runs pull-request code, so the write
+# token never meets outside code. It starts when CI finishes (workflow_run runs in this repository's context with a
+# write token, also for forks), when a review is submitted (for a fork's pull request GitHub gives that run a read-only
+# token, so its merge is refused and the next CI or timer run merges), on a timer as a fallback (GitHub runs
+# schedules late or not at all under load), and by hand. It reads only numbers, SHAs and states from the API, never titles or
# bodies, so no pull-request text reaches the shell.
#
# A pull request merges only when all of these hold on its current head commit:
@@ -15,6 +18,11 @@ name: Merge approved
# GitHub does not start other workflows from a merge made with this token, so CI on main is not re-run by it.
on:
+ workflow_run:
+ workflows: [CI]
+ types: [completed]
+ pull_request_review:
+ types: [submitted]
schedule:
- cron: "*/10 * * * *"
workflow_dispatch:
@@ -56,6 +64,6 @@ jobs:
echo "#$n: not ready"
else
echo "#$n: approved and green at $ready, merging"
- gh pr merge "$n" --squash --match-head-commit "$ready"
+ gh pr merge "$n" --squash --match-head-commit "$ready" || echo "#$n: merge refused (read-only token or head moved); a later run retries"
fi
done
diff --git a/scripts/oss/tests/test_github_config.py b/scripts/oss/tests/test_github_config.py
index b4803cec8..0f8e6966c 100644
--- a/scripts/oss/tests/test_github_config.py
+++ b/scripts/oss/tests/test_github_config.py
@@ -127,7 +127,9 @@ def test_merge_workflow_never_touches_pull_request_code():
# Owner ruling 2026-10-11: approved pull requests merge without giving contributors write access. The job holds a
# write token, so it must never check out, build or run pull-request code, and never read PR text into the shell.
wf = yaml.safe_load(MERGE.read_text(encoding="utf-8"))
- assert set(triggers(wf)) == {"schedule", "workflow_dispatch"}
+ assert set(triggers(wf)) == {"workflow_run", "pull_request_review", "schedule", "workflow_dispatch"}
+ assert triggers(wf)["workflow_run"]["workflows"] == ["CI"]
+ assert "pull_request_target" not in triggers(wf)
assert wf["permissions"] == {"contents": "write", "pull-requests": "write"}
script = "\n".join(s.get("run", "") for s in steps(wf))
assert not any("uses" in s for s in steps(wf)) and "checkout" not in script