CI: run only what a change needs, on pull requests and on main

- Pushes to main use the same code/no-code rule as pull requests (`touches_code` in Select
  checks): a push changing only documentation, packaging, other workflows or the bots' scripts
  runs the repository checks only. With the merge queue off, every push to main ran the full suite
  and the Windows jobs, docs-only ones included.
- affected.py: test data under tests/ selects the packages that read it (robustness, hole matrix,
  projection, taper: solidcraft-engine; oracle: the CLI, the kernel, xtask; action matrix: the
  CLI, the engine, xtask), and a vendored crate the packages that use it (truck: the kernel and up;
  egui-wgpu: the UI and the apps), instead of the whole workspace. tests/tools and unknown vendored
  crates still select everything.
- Docker (the web app image) skips pushes touching only docs, test data or bot scripts; Pages skips
  test data and bot scripts; Generated files runs only when the manifests, lockfile, command
  registry, CLI or xtask change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QWhMwdqJYQKQq8RCLSL1LT
This commit is contained in:
jyviko
2026-10-19 08:48:31 -04:00
committed by Irakli Kourtis
parent 983fbe2b14
commit 948c208db9
6 changed files with 130 additions and 15 deletions
+32 -10
View File
@@ -11,8 +11,11 @@
# the viewport's GPU glue, the graphics dependencies, their scripts or this file); main and
# nightly always run them. Only main saves the build caches; pull requests restore them.
# The merge queue runs the full suite on exactly the commit it then puts on main, so a push to
# main that a passing merge-queue run already tested runs only the repository checks; a push
# that skipped the queue still runs everything. Pull requests run the reference tests when the
# main that a passing merge-queue run already tested runs only the repository checks. A push that
# skipped the queue runs everything when it changes code; one that changes only documentation,
# packaging, other workflows or the GitHub bots' scripts (the same rule as pull requests,
# `touches_code` in Select checks) runs only the repository checks. Test data under tests/ and
# vendored crates under vendor/ select the packages that read them (scripts/ci/affected.py). Pull requests run the reference tests when the
# command line (or anything it depends on) changes, and doc tests for the affected packages.
# Heavy checks wait for review: a pull request without the `approved-for-ci` label runs only
# Select checks, the format and repository checks and a quick compile. Adding the label (after
@@ -122,6 +125,7 @@ jobs:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PUSH_SHA: ${{ github.sha }}
BEFORE_SHA: ${{ github.event.before }}
REPO: ${{ github.repository }}
APPROVED: ${{ contains(github.event.pull_request.labels.*.name, 'approved-for-ci') }}
GH_TOKEN: ${{ github.token }}
@@ -132,6 +136,23 @@ jobs:
windows=false
full=true
packages=
# Whether any of the NUL-separated paths on stdin is something a build or test reads.
# Pull requests and pushes to main share it, so a docs-only change runs no native job
# on either.
touches_code() {
local path
while IFS= read -r -d '' path; do
case "$path" in
.github/workflows/ci.yml) return 0 ;;
*.rs|Cargo.toml|Cargo.lock|*/Cargo.toml|.cargo/*|rust-toolchain*) return 0 ;;
docs/*|*.md|.github/*|packaging/*|LICENSE*|NOTICE|THIRD-PARTY-LICENSES.txt) ;;
# The GitHub bots' scripts: no Rust, tested in this job (Claim and triage bot tests).
scripts/claim/*|scripts/triage/*) ;;
*) return 0 ;;
esac
done
return 1
}
if [ "$EVENT_NAME" = push ]; then
# The queue lands the very commit its merge_group run tested. If that run passed,
# testing the push again proves nothing new; otherwise (a merge that skipped the
@@ -142,7 +163,15 @@ jobs:
| grep -o '"total_count": *[0-9]*' | grep -o '[0-9]*$' || echo 0)
if [ "${tested:-0}" -gt 0 ]; then
echo "The merge queue already tested $PUSH_SHA: repository checks only."
elif [ -n "$BEFORE_SHA" ] && [ "${BEFORE_SHA#0000000}" = "$BEFORE_SHA" ] \
&& git cat-file -e "$BEFORE_SHA^{commit}" 2>/dev/null \
&& git diff --no-renames --name-only -z "$BEFORE_SHA" "$PUSH_SHA" > "$RUNNER_TEMP/ci-paths" \
&& ! touches_code < "$RUNNER_TEMP/ci-paths"; then
# Nothing a build reads changed (documentation, packaging, other workflows, the bots'
# scripts): the code on main is what the last push already tested.
echo "$BEFORE_SHA..$PUSH_SHA changes no code: repository checks only."
else
# Code changed (or the push can't be compared): main runs everything.
native=true
windows=true
fi
@@ -164,15 +193,8 @@ jobs:
crates/gpu/*|apps/solidcraft/*|crates/ui-egui/src/gpu.rs|vendor/egui-wgpu/*) windows=true ;;
tools/windows-*.ps1|.github/workflows/ci.yml|rust-toolchain*|.cargo/*) windows=true ;;
esac
case "$path" in
.github/workflows/ci.yml) native=true ;;
*.rs|Cargo.toml|Cargo.lock|*/Cargo.toml|.cargo/*|rust-toolchain*) native=true ;;
docs/*|*.md|.github/*|packaging/*|LICENSE*|NOTICE|THIRD-PARTY-LICENSES.txt) ;;
# The GitHub bots' scripts: no Rust, tested in this job (Claim and triage bot tests).
scripts/claim/*|scripts/triage/*) ;;
*) native=true ;;
esac
done < "$RUNNER_TEMP/ci-paths"
if touches_code < "$RUNNER_TEMP/ci-paths"; then native=true; fi
# A lockfile change that moves the graphics stack (wgpu, naga, egui, winit, windows).
if [ "$windows" = false ] && grep -qxz 'Cargo.lock' "$RUNNER_TEMP/ci-paths" \
&& git diff "$BASE_SHA...$HEAD_SHA" -- Cargo.lock \
+3
View File
@@ -14,6 +14,9 @@ name: Docker
on:
push:
branches: [main]
# The image holds the web app only: documentation, test data and the GitHub bots' scripts can't
# change it, so a push touching only those builds nothing (edge stays at the last code change).
paths-ignore: ["docs/**", "**/*.md", "tests/**", "scripts/claim/**", "scripts/triage/**"]
release:
types: [published]
pull_request:
+9
View File
@@ -6,6 +6,15 @@ name: Generated files
on:
push:
branches: [main]
# THIRD-PARTY-LICENSES.txt follows the manifests and the lockfile; docs/features.md follows the
# command registry (crates/engine), read through solidcraft-cli. Other pushes regenerate nothing.
paths:
- "Cargo.lock"
- "**/Cargo.toml"
- "crates/engine/**"
- "apps/solidcraft-cli/**"
- "xtask/**"
- ".github/workflows/generated.yml"
workflow_dispatch:
permissions:
+2
View File
@@ -6,6 +6,8 @@ name: Pages
on:
push:
branches: [main]
# The site is the book and the web app: test data and the GitHub bots' scripts change neither.
paths-ignore: ["tests/**", "scripts/claim/**", "scripts/triage/**"]
workflow_dispatch:
inputs:
release_tag:
+49 -5
View File
@@ -12,9 +12,10 @@ Prints and optionally appends to $GITHUB_OUTPUT:
packages=a b c the affected packages (empty when full, or when nothing needs building)
A changed file maps to the package whose directory holds it. The packages that depend on those
(directly or not, dev-dependencies included) are added. Anything that can change every package,
or that no package owns, selects the full workspace. Only documentation and packaging files are
ignored.
(directly or not, dev-dependencies included) are added. Test data under tests/ maps to the
packages that read it, and a vendored crate (vendor/, a [patch] of a crates.io dependency) to the
packages that use it. Anything that can change every package, or that no package owns, selects
the full workspace. Only documentation and packaging files are ignored.
"""
import argparse
import json
@@ -22,7 +23,7 @@ import subprocess
import sys
# Changes here can affect every package.
FULL_PREFIXES = (".cargo/", ".config/", ".github/", "vendor/", "tests/", "scripts/")
FULL_PREFIXES = (".cargo/", ".config/", ".github/", "scripts/")
FULL_FILES = ("Cargo.toml", "Cargo.lock")
# Changes here affect no code: documentation and packaging.
IGNORED_PREFIXES = ("docs/", "packaging/")
@@ -30,6 +31,29 @@ IGNORED_PREFIXES = ("docs/", "packaging/")
EMBEDDED = {"ATTRIBUTION.md": "solidcraft-ui-egui"}
# Asset folders that only some packages read: the UI embeds the catalogs, xtask checks them.
EMBEDDED_PREFIXES = {"assets/locales/": ("solidcraft-ui-egui", "xtask")}
# Test data and the package directories whose tests (or xtask) read it. Any other folder under
# tests/ selects the full workspace.
TEST_DATA = {
"tests/robustness/": ("crates/engine/",),
"tests/hole_matrix/": ("crates/engine/",),
"tests/projection/": ("crates/engine/",),
"tests/taper/": ("crates/engine/",),
"tests/oracle/": ("apps/solidcraft-cli/", "crates/kernel/", "xtask/"),
"tests/action_matrix/": ("apps/solidcraft-cli/", "crates/engine/", "xtask/"),
}
# Vendored crates (vendor/<crate>/, a [patch] of a crates.io dependency) and the dependency names
# through which workspace packages reach them: the truck crates and their maths crate only through
# truck itself (crates/kernel), egui-wgpu directly or through eframe. Another vendored crate
# selects the full workspace.
TRUCK = lambda dep: dep.startswith("truck-") # noqa: E731
VENDOR_USES = {
"truck-geometry": TRUCK,
"truck-shapeops": TRUCK,
"truck-stepio": TRUCK,
"truck-meshalgo": TRUCK,
"matext4cgmath": TRUCK,
"egui-wgpu": lambda dep: dep in ("egui-wgpu", "eframe"),
}
def load_metadata(path):
@@ -69,12 +93,32 @@ def select(meta, paths):
if target:
dependents[target].add(p["name"])
def users_of(vendored):
"""The workspace packages that depend on a vendored crate (by dependency name)."""
uses = VENDOR_USES.get(vendored)
if uses is None:
return set()
return {p["name"] for p in meta["packages"] if any(uses(d["name"]) for d in p["dependencies"])}
hit = set()
for path in paths:
if path in FULL_FILES or path.startswith(FULL_PREFIXES) or path.startswith("rust-toolchain"):
return True, []
owners = [d for d in by_dir if path.startswith(d)]
if owners:
if path.startswith("vendor/"):
if path == "vendor/README.md":
continue
users = users_of(path.split("/")[1])
if not users:
return True, []
hit.update(users)
elif path.startswith("tests/"):
data = next((v for k, v in TEST_DATA.items() if path.startswith(k)), None)
readers = [by_dir[d] for d in data or () if d in by_dir]
if not readers:
return True, []
hit.update(readers)
elif owners:
hit.add(by_dir[max(owners, key=len)])
elif path in EMBEDDED:
hit.add(EMBEDDED[path])
+35
View File
@@ -71,6 +71,41 @@ class RealWorkspace(unittest.TestCase):
def test_docs_only_selects_nothing(self):
self.assertEqual(affected.select(self.meta, ["docs/book/src/dev/testing.md", "CONTRIBUTING.md"]), (False, []))
def test_goldens_select_the_engine_and_its_dependents_not_the_kernel(self):
full, pk = affected.select(self.meta, ["tests/robustness/goldens.json"])
self.assertFalse(full)
self.assertIn("solidcraft-engine", pk)
self.assertNotIn("solidcraft-kernel", pk)
self.assertNotIn("solidcraft-render", pk)
def test_oracle_cases_select_the_cli_and_xtask(self):
full, pk = affected.select(self.meta, ["tests/oracle/box/recipe.json"])
self.assertFalse(full)
self.assertIn("solidcraft-cli", pk)
self.assertIn("xtask", pk)
def test_unmapped_test_data_selects_full(self):
self.assertEqual(affected.select(self.meta, ["tests/tools/x.json"]), (True, []))
def test_vendored_truck_selects_the_kernel_and_up_not_render(self):
full, pk = affected.select(self.meta, ["vendor/truck-shapeops/src/lib.rs"])
self.assertFalse(full)
self.assertIn("solidcraft-kernel", pk)
self.assertIn("solidcraft-engine", pk)
self.assertNotIn("solidcraft-render", pk)
self.assertNotIn("solidcraft-geom", pk)
def test_vendored_egui_wgpu_selects_the_ui_and_apps_not_the_kernel(self):
full, pk = affected.select(self.meta, ["vendor/egui-wgpu/src/winit.rs"])
self.assertFalse(full)
self.assertIn("solidcraft-ui-egui", pk)
self.assertIn("solidcraft", pk)
self.assertNotIn("solidcraft-kernel", pk)
self.assertNotIn("solidcraft-engine", pk)
def test_vendor_readme_alone_selects_nothing(self):
self.assertEqual(affected.select(self.meta, ["vendor/README.md"]), (False, []))
def test_translation_selects_the_ui_and_xtask_not_the_kernel(self):
full, pk = affected.select(self.meta, ["assets/locales/ja.json", "assets/locales/it.json"])
self.assertFalse(full)