Repository navigation
ci: reuse each native build's output until its inputs change - #243
Open
herefishyfish wants to merge 13 commits into
Open
herefishyfish wants to merge 13 commits into
herefishyfish wants to merge 13 commits into
Conversation
A 20-line TypeScript change ran every native build for hours. Each native job now restores its finished output from .github/actions/native-cache and skips its build on a hit, so a change rebuilds only the jobs that depend on it: a crate change rebuilds every platform that links the crate, a Windows script change only the Windows jobs, and a TypeScript change nothing. tools/scripts/native-inputs.py computes each output's key from git objects at the commit. A key covers every tracked file except those OWNERS gives only to other outputs, the crates outside the output's cargo closure, other jobs' workflow blocks and the actions its jobs do not use, so an unplaced file rebuilds everything rather than nothing. The week is part of the key, and the release builds with fresh: true. The Apple xcframeworks, built in per-platform jobs, are looked up first, so a hit skips those jobs, as the canvas-svg lookup already did; the restore takes the lookup's key. Keys replace the hand-kept hashFiles lists. tools/tests/check-native-inputs.py, run by Static Checks, fails when a job reads a file its key leaves out: it follows the jobs' steps, scripts and make -n output, and scans every text file in the key (CMake, Gradle, Xcode, Rust, scripts) for paths that lead out of it. It also checks that every cached job skips its build on a hit and reads no value that changes between runs. The npm prerelease job waits for it.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
GitHub evaluates expressions in an action's input descriptions, so the native-cache action did not load on any runner. The check now fails on an expression in any local action's metadata. An xcframework's first job now restores it, uploads it on a hit and skips the jobs that build it, so a cache entry lost between a lookup and a restore can no longer fail the run, and a hit takes one macOS runner instead of two. On a miss, the last job saves it under the first job's key. That job must need every part, and no job of the output may use always(), cancelled() or failure(), so a failed leg cannot ship a partial xcframework. The key scan now resolves paths from any dir above the file when they go up or start at an unknown variable (CMAKE_CURRENT_SOURCE_DIR, CARGO_MANIFEST_DIR with "/../x", Xcode group paths, Gradle's rootDir), flags crate dirs outside the closure, strips comments by each file's syntax, skips prose, expands matrix values to the values the strategy lists, and fails on a keyed text file too large to scan. The Makefile check also refuses $(VAR:a=b), $V and variables only a recipe sets. The Cargo resolution input now names the dependency fields it hashes and includes each member's features. The Apple builds key only their binary dirs under platforms/ios, and the JavaScript-only packages are placed.
…pload
The key scan no longer takes a comment marker inside a string for a
comment, so a glob such as "src/*/gen.rs" or '**/*.so' cannot hide the
reads after it; Ruby's #{x} reads as a variable, and a kind of file whose
comments are not known is scanned whole. It follows a script's cd, so a
../ path after one resolves. In a job whose legs build different outputs,
only paths made with a matrix value count against any leg; every other
path counts against the output's own key.
The wiring check refuses a status function (success(), always(),
cancelled(), failure()) in any if: of an output's jobs, requires each
build-native.yml job that restores an output to upload it once under its
artifact's name, and refuses expressions only in action descriptions. The
Makefile check accepts a target's own variables and define blocks, and
refuses a ?= default next to any path character. A matrix list written
over several lines is refused, since its values could not be read.
The repo's .github settings and JavaScript and CSS files belong to no
output, nor do the build scripts only nx runs (build-ios.sh and the debug
builds). Outputs without crates compute their key without cargo.
check-native-inputs.py held a job reader, a key scanner and the wiring rules in one 1,170-line file. They now live in tools/tests/native_check (jobs.py, paths.py, wiring.py), with explicit imports between them, and check-native-inputs.py keeps the spec, the check that runs both passes and main. The code moved unchanged: the tests and every earlier review's reproductions give the same results.
Canvas Native run by hand takes `fresh`, which builds every native output without restoring or saving, to check a cached one. The native-cache action says how to drop a bad entry. The jobs that restore the two xcframeworks run on ubuntu-22.04, so a hit takes no macOS runner. actions/cache uses the same version on Linux and macOS, so they restore what the macOS job saved. The cache check now reads: - every cd in a line, and pushd/popd; - exported values and CMake set() lists; - scripts run from another directory or through $GITHUB_ACTION_PATH; - -I/-L/-F flags whose path climbs with ..; - cargo --workspace and package runners in followed scripts; - git describe/log/show, which read the commit. It also refuses continue-on-error and status functions in any if, and a matrix leg that names no artifact.
…uild
The key scan read only the first quoted part of a shell word, so after
`cd "$(dirname "$0")/../../packages/canvas-svg/src-native/ios"`, as in
canvas-svg-build.sh, a relative read was resolved from the wrong dir. A
read of canvas_ios.h there went unseen, and canvas-svg-ios could reuse a
stale xcframework. A word's quoted and bare parts are now one word, and
$(dirname "$0") is the script's own dir. The check now also reads:
- every value of a variable that a cd goes to;
- the default in ${X:-...};
- a path after a dir named another way (format!("{}/x"), root + '/x');
- a value given to a command (X=dir cmd) and a heredoc's body;
- join() segments over several lines;
- get_filename_component modes other than DIRECTORY.
A cargo build must name every crate with -p, without a glob and without
--workspace or --all, in any dir and after --manifest-path. This holds
for plugins (zigbuild, ndk), behind launchers (rustup run, xcrun, cross)
and for a computed cargo.
The wiring check expands a matrix job's native-cache artifact for every
leg, so a leg with no ARTIFACTS entry fails Static Checks rather than
its build. A local action's step may not use continue-on-error or a
status function. Git global options and rev-list count as commit reads.
native-inputs.py adds the root manifest's [patch] and [replace] targets
to every crate closure, since cargo metadata reports a patched
dependency with no path. Today they are non-members and already in the
closure, so no key changes. It also runs git from the repo root, so a
key computes from any dir.
The xcframework's first job restores on Linux what its last job saved on macOS. If those runners ever disagree on the cache version, the first job misses every time and the four macOS part jobs build for nothing, silently. The native-cache action now prints a warning when the last job (given a key) restores an entry. A run by hand with `fresh` saves nothing, so it now has a concurrency group of its own. It can no longer replace a master push that is waiting to save the caches pull requests read. The input's description says it still publishes the prerelease, as any dispatch does.
…ules - The check reads the commands in a "$(...)" or backtick substitution in double quotes, so a cargo build, a package runner or a read there is held to the same rules. A plain assignment's substitution (X="$(cat f)") counts as a read again; round 13 had dropped it. - A cargo command is found where it runs (also cargo-ndk, "$CARGO" ndk, rustup run and xcrun), and only its subcommand decides whether it builds. `cargo build --features new` needs -p; `cargo clean` and `[ "$X" = cross ]` pass. - git commands that read a commit or a ref are refused: ls-tree, cat-file, branch and the like, and a revision given to rev-parse or diff (`git rev-parse @` too). - hashFiles() is exempt only in cache steps. A large fixture in a crate's tests no longer fails the size rule, and a long line no longer recurses or stalls the scan. - build-napi.sh's own module dirs are in NOT_READ. - A `fresh` run shares master's concurrency group again, so prerelease publishes stay in order. - Comments and docstrings now say that each output (not each job) is restored, that an xcframework saves only when all five of its macOS jobs run in one run, and how to add an output.
herefishyfish
marked this pull request as ready for review
November 17, 2026 23:31
Each native job lists what its output is built from as git pathspecs. The native-cache action hashes git's ids of those files, restores the output under that key and skips the build on a hit. This replaces the per-job hashFiles keys and adds the four outputs that had none: canvas-android, canvas-ios, canvas-windows and linux. A Linux lookup restores the split xcframeworks, so a hit takes no macOS runner. Releases (tags) always build.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A 20-line TypeScript change ran the canvas builds on every platform for hours. With this change, each native job reuses its output until something it is built from changes.
How it works
Each native job lists its inputs as git pathspecs.
.github/actions/native-cachehashes git's ids of those files, restores the output under that key, and the job skips its build on a hit.hashFileskeys. They use the action too. Their old keys missed some inputs: the SVG mobile keys did not countCargo.toml, so a Skia bump reused the old output, and the SVG Windows key did not countcanvas-coreorgl-bindings.cratesminus the ones the output does not link, so a new crate counts until someone excludes it. The Windows module jobs still list theirs..github/actionsandbuild-native.ymlcount for every output.Cargo.lockis not committed and crate versions float.One Linux job looks up both split xcframeworks. On a hit it uploads them, and the ten macOS jobs that build them never start.
A job that starts to read a new file needs it in its list. Until then, pull requests and
prprereleases can reuse an older output, for a week at most.Verification
canvas-2dedit moves the four canvas outputs. Abuild-napi.shedit moves only Windows.Not yet verified on GitHub Actions: this version. An earlier, larger version of this branch restored outputs the same way, and its second run restored every output and took native jobs from 232 runner minutes to 8.
PR Publish Notice fails with a 403 on pull requests from forks, because GitHub makes their
GITHUB_TOKENread-only.