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.

chore(oss): GitHub settings for the owner to apply: protect-main and main-review rulesets, repo and Actions settings

eyalgolan56deab57302e
diff --git a/scripts/oss/apply_github_settings.sh b/scripts/oss/apply_github_settings.sh
new file mode 100755
index 000000000..e3f922df2
--- /dev/null
+++ b/scripts/oss/apply_github_settings.sh
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+# OWNER ONLY. Applies scripts/oss/github/* to the GitHub repository: repo settings (squash only, no auto-merge, secret
+# scanning, Discussions on), two rulesets (protect-main: force-push and deletion blocked, no bypass; main-review:
+# required review and checks, admin bypass; no classic branch protection), the Actions allow-list with SHA pinning,
+# private vulnerability reporting, Dependabot alerts, a read-only default workflow token, approval for outside
+# contributors' workflow runs, and the labels.
+# Agents never run this. It refuses without an interactive terminal and asks you to type the repository name.
+# Usage: bash scripts/oss/apply_github_settings.sh OWNER/REPO
+set -euo pipefail
+repo="${1:?usage: apply_github_settings.sh OWNER/REPO}"
+here="$(cd "$(dirname "$0")" && pwd)"
+
+if [ ! -t 0 ]; then
+ echo "refusing: this owner step needs an interactive terminal; nothing was applied"
+ exit 2
+fi
+read -r -p "Type the repository name ($repo) to apply the settings: " typed
+if [ "$typed" != "$repo" ]; then
+ echo "names differ; nothing was applied"
+ exit 2
+fi
+
+gh api -X PATCH "repos/$repo" --input "$here/github/repo-settings.json" >/dev/null
+echo "repo settings applied"
+# Two rulesets, looked up by name. protect-main (the live one, kept) blocks force-push and deletion with NO bypass:
+# nobody, the owner included, can rewrite public history (owner ruling 1). main-review adds review and required checks,
+# and only it carries the admin bypass (decision D12).
+put_ruleset() {
+ local name="$1" file="$2" id
+ id="$(gh api --paginate "repos/$repo/rulesets" --jq ".[] | select(.name==\"$name\") | .id")"
+ if [ -n "$id" ]; then
+ gh api -X PUT "repos/$repo/rulesets/$id" --input "$file" >/dev/null
+ echo "ruleset $name ($id) updated"
+ else
+ gh api -X POST "repos/$repo/rulesets" --input "$file" >/dev/null
+ echo "ruleset $name created"
+ fi
+}
+put_ruleset protect-main "$here/github/ruleset-protect-main.json"
+put_ruleset main-review "$here/github/ruleset-main-review.json"
+gh api -X PUT "repos/$repo/private-vulnerability-reporting" >/dev/null
+echo "private vulnerability reporting on"
+gh api -X PUT "repos/$repo/vulnerability-alerts" >/dev/null
+echo "Dependabot alerts on"
+gh api -X PUT "repos/$repo/actions/permissions/workflow" -f default_workflow_permissions=read \
+ -F can_approve_pull_request_reviews=false >/dev/null
+echo "default workflow token read-only"
+if gh api -X PUT "repos/$repo/actions/permissions/fork-pr-contributor-approval" \
+ -f approval_policy=all_external_contributors >/dev/null 2>&1; then
+ echo "outside contributors' workflow runs need approval"
+else
+ echo "WARN: set it by hand: Settings > Actions > General > 'Require approval for all external contributors'"
+fi
+gh api -X PUT "repos/$repo/actions/permissions" --input "$here/github/actions-permissions.json" >/dev/null
+# Runs after "selected" is on (GitHub refuses the list otherwise); if it fails, no workflow runs until a re-run succeeds.
+gh api -X PUT "repos/$repo/actions/permissions/selected-actions" --input "$here/github/actions-selected.json" >/dev/null ||
+ { echo "ERROR: the actions allow-list was not set, so every workflow is blocked; re-run this script"; exit 1; }
+echo "only allow-listed actions run, pinned to a full SHA"
+while IFS=$'\t' read -r name color desc; do
+ [ -n "$name" ] && gh label create "$name" --repo "$repo" --color "$color" --description "$desc" --force >/dev/null
+done < "$here/github/labels.tsv"
+echo "labels created"
+
+echo "--- verify ---"
+gh api "repos/$repo" --jq '{allow_auto_merge, allow_merge_commit, allow_rebase_merge, allow_squash_merge, delete_branch_on_merge, has_discussions, visibility}'
+for name in protect-main main-review; do
+ id="$(gh api --paginate "repos/$repo/rulesets" --jq ".[] | select(.name==\"$name\") | .id")"
+ gh api "repos/$repo/rulesets/$id" --jq '{name, enforcement, bypass: [.bypass_actors[] | .bypass_mode], rules: [.rules[].type], checks: [.rules[] | select(.type=="required_status_checks") | .parameters.required_status_checks[].context]}'
+done
+gh api "repos/$repo/actions/permissions" --jq '{allowed_actions, sha_pinning_required}'
+gh api "repos/$repo/branches/main/protection" >/dev/null 2>&1 && echo "WARN: classic branch protection exists too; remove it (rulesets only)" || echo "no classic branch protection (rulesets only)"
diff --git a/scripts/oss/github/actions-permissions.json b/scripts/oss/github/actions-permissions.json
new file mode 100644
index 000000000..fceb4a0c5
--- /dev/null
+++ b/scripts/oss/github/actions-permissions.json
@@ -0,0 +1 @@
+{"enabled": true, "allowed_actions": "selected", "sha_pinning_required": true}
diff --git a/scripts/oss/github/actions-selected.json b/scripts/oss/github/actions-selected.json
new file mode 100644
index 000000000..062fc07b6
--- /dev/null
+++ b/scripts/oss/github/actions-selected.json
@@ -0,0 +1 @@
+{"github_owned_allowed": false, "verified_allowed": false, "patterns_allowed": ["actions/*", "astral-sh/setup-uv@*"]}
diff --git a/scripts/oss/github/repo-settings.json b/scripts/oss/github/repo-settings.json
new file mode 100644
index 000000000..f584b67ea
--- /dev/null
+++ b/scripts/oss/github/repo-settings.json
@@ -0,0 +1,19 @@
+{
+ "has_issues": true,
+ "has_wiki": false,
+ "has_projects": false,
+ "has_discussions": true,
+ "allow_squash_merge": true,
+ "allow_merge_commit": false,
+ "allow_rebase_merge": false,
+ "allow_auto_merge": false,
+ "allow_update_branch": true,
+ "delete_branch_on_merge": true,
+ "squash_merge_commit_title": "PR_TITLE",
+ "squash_merge_commit_message": "PR_BODY",
+ "web_commit_signoff_required": false,
+ "security_and_analysis": {
+ "secret_scanning": { "status": "enabled" },
+ "secret_scanning_push_protection": { "status": "enabled" }
+ }
+}
diff --git a/scripts/oss/github/ruleset-main-review.json b/scripts/oss/github/ruleset-main-review.json
new file mode 100644
index 000000000..b1a118d3d
--- /dev/null
+++ b/scripts/oss/github/ruleset-main-review.json
@@ -0,0 +1,35 @@
+{
+ "name": "main-review",
+ "target": "branch",
+ "enforcement": "active",
+ "conditions": { "ref_name": { "include": ["~DEFAULT_BRANCH"], "exclude": [] } },
+ "bypass_actors": [
+ { "actor_id": 5, "actor_type": "RepositoryRole", "bypass_mode": "always" }
+ ],
+ "rules": [
+ {
+ "type": "pull_request",
+ "parameters": {
+ "required_approving_review_count": 1,
+ "dismiss_stale_reviews_on_push": true,
+ "require_code_owner_review": true,
+ "require_last_push_approval": true,
+ "required_review_thread_resolution": true,
+ "allowed_merge_methods": ["squash"]
+ }
+ },
+ {
+ "type": "required_status_checks",
+ "parameters": {
+ "strict_required_status_checks_policy": true,
+ "do_not_enforce_on_create": false,
+ "required_status_checks": [
+ { "context": "Sim (dotnet test)", "integration_id": 15368 },
+ { "context": "Tools (pytest)", "integration_id": 15368 },
+ { "context": "Repo policy", "integration_id": 15368 },
+ { "context": "Changelog", "integration_id": 15368 }
+ ]
+ }
+ }
+ ]
+}
diff --git a/scripts/oss/github/ruleset-protect-main.json b/scripts/oss/github/ruleset-protect-main.json
new file mode 100644
index 000000000..5155b8896
--- /dev/null
+++ b/scripts/oss/github/ruleset-protect-main.json
@@ -0,0 +1,11 @@
+{
+ "name": "protect-main",
+ "target": "branch",
+ "enforcement": "active",
+ "conditions": { "ref_name": { "include": ["~DEFAULT_BRANCH"], "exclude": [] } },
+ "bypass_actors": [],
+ "rules": [
+ { "type": "non_fast_forward" },
+ { "type": "deletion" }
+ ]
+}
diff --git a/scripts/oss/tests/test_merge_policy.py b/scripts/oss/tests/test_merge_policy.py
new file mode 100644
index 000000000..11fdb5cef
--- /dev/null
+++ b/scripts/oss/tests/test_merge_policy.py
@@ -0,0 +1,97 @@
+import json
+import os
+import subprocess
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[3]
+GH = ROOT / "scripts/oss/github"
+
+
+def load(name: str) -> dict:
+ return json.loads((GH / name).read_text())
+
+
+def rule(ruleset: dict, kind: str) -> dict | None:
+ return next((r for r in ruleset["rules"] if r["type"] == kind), None)
+
+
+def test_squash_only_no_auto_merge_branches_deleted_discussions_on():
+ s = load("repo-settings.json")
+ assert s["allow_squash_merge"] is True
+ assert s["allow_merge_commit"] is False and s["allow_rebase_merge"] is False
+ assert s["allow_auto_merge"] is False # no_human's live setting was true despite its docs
+ assert s["delete_branch_on_merge"] is True and s["has_discussions"] is True
+
+
+def test_history_ruleset_is_the_live_one_and_nobody_bypasses_it():
+ # Review N2: force-push and deletion stay blocked for everyone, the owner included (owner ruling 1).
+ r = load("ruleset-protect-main.json")
+ assert r["name"] == "protect-main" and r["enforcement"] == "active"
+ assert r["conditions"]["ref_name"]["include"] == ["~DEFAULT_BRANCH"]
+ assert {x["type"] for x in r["rules"]} == {"non_fast_forward", "deletion"}
+ assert r["bypass_actors"] == []
+
+
+def test_review_ruleset_requires_code_owner_review_squash_and_checks():
+ r = load("ruleset-main-review.json")
+ assert r["name"] == "main-review" and r["enforcement"] == "active"
+ assert r["conditions"]["ref_name"]["include"] == ["~DEFAULT_BRANCH"]
+ assert {x["type"] for x in r["rules"]} == {"pull_request", "required_status_checks"}
+ pr = rule(r, "pull_request")["parameters"]
+ assert pr["require_code_owner_review"] and pr["dismiss_stale_reviews_on_push"] and pr["require_last_push_approval"]
+ assert pr["required_approving_review_count"] == 1 and pr["required_review_thread_resolution"]
+ assert pr["allowed_merge_methods"] == ["squash"]
+ assert rule(r, "required_status_checks")["parameters"]["strict_required_status_checks_policy"] is True
+ # Each check must come from the GitHub Actions app (id 15368), so a status posted by anything else can't satisfy it.
+ assert {c["integration_id"] for c in rule(r, "required_status_checks")["parameters"]["required_status_checks"]} == {15368}
+
+
+def test_no_history_enforcement():
+ # Owner ruling 2026-10-11: no signed-commit or linear-history requirement.
+ for name in ("ruleset-protect-main.json", "ruleset-main-review.json"):
+ r = load(name)
+ assert rule(r, "required_signatures") is None and rule(r, "required_linear_history") is None
+
+
+def test_only_the_review_ruleset_has_the_admin_bypass():
+ # Decision D12: the maintainer keeps merging locally and pushing; everyone else goes through review and checks.
+ assert load("ruleset-main-review.json")["bypass_actors"] == [
+ {"actor_id": 5, "actor_type": "RepositoryRole", "bypass_mode": "always"}]
+
+
+def test_actions_are_pinned_and_allow_listed():
+ p = load("actions-permissions.json")
+ assert p["sha_pinning_required"] is True and p["allowed_actions"] == "selected" and p["enabled"] is True
+ s = load("actions-selected.json")
+ assert s["patterns_allowed"] == ["actions/*", "astral-sh/setup-uv@*"]
+ assert s["github_owned_allowed"] is False and s["verified_allowed"] is False
+ text = (ROOT / "scripts/oss/apply_github_settings.sh").read_text()
+ assert 'actions/permissions" --input' in text and "actions/permissions/selected-actions" in text
+
+
+def test_apply_script_looks_rulesets_up_by_name():
+ text = (ROOT / "scripts/oss/apply_github_settings.sh").read_text()
+ assert "put_ruleset protect-main" in text and "put_ruleset main-review" in text
+ assert "24834491" not in text
+
+
+def test_no_classic_branch_protection_file():
+ assert not (GH / "branch-protection.json").exists()
+ assert "branches/main/protection\" --input" not in (ROOT / "scripts/oss/apply_github_settings.sh").read_text()
+
+
+def test_labels_include_the_ones_ci_forms_and_readme_use():
+ names = {l.split("\t")[0] for l in (GH / "labels.tsv").read_text().splitlines() if l}
+ assert {"no-changelog", "historical-accuracy", "bug", "enhancement", "spam", "good first issue"} <= names
+
+
+def test_apply_script_refuses_without_a_terminal_and_calls_nothing(tmp_path):
+ marker = tmp_path / "gh-called"
+ fake = tmp_path / "gh"
+ fake.write_text(f"#!/bin/sh\ntouch {marker}\n")
+ fake.chmod(0o755)
+ env = dict(os.environ, PATH=f"{tmp_path}:{os.environ['PATH']}")
+ r = subprocess.run(["bash", str(ROOT / "scripts/oss/apply_github_settings.sh"), "eyalgolan/statecraft-israel"],
+ stdin=subprocess.DEVNULL, capture_output=True, text=True, env=env)
+ assert r.returncode == 2 and "interactive terminal" in r.stdout
+ assert not marker.exists()