diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c04a3f5466..8b6e83dea1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,8 @@ on: - "AGENTS.md" - "docs/**/*.md" pull_request: + # Ready for a merge queue: the required checks on each pull request merged with the ones before it. + merge_group: workflow_dispatch: # One independent default-branch snapshot daily, not a full run for every queued merge. schedule: @@ -34,6 +36,8 @@ jobs: timeout-minutes: 5 outputs: docs-only: ${{ steps.paths.outputs.docs-only }} + translator: ${{ steps.paths.outputs.translator }} + rust-only: ${{ steps.paths.outputs.rust-only }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -61,6 +65,25 @@ jobs: fi fi echo "docs-only=$docs_only" >> "$GITHUB_OUTPUT" + # The translator suite runs on a pull request only when something it can depend on changed; it always runs + # on main, in the merge queue and every day. Anything unclear runs it. + translator=true + if git rev-parse --verify -q "${base}^{commit}" >/dev/null 2>&1 && + git diff --quiet --no-renames "$base" "$GITHUB_SHA" -- tools tests scripts runtime make_game.py \ + .github/workflows/ci.yml; then + translator=false + fi + echo "translator=$translator" >> "$GITHUB_OUTPUT" + # Only Rust sources of the D3D12 runtime: the Windows Python jobs have nothing to say about them. The Linux + # job still runs the tests that read them, and the D3D12 runtime workflow builds and tests them. + rust_only=false + if git rev-parse --verify -q "${base}^{commit}" >/dev/null 2>&1 && + ! git diff --quiet "$base" "$GITHUB_SHA" -- && + git diff --quiet --no-renames "$base" "$GITHUB_SHA" -- . \ + ':(exclude,top,glob)d3d12/crates/**/*.rs' ':(exclude,top,glob)d3d12/apps/**/*.rs'; then + rust_only=true + fi + echo "rust-only=$rust_only" >> "$GITHUB_OUTPUT" # A docs-only diff still needs the tests that read those documents, because `check` is skipped for it: every # tests/test_docs_*.py (links, the design.md contract rows, list items, the repository paths a document # names) and the i18n index, which checks docs/i18n/README.md. All are standard library only and read only @@ -81,13 +104,20 @@ jobs: PreflightPrerequisiteTest.test_ensure_submodule_names_the_clone_command_the_readme_gives || exit 1 python3 -I tests/test_progress_dashboard.py Github.test_default_repo_is_the_one_the_readme_clones || exit 1 - check: + # The standard-library loop, over two runners: about 11 minutes on one (658 files, 1 December 2026). `check` below + # is the single result branch protection asks for. + check-tests: + name: check shard ${{ matrix.shard }} needs: change-scope - if: ${{ !cancelled() && needs.change-scope.outputs.docs-only != 'true' }} + if: ${{ !cancelled() && needs.change-scope.outputs.docs-only != 'true' && needs.change-scope.outputs.rust-only != 'true' }} runs-on: windows-latest - # The standard-library loop takes about 20 minutes on this runner (486 files in 20 min 15 s, the whole job - # 21 min 20 s, on 24 November 2026). At 15 the job was cancelled on every run and reported nothing. timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + shard: [1, 2] + env: + SHARD: ${{ matrix.shard }}/2 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -96,15 +126,6 @@ jobs: - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: "3.12" - - uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 - with: - dotnet-version: "8.0.x" - cache: true - cache-dependency-path: "**/packages.lock.json" - - name: Python tools compile - run: python -m compileall -q make_game.py tools tests - - name: make_game.py help - run: python -I make_game.py --help - name: Tests (standard library only, no game data) shell: bash run: | @@ -115,14 +136,37 @@ jobs: continue fi printf '%s\n' "$t" - done < <(find tests -path 'tests/semantic' -prune -o -type f -name 'test_*.py' -print | LC_ALL=C sort) | python -I scripts/run_standalone_tests.py -j 4 + done < <(find tests -path 'tests/semantic' -prune -o -type f -name 'test_*.py' -print | LC_ALL=C sort) | python -I scripts/run_standalone_tests.py -j 4 --shard "${SHARD:-1/1}" + + check-build: + needs: change-scope + if: ${{ !cancelled() && needs.change-scope.outputs.docs-only != 'true' && needs.change-scope.outputs.rust-only != 'true' }} + runs-on: windows-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: recursive + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: "3.12" + - uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 + with: + dotnet-version: "8.0.x" + cache: true + cache-dependency-path: "**/packages.lock.json" + - name: Python tools compile + run: python -m compileall -q make_game.py tools tests + - name: make_game.py help + run: python -I make_game.py --help - name: Build rpf9dump run: dotnet build tools/rpf9dump/rpf9dump.csproj -c Release - name: Test TTPF export retry env: RPF9DUMP_DLL: tools/rpf9dump/bin/Release/net8.0/rpf9dump.dll run: python -I tests/test_ttpf_export_resume.py - # The standard-library loop above runs this file before rpf9dump is built, where it skips for lack of the DLL. + # The standard-library loop (check-tests) runs this file without rpf9dump, where it skips for lack of the DLL. - name: Test rpf9dump exit codes env: RPF9DUMP_DLL: tools/rpf9dump/bin/Release/net8.0/rpf9dump.dll @@ -140,6 +184,21 @@ jobs: - name: Test rpf9dump diagnostics run: dotnet run --project tests/Rpf9DumpDiagnostics/Rpf9DumpDiagnostics.csproj -c Release + check: + needs: [change-scope, check-tests, check-build] + # always(): a cancelled part is a failed result, not a missing one. + if: ${{ always() && needs.change-scope.outputs.docs-only != 'true' && needs.change-scope.outputs.rust-only != 'true' }} + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Every part passed + env: + TESTS: ${{ needs.check-tests.result }} + BUILD: ${{ needs.check-build.result }} + run: | + echo "tests: $TESTS, build: $BUILD" + [ "$TESTS" = success ] && [ "$BUILD" = success ] + # Consolidated Linux job: viewer streaming tests, pytest translator/numpy tests, and the Linux standard-library # test loop (with SPIRV-Tools, LLVM 21, and numpy installed so spirv-val checks, numpy paths, and POSIX-only # tests that skip on Windows run here). @@ -204,7 +263,7 @@ jobs: semantic-tests: needs: change-scope - if: ${{ !cancelled() && needs.change-scope.outputs.docs-only != 'true' }} + if: ${{ !cancelled() && needs.change-scope.outputs.docs-only != 'true' && needs.change-scope.outputs.translator != 'false' }} runs-on: ubuntu-latest timeout-minutes: 10 steps: diff --git a/.github/workflows/d3d12.yml b/.github/workflows/d3d12.yml index 3cf56fa817..55f0556968 100644 --- a/.github/workflows/d3d12.yml +++ b/.github/workflows/d3d12.yml @@ -18,14 +18,17 @@ on: # leonida-lua's tests read mods/example_lua. - "mods/**" - ".github/workflows/d3d12.yml" + # No path filter on these two: a required check that never starts would block the merge. `scope` skips the builds when + # nothing they read changed, and a skipped check counts as passed. pull_request: - paths: - - "d3d12/**" - # leonida-lua's tests read mods/example_lua. - - "mods/**" - - ".github/workflows/d3d12.yml" + merge_group: workflow_dispatch: +env: + # Line numbers in a failing test's backtrace, without the rest of the debug information: faster to build. + CARGO_PROFILE_DEV_DEBUG: line-tables-only + CARGO_INCREMENTAL: "0" + permissions: contents: read @@ -35,8 +38,39 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + scope: + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + build: ${{ steps.paths.outputs.build }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 2 + persist-credentials: false + - name: Does anything the builds read change + id: paths + shell: bash + env: + QUEUE_BASE: ${{ github.event.merge_group.base_sha }} + run: | + # A pull_request checkout is the test merge, its first parent the base. Anything unclear builds. + build=true + base="" + case "$GITHUB_EVENT_NAME" in + pull_request) base="${GITHUB_SHA}^1" ;; + merge_group) base="$QUEUE_BASE"; git fetch -q --depth=1 origin "$base" || base="" ;; + esac + if [ -n "$base" ] && git rev-parse --verify -q "${base}^{commit}" >/dev/null 2>&1 && + git diff --quiet --no-renames "$base" "$GITHUB_SHA" -- d3d12 mods .github/workflows/d3d12.yml; then + build=false + fi + echo "build=$build" >> "$GITHUB_OUTPUT" + d3d12: name: d3d12 (windows-latest) + needs: scope + if: ${{ !cancelled() && needs.scope.outputs.build != 'false' }} # The crates are Windows-only today (leonida-gpu does not build on macOS); Linux follows #2577 if it lands. runs-on: windows-latest timeout-minutes: 70 @@ -66,23 +100,56 @@ jobs: d3d12-windows-cargo- - name: Build run: cargo build --workspace --all-targets --locked - # The features of the executable people run (d3d12/scripts/build-nvidia.ps1, without dlss); no other step builds them. - - name: Build as shipped (diagnostics, mimalloc) - run: cargo build -p leonida --features diagnostics,mimalloc --locked # The software adapter of the runner does not do the depth bounds test as this one expects, and #2663 fixes that # in the renderer; drop the --skip with it. A failing test here also stops the crates after leonida-gpu. - name: Tests (no GPU, no game data) timeout-minutes: 30 run: cargo test --workspace --exclude xtask --locked -- --skip depth_bounds_pipeline_loads_and_filters_draws - # tests/replay.rs is compiled only with the diagnostics feature. - - name: Replay test (diagnostics) - timeout-minutes: 15 - run: cargo test -p leonida-gpu --features diagnostics --test replay --locked # Report only until host.rs and lower.rs are split under the limit; make it blocking then. - name: Asset policy (report) continue-on-error: true + if: github.event_name != 'pull_request' run: cargo test -p xtask --locked # Report only until the existing findings are fixed; make it blocking (-D warnings) then. - name: Clippy (report) continue-on-error: true + if: github.event_name != 'pull_request' run: cargo clippy --workspace --all-targets --locked -- -D warnings + + shipped: + name: d3d12 shipped (windows-latest) + needs: scope + if: ${{ !cancelled() && needs.scope.outputs.build != 'false' }} + runs-on: windows-latest + timeout-minutes: 70 + defaults: + run: + working-directory: d3d12 + shell: bash + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + # The runner's own rustup installs the toolchain pinned in d3d12/rust-toolchain.toml, no third-party action. + - name: Rust toolchain + run: | + rustup show active-toolchain || rustup toolchain install + rustc --version + echo "RUSTC_HASH=$(rustc -vV | tr -d '\r' | awk '/^commit-hash: /{print $2}')" >> "$GITHUB_ENV" + - name: Cache Cargo downloads + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: d3d12-windows-cargo-${{ env.RUSTC_HASH }}-${{ hashFiles('d3d12/Cargo.lock') }} + restore-keys: | + d3d12-windows-cargo-${{ env.RUSTC_HASH }}- + d3d12-windows-cargo- + # The features of the executable people run (d3d12/scripts/build-nvidia.ps1, without dlss); no other step builds them. + - name: Build as shipped (diagnostics, mimalloc) + run: cargo build -p leonida --features diagnostics,mimalloc --locked + # tests/replay.rs is compiled only with the diagnostics feature. + - name: Replay test (diagnostics) + timeout-minutes: 15 + run: cargo test -p leonida-gpu --features diagnostics --test replay --locked diff --git a/.github/workflows/no-game-data.yml b/.github/workflows/no-game-data.yml index 89cf28d957..9080b6520d 100644 --- a/.github/workflows/no-game-data.yml +++ b/.github/workflows/no-game-data.yml @@ -3,6 +3,8 @@ on: push: branches: [main] pull_request: + # The merge queue runs the required checks on each pull request merged with the ones before it. + merge_group: workflow_dispatch: concurrency: diff --git a/docs/linux.md b/docs/linux.md index cd20a1f884..46caa92d86 100644 --- a/docs/linux.md +++ b/docs/linux.md @@ -14,7 +14,7 @@ names; the build lists anything it can't find before it starts. | `make_game.py`: check, shaders, assets, pipelines | Native | CI (`linux-python-and-viewer`, `semantic-tests`) | | `Build.sh`, `Mods.sh` | Native (`/bin/sh`) | `tests/test_shell_launchers.py`, in the standard-library loop of `linux-python-and-viewer` | | Shader translator, its tests and the GPU test tools (`vk_harness`, `vk_pipeline_check`, ...) | Native, GCC or Clang | CI (`linux-gpu-tools`: GCC, tests on llvmpipe); Clang builds them too, but no CI job uses it yet | -| `rpf9dump` (asset export) | Native, .NET 8 or newer | CI builds it on Windows only (the `check` job) | +| `rpf9dump` (asset export) | Native, .NET 8 or newer | CI builds it on Windows only (the `check-build` job) | | `gta6rt`, its shims and their tests | Windows program, under Wine or Proton | Cross-built with clang-cl and xwin; CI runs the Windows build under Wine on pushes to `main` | | `scripts/run_game_wine.sh`: one retail run under Wine, headless or visible, counts only ([linux_proton.md](linux_proton.md#running-the-game-under-wine-with-one-command)) | Native (`bash`) around the Windows `gta6rt` | `tests/test_run_game_wine.py` and `tests/test_game_run_summary.py`, without the game | diff --git a/scripts/run_standalone_tests.py b/scripts/run_standalone_tests.py index 5c6695cebf..dee915ef2f 100644 --- a/scripts/run_standalone_tests.py +++ b/scripts/run_standalone_tests.py @@ -6,6 +6,7 @@ each file's output together and still reports every failure at the end. """ import argparse +import re from concurrent.futures import ThreadPoolExecutor, as_completed import subprocess import sys @@ -18,6 +19,14 @@ def positive_int(value): return jobs +def shard(text): + """(I, N) of `I/N`: part I of N.""" + m = re.fullmatch(r"([1-9]\d{0,2})/([1-9]\d{0,2})", text) + if not m or int(m.group(1)) > int(m.group(2)): + raise argparse.ArgumentTypeError("shard must be I/N with 1 <= I <= N") + return int(m.group(1)), int(m.group(2)) + + def run_file(path): try: # A test (or one of its children) must not read the stream of selected paths. @@ -55,8 +64,12 @@ def run_tests(paths, jobs): def main(argv=None): parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("-j", "--jobs", type=positive_int, default=1, help="files at a time (default: 1)") + parser.add_argument("--shard", type=shard, default=(1, 1), metavar="I/N", + help="run every Nth path from the Ith one (default: 1/1, all of them)") args = parser.parse_args(argv) - return run_tests([path for path in sys.stdin.read().splitlines() if path], args.jobs) + paths = [path for path in sys.stdin.read().splitlines() if path] + part, parts = args.shard + return run_tests(paths[part - 1::parts], args.jobs) if __name__ == "__main__": diff --git a/tests/test_ci_registration.py b/tests/test_ci_registration.py index 5eed7dabc2..9f5396ef33 100644 --- a/tests/test_ci_registration.py +++ b/tests/test_ci_registration.py @@ -800,6 +800,7 @@ def test_loop_runs_past_a_failure_and_names_every_failed_file(self): f.write("#!/bin/sh\nexec '%s' \"$@\"\n" % sys.executable.replace("'", "'\\''")) os.chmod(shim, 0o755) env = dict(os.environ, PYTEST_FILE_MARKERS=markers, PATH=bindir + os.pathsep + os.environ.get("PATH", "")) + env.pop("SHARD", None) # the part this test file itself runs in, on the runner # GitHub runs `shell: bash` as `bash --noprofile --norc -eo pipefail {0}`. result = subprocess.run([git_bash(), "--noprofile", "--norc", "-eo", "pipefail", "step.sh"], cwd=tmp, env=env, capture_output=True, text=True, timeout=120) diff --git a/tests/test_run_standalone_tests.py b/tests/test_run_standalone_tests.py index 684294c5c5..eb3d8363c8 100644 --- a/tests/test_run_standalone_tests.py +++ b/tests/test_run_standalone_tests.py @@ -15,6 +15,22 @@ import run_standalone_tests as runner # noqa: E402 +class ShardTest(unittest.TestCase): + def test_the_parts_cover_every_path_once(self): + paths = [f"test_{i}.py" for i in range(10)] + got = [] + for part in range(1, 5): + with mock.patch.object(runner, "run_tests", side_effect=lambda p, jobs: got.extend(p) or 0), \ + mock.patch.object(sys, "stdin", io.StringIO("\n".join(paths))): + self.assertEqual(runner.main(["--shard", f"{part}/4"]), 0) + self.assertEqual(sorted(got), sorted(paths)) + + def test_bad_shards(self): + for text in ("0/4", "5/4", "1", "1/0", "a/b", "1/4/2"): + with self.assertRaises(SystemExit), contextlib.redirect_stderr(io.StringIO()): + runner.main(["--shard", text]) + + class StandaloneRunnerTest(unittest.TestCase): def run_cli(self, cwd, paths, jobs): return subprocess.run([sys.executable, "-I", str(RUNNER), "-j", str(jobs)],