Nightly: nothing an unreviewed build leaves reaches a release

Orchestrator's review of #2859: a nightly can hold pull requests nobody
reviewed yet, and their build scripts run in `build`. game-build.yml gets a
`trusted` input, true only from release.yml:

- the Rust cache (GitHub-hosted Linux and Windows): its own key for an
  untrusted build (`nightly-<name>`), never saved; a release restores only
  what a release saved;
- macOS: an untrusted build's exporters and build jobs run on the runner
  that already runs pull requests' parity jobs (macOS + horizon-game), never
  the release runner (MAC_RUNNER) nor parity-main's;
- a trusted build doesn't read the machine's shared sccache, which pull
  requests' jobs write (runner-env.sh: HORIZON_NO_SCCACHE).

tests/test_nightly.py pins all three.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-27 16:26:51 +01:00
parent 7efd8ef33a
commit 8d5424408c
6 changed files with 69 additions and 7 deletions
+21 -4
View File
@@ -19,6 +19,15 @@ on:
description: A nightly's "<date> <short sha>" (HORIZON_NIGHTLY), shown by the game; empty for a release
type: string
default: ''
trusted:
# Only release.yml says true: it builds main. A nightly can hold pull requests nobody reviewed yet, whose
# build scripts and tests run here and could rewrite target/, the cargo home or a compiler cache. So an
# untrusted build never runs on the release runner, never saves the Rust cache (its key is its own anyway),
# and a trusted one never reads the machine's shared sccache, which pull requests' jobs write
# (tests/test_nightly.py pins all of it).
description: The source is main (a release); false for anything else (a nightly)
type: boolean
default: false
developer_id:
description: Sign the macOS programs with Developer ID and notarize the zip (the runner's keychain)
type: boolean
@@ -27,8 +36,10 @@ permissions:
contents: read
jobs:
exporters:
# This runner holds the maintainer's own pinned Minecraft jars. Only our classes leave it.
runs-on: ${{ vars.MAC_RUNNER || 'ludovics-mac-mini' }}
# This runner holds the maintainer's own pinned Minecraft jars. Only our classes leave it. An untrusted build
# goes to the Mac mini runner that already runs pull requests' parity jobs (macOS + horizon-game:
# ludovics-mac-mini), never the release runner (MAC_RUNNER: ludovics-mac-mini-release) nor parity-main's.
runs-on: ${{ inputs.trusted && vars.MAC_RUNNER || fromJSON('["self-hosted", "macOS", "horizon-game"]') }}
# Three full preparations (two isolated, one batched) besides the compile.
timeout-minutes: 60
steps:
@@ -39,6 +50,8 @@ jobs:
clean: true
- uses: dtolnay/rust-toolchain@stable
- run: bash tools/ci/runner-env.sh
env:
HORIZON_NO_SCCACHE: ${{ inputs.trusted && '1' || '' }}
- run: bash tools/ci/vanilla-data.sh
- name: Compile and validate original exporters against the pinned jars
shell: bash
@@ -90,7 +103,7 @@ jobs:
mac: true
dir: horizon-macos-arm64
asset: horizon-macos-arm64.zip
runs-on: ${{ matrix.mac && (vars.MAC_RUNNER || 'ludovics-mac-mini') || matrix.os }}
runs-on: ${{ matrix.mac && (inputs.trusted && vars.MAC_RUNNER || fromJSON('["self-hosted", "macOS", "horizon-game"]')) || matrix.os }}
# Notarizing the zip can take a few minutes.
timeout-minutes: ${{ matrix.mac && 60 || 40 }}
env:
@@ -117,7 +130,9 @@ jobs:
- uses: Swatinem/rust-cache@v2
if: runner.environment == 'github-hosted'
with:
shared-key: release-${{ matrix.name }}
# A release restores only what a release saved: an untrusted build has its own key and saves nothing.
shared-key: ${{ inputs.trusted && 'release' || 'nightly' }}-${{ matrix.name }}
save-if: ${{ inputs.trusted }}
- name: ALSA and udev headers
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev
@@ -173,6 +188,8 @@ jobs:
done
- name: Tools from the runner
if: runner.environment == 'self-hosted'
env:
HORIZON_NO_SCCACHE: ${{ inputs.trusted && '1' || '' }}
run: bash tools/ci/runner-env.sh
- name: Resources prepared from the runner's own Minecraft
if: runner.environment == 'self-hosted'
+4
View File
@@ -14,6 +14,9 @@ run-name: nightly build${{ inputs.request && format(' (request {0})', inputs.req
# pushes the merge as nightly/build-<date>-<n> and saves the set on the nightly-state branch.
# - This file, game-build.yml and every script below run from main's copy: a schedule runs the default branch, and
# `uses: ./…` takes the caller's commit. The union's own .github/ is never read.
# - `build` (game-build.yml, `trusted: false`) never reaches a release's tools: its macOS jobs run on the runner
# that already runs pull requests' parity jobs, never the release runner; its Rust cache has its own key and is
# never saved; and releases don't read the machine's shared sccache.
# - `build` (game-build.yml) checks out and compiles the merge (or the union) with no secrets: its token reads contents only and
# isn't kept in the checkout; the macOS programs are signed ad hoc (Developer ID needs the runner's keychain,
# which stays locked for nightlies).
@@ -107,6 +110,7 @@ jobs:
version: ${{ needs.pick.outputs.version }}
nightly: ${{ needs.pick.outputs.nightly }}
developer_id: false
trusted: false # it can hold unreviewed pull requests: their own cache key, never saved, not the release runner
sign:
needs: [pick, build]
+1
View File
@@ -90,6 +90,7 @@ jobs:
with:
ref: ${{ needs.decide.outputs.head }}
version: ${{ needs.decide.outputs.version }}
trusted: true # main: the release runner, the release cache, no shared sccache
sign:
needs: [decide, build]
+5 -1
View File
@@ -474,7 +474,11 @@ comment on any issue or pull request (`.github/workflows/nightly-command.yml`, `
merge with a read-only token that isn't kept in the checkout and no secrets; the runner's Developer ID keychain
stays locked. `sign` is the only job with the key, and checks out only main's `tools/ci/sign_release.sh`, which
hashes the archives with the runner's `sha256sum` and signs with its OpenSSL: it never runs what `build` made.
`publish` runs main's `horizon-release-sign`, never the archives.
`publish` runs main's `horizon-release-sign`, never the archives. Nothing a nightly's build leaves reaches a
release either: `game-build.yml`'s `trusted` input is true only for `release.yml`. An untrusted build runs its
macOS jobs on the runner that runs pull requests' parity jobs (`horizon-game`), never the release runner
(`MAC_RUNNER`), and its Rust cache has its own key and is never saved. A trusted build doesn't use the machine's
shared sccache, which pull requests' jobs write (`HORIZON_NO_SCCACHE`, `tools/ci/runner-env.sh`).
- **Players.** Releases stay the default and the only channel any launcher follows unless its player turns Nightly
on. `release_train.py`, `horizon-server update`, `install.sh` and the launcher's release list skip the tags: none
of them is `vX.Y.Z`.
+35
View File
@@ -85,3 +85,38 @@ class ScheduledTests(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
WORKFLOWS = Path(__file__).resolve().parents[1] / ".github" / "workflows"
class UntrustedBuildTests(unittest.TestCase):
"""A nightly can hold unreviewed pull requests: nothing its build leaves may reach a release (game-build.yml)."""
def setUp(self):
self.game = (WORKFLOWS / "game-build.yml").read_text()
def test_only_the_release_is_trusted(self):
self.assertIn("trusted: true", (WORKFLOWS / "release.yml").read_text())
nightly_build = (WORKFLOWS / "nightly-build.yml").read_text()
self.assertIn("trusted: false", nightly_build)
self.assertNotIn("trusted: true", nightly_build)
self.assertIn("default: false", self.game.split("trusted:", 1)[1].split("developer_id:", 1)[0])
def test_an_untrusted_build_neither_shares_nor_saves_the_release_cache(self):
self.assertIn("shared-key: ${{ inputs.trusted && 'release' || 'nightly' }}-${{ matrix.name }}", self.game)
self.assertIn("save-if: ${{ inputs.trusted }}", self.game)
self.assertEqual(self.game.count("Swatinem/rust-cache"), 1)
def test_an_untrusted_build_never_runs_on_the_release_runner(self):
runs_on = [line for line in self.game.splitlines() if "runs-on:" in line]
self.assertEqual(len(runs_on), 2)
pr_runner = "fromJSON('[\"self-hosted\", \"macOS\", \"horizon-game\"]')"
for line in runs_on:
self.assertIn(f"inputs.trusted && vars.MAC_RUNNER || {pr_runner}", line)
def test_a_trusted_build_never_reads_the_shared_sccache(self):
calls = self.game.count("bash tools/ci/runner-env.sh")
self.assertEqual(self.game.count("HORIZON_NO_SCCACHE: ${{ inputs.trusted && '1' || '' }}"), calls)
env = (Path(__file__).resolve().parents[1] / "tools/ci/runner-env.sh").read_text()
self.assertEqual(env.count('-z "${HORIZON_NO_SCCACHE:-}"'), 2)
+3 -2
View File
@@ -15,7 +15,8 @@ if [ "$(uname)" = Darwin ]; then
echo "JAVA_HOME=$java_home" >> "$GITHUB_ENV"
# Builds go through the machine's sccache (shared with ~/fleet/rbuild), so the build folders runner-gc.sh
# removes come back from the cache instead of compiling cold.
if [ -x /opt/homebrew/bin/sccache ]; then
# Not for a release (HORIZON_NO_SCCACHE=1, game-build.yml's trusted builds): pull requests' jobs write that cache.
if [ -x /opt/homebrew/bin/sccache ] && [ -z "${HORIZON_NO_SCCACHE:-}" ]; then
{ echo "RUSTC_WRAPPER=/opt/homebrew/bin/sccache"; echo "CARGO_INCREMENTAL=0"; } >> "$GITHUB_ENV"
fi
else
@@ -40,7 +41,7 @@ else
[ -n "$java_home" ] || { echo "::error::no JDK $java_major on this runner"; exit 1; }
{ echo "$bin"; echo "$java_home/bin"; } >> "$GITHUB_PATH"
echo "JAVA_HOME=$java_home" >> "$GITHUB_ENV"
if sccache=$(command -v sccache); then
if [ -z "${HORIZON_NO_SCCACHE:-}" ] && sccache=$(command -v sccache); then
{ echo "RUSTC_WRAPPER=$sccache"; echo "CARGO_INCREMENTAL=0"; } >> "$GITHUB_ENV"
fi
fi