Skip to content

ci: reuse each native build's output until its inputs change - #243

Open
herefishyfish wants to merge 13 commits into
NativeScript:masterfrom
herefishyfish:ci/cache-native-outputs
Open

herefishyfish wants to merge 13 commits into
NativeScript:masterfrom
herefishyfish:ci/cache-native-outputs

Conversation

@herefishyfish

@herefishyfish herefishyfish commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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-cache hashes git's ids of those files, restores the output under that key, and the job skips its build on a hit.

  • The canvas Android, iOS, Windows and Linux outputs were not cached. They are now.
  • The SVG, audio and Windows module outputs had their own hashFiles keys. They use the action too. Their old keys missed some inputs: the SVG mobile keys did not count Cargo.toml, so a Skia bump reused the old output, and the SVG Windows key did not count canvas-core or gl-bindings.
  • Crates are listed as crates minus the ones the output does not link, so a new crate counts until someone excludes it. The Windows module jobs still list theirs.
  • An input that matches no tracked file fails the job, so a renamed file cannot drop out of a key.
  • .github/actions and build-native.yml count for every output.
  • The week is part of the key, because Cargo.lock is not committed and crate versions float.
  • Releases (tags) always build.

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 pr prereleases can reuse an older output, for a week at most.

Verification

  • Compared with master's workflow, every job has the same steps once cache steps and guards are left out.
  • Each list covers every file master's key for that output covers.
  • The action's key step, run on throwaway edits: a TypeScript, docs or version change moves no key. A canvas-2d edit moves the four canvas outputs. A build-napi.sh edit moves only Windows.
  • Over the last 60 master commits, the 12 outputs rebuild 149 times. With master's keys they rebuild 272 times. 22 commits rebuild nothing, and with master's keys none do.

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_TOKEN read-only.

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.
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 46d2b395-4f47-41f5-b86a-05692a9745e4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant