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.

tools: one-command check script (fixes #263) (#276)

Guy Shoham2f6ec7400943
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 4cc03204d..10a9b5d6e 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -8,7 +8,7 @@
## Evidence
-<!-- Paste the commands you ran and the end of their output. Not a description of the output. -->
+<!-- Paste the commands you ran and the end of their output. Not a description of the output. `scripts/check.sh` runs everything CI runs. -->
```
```
diff --git a/AGENTS.md b/AGENTS.md
index e251774bc..559378f22 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -55,6 +55,7 @@ Before writing or editing content, review:
- `dotnet test sim/Statecraft.sln` loads all of `content/` and must pass with 0 warnings.
- `uv run scripts/oss/check_repo.py` runs the repository policy checks that CI runs.
- If you change `sim/`, `content/` or `unity/`, add a line under `## [Unreleased]` in `CHANGELOG.md`.
+- `scripts/check.sh` runs every check CI runs in one command: the changelog rule, the policy checker tests, `check_repo.py`, the sim build and tests, and the tools tests. It stops at the first failure.
## Git
diff --git a/docs/dev-setup.md b/docs/dev-setup.md
index 4a7392563..ba3bf52a4 100644
--- a/docs/dev-setup.md
+++ b/docs/dev-setup.md
@@ -24,6 +24,8 @@ Unity, a Unity licence and macOS are only needed for `unity/`. The sim, the cont
| Data tool tests (one runs the sim's release gate, so they need the .NET SDK too) | `uv run --with pytest==9.1.1 --with rasterio==1.5.2 --with numpy==2.5.3 --with pyyaml==6.0.3 --with pillow==12.3.0 --with requests==2.32.5 --with pyproj==3.8.0 pytest tools/tests -q` | Tools (pytest) |
| Changelog line | `uv run scripts/oss/changelog_check.py --base origin/main` | Changelog |
+`scripts/check.sh` runs all five in one go, cheapest first, plus a sim build with warnings as errors. It stops at the first failure and shows the end of its output. It takes the base ref as its argument (default `origin/main`); set `CHECK_NO_CHANGELOG=1` if the PR has the `no-changelog` label.
+
Not possible without Unity and not in CI: the Unity EditMode tests, player builds, `tools/web_check.py` and the visual profiles below. If your change touches `unity/`, or `sim/` code that Unity compiles, say in the PR that you could not run them. The maintainer runs them (`CONTRIBUTING.md`, "Unity EditMode tests are not in CI").
## Builds and browser checks (M3)
diff --git a/scripts/check.sh b/scripts/check.sh
new file mode 100755
index 000000000..0c50209e6
--- /dev/null
+++ b/scripts/check.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+# One command for "does my change pass?": the same checks CI runs, in order, cheapest first. Needs dotnet and uv, not
+# Unity (Unity edit-mode tests are not run by CI either; CONTRIBUTING.md, "What CI runs").
+# Stops at the first failure, prints the last lines of that step's output and exits non-zero.
+#
+# Usage: scripts/check.sh [BASE_REF] BASE_REF defaults to $CHECK_BASE, then origin/main.
+# The changelog step compares BASE_REF...HEAD, so it sees committed changes only (as CI does). Set
+# CHECK_NO_CHANGELOG=1 if the pull request carries the no-changelog label. CHECK_TAIL sets the lines shown (default 40).
+set -uo pipefail
+cd "$(dirname "$0")/.."
+base="${1:-${CHECK_BASE:-origin/main}}"
+tail_lines="${CHECK_TAIL:-40}"
+export UV_PYTHON="${UV_PYTHON:-3.12}" # the Python CI uses (UV_PYTHON in .github/workflows/ci.yml)
+log="$(mktemp)"
+trap 'rm -f "$log"' EXIT
+
+for tool in dotnet uv; do
+ command -v "$tool" >/dev/null || { echo "missing: $tool (see docs/dev-setup.md)"; exit 2; }
+done
+git rev-parse --verify --quiet "$base^{commit}" >/dev/null || { echo "base ref not found: $base (try: git fetch origin)"; exit 2; }
+
+skip=false
+[ "${CHECK_NO_CHANGELOG:-}" = 1 ] && skip=true
+
+run() {
+ local name="$1"; shift
+ echo "== $name"
+ if ! "$@" >"$log" 2>&1; then
+ echo "FAILED: $name"
+ echo "-- last $tail_lines lines of: $*"
+ tail -n "$tail_lines" "$log"
+ exit 1
+ fi
+ tail -n 3 "$log"
+}
+
+run "changelog (against $base)" uv run scripts/oss/changelog_check.py --base "$base" --skip-label "$skip"
+run "policy checker tests" uv run --with pytest==9.1.1 --with pyyaml==6.0.3 --with requests==2.32.5 pytest scripts/oss/tests -q
+run "repo policy" uv run scripts/oss/check_repo.py
+run "sim build, warnings as errors" dotnet build sim/Statecraft.sln -c Release --nologo -warnaserror
+run "sim and content tests" dotnet test sim/Statecraft.sln -c Release --nologo
+run "data tool tests" uv run --with pytest==9.1.1 --with rasterio==1.5.2 --with numpy==2.5.3 --with pyyaml==6.0.3 --with pillow==12.3.0 --with requests==2.32.5 --with pyproj==3.8.0 pytest tools/tests -q
+
+echo
+echo "ALL CHECKS PASSED"
diff --git a/scripts/oss/tests/test_policies.py b/scripts/oss/tests/test_policies.py
index 980c1e2a6..6583a7c20 100644
--- a/scripts/oss/tests/test_policies.py
+++ b/scripts/oss/tests/test_policies.py
@@ -48,6 +48,20 @@ def test_contributing_names_every_ci_command_and_the_unity_gate():
assert cmd in text, cmd
+def test_check_script_runs_every_ci_command():
+ # scripts/check.sh (#263) promises to run what CI runs; a pin changed in ci.yml must change there too.
+ import yaml
+ ci = yaml.safe_load(read(".github/workflows/ci.yml"))
+ script = read("scripts/check.sh")
+ runs = [s["run"] for job in ci["jobs"].values() for s in job["steps"] if "run" in s]
+ assert len(runs) == 5, runs
+ for cmd in runs:
+ # The changelog job passes the PR's SHAs; the script passes its own base ref.
+ cmd = cmd.split(" --base ")[0]
+ assert cmd in script, cmd
+ assert f'UV_PYTHON:-{ci["env"]["UV_PYTHON"]}' in script
+
+
def test_changelog_has_unreleased_on_top():
text = read("CHANGELOG.md")
assert text.index("## [Unreleased]") == text.index("## [")