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: squash-merge pull requests once the maintainer approves their latest commit and checks pass

eyalgoland4d6d8d4c9ac
diff --git a/.github/workflows/merge-approved.yml b/.github/workflows/merge-approved.yml
new file mode 100644
index 000000000..8ec5837ac
--- /dev/null
+++ b/.github/workflows/merge-approved.yml
@@ -0,0 +1,61 @@
+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
+# bodies, so no pull-request text reaches the shell.
+#
+# A pull request merges only when all of these hold on its current head commit:
+# - it targets main, is not a draft, and GitHub reports it MERGEABLE (no conflicts);
+# - the maintainer's most recent review is APPROVED and was made on that exact commit (a later push needs a new
+# approval);
+# - the four CI checks below exist on that commit and each concluded SUCCESS (a first-time contributor's run that is
+# still waiting for approval has no results, so it waits).
+# GitHub does not start other workflows from a merge made with this token, so CI on main is not re-run by it.
+
+on:
+ schedule:
+ - cron: "*/10 * * * *"
+ workflow_dispatch:
+
+permissions:
+ contents: write
+ pull-requests: write
+
+concurrency:
+ group: merge-approved
+ cancel-in-progress: false
+
+jobs:
+ merge:
+ name: Merge approved pull requests
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ env:
+ GH_TOKEN: ${{ github.token }}
+ GH_REPO: ${{ github.repository }}
+ MAINTAINER: eyalgolan
+ REQUIRED_CHECKS: "Sim (dotnet test)|Tools (pytest)|Repo policy|Changelog"
+ steps:
+ - name: Merge every pull request that is approved and green
+ run: |
+ set -euo pipefail
+ gh pr list --state open --base main --limit 100 --json number --jq '.[].number' | while read -r n; do
+ ready=$(gh pr view "$n" --json isDraft,mergeable,headRefOid,reviews,statusCheckRollup --jq '
+ . as $p
+ | ([$p.reviews[] | select(.author.login == env.MAINTAINER)] | last) as $r
+ | (env.REQUIRED_CHECKS | split("|")) as $need
+ | ($p.isDraft | not)
+ and $p.mergeable == "MERGEABLE"
+ and $r != null and $r.state == "APPROVED" and $r.commit.oid == $p.headRefOid
+ and ($need | all(. as $x | [$p.statusCheckRollup[] | select(.name == $x)]
+ | length > 0 and all(.conclusion == "SUCCESS")))
+ | if . then $p.headRefOid else "no" end')
+ if [ "$ready" = "no" ]; then
+ echo "#$n: not ready"
+ else
+ echo "#$n: approved and green at $ready, merging"
+ gh pr merge "$n" --squash --match-head-commit "$ready"
+ fi
+ done
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 111f11d01..cca677681 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -82,7 +82,7 @@ AI-assisted work is welcome. Say so in the pull request: which parts, and how yo
- Base your branch on `main`. History on `main` is protected, so no force-pushes.
- In the description, say what changed and why. Paste the test commands you ran and their output; a description of the output doesn't count.
-- The maintainer reviews every PR (`.github/CODEOWNERS`).
+- The maintainer reviews every PR (`.github/CODEOWNERS`). Once the maintainer approves your latest commit and every check on it has passed, `.github/workflows/merge-approved.yml` squash-merges it within about ten minutes. A new push needs a new approval.
## What CI runs
diff --git a/scripts/oss/tests/test_github_config.py b/scripts/oss/tests/test_github_config.py
index e92bd2b02..b4803cec8 100644
--- a/scripts/oss/tests/test_github_config.py
+++ b/scripts/oss/tests/test_github_config.py
@@ -118,3 +118,25 @@ def test_setup_uv_caches_on_the_files_that_carry_the_dependencies():
for s in uv_steps:
globs = s["with"]["cache-dependency-glob"].split()
assert globs == ["tools/**/*.py", "scripts/oss/**/*.py"], globs
+
+
+MERGE = ROOT / ".github/workflows/merge-approved.yml"
+
+
+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 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
+ for field in ("title", "body", "headRefName"):
+ assert field not in script, field
+ assert "--match-head-commit" in script and "$r.commit.oid == $p.headRefOid" in script
+
+
+def test_merge_workflow_waits_for_every_required_check():
+ wf = yaml.safe_load(MERGE.read_text(encoding="utf-8"))
+ need = set(wf["jobs"]["merge"]["env"]["REQUIRED_CHECKS"].split("|"))
+ assert need == EXPECTED_JOBS