Skip to content

ci: skip builds when a change touches no build inputs - #3763

Open
KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:ci/path-filtering-189
Open

KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:ci/path-filtering-189

Conversation

@KuSh

@KuSh KuSh commented Aug 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #189, deliberately not the way it proposed (see below).

What

.github/ has no path filtering: every push to develop runs the whole release build and publishes a dev-*-rc.N prerelease, and every PR runs the whole CI matrix, whatever changed. This adds a gate that skips both when a change touches nothing that can affect the build.

.github/inert-paths.conf holds git pathspecs for those paths. changed-scope.sh subtracts them from a diff range and answers through its exit status, so git does the matching.

The saving depends on how many changes are docs-only. Over the last 100 merges into develop, 3 would have skipped and 97 would have built; every file in the 3 is markdown.

About #189

The issue asked to gate the binary build on the release path. Two problems, both verified:

  1. The proposed diff can never return false. It checks '*.rs' 'Cargo.toml' 'Cargo.lock' 'build.rs' since the previous tag, and release-please's own commit always bumps Cargo.toml and Cargo.lock.
  2. Skipping the build on master breaks installs. install.sh follows the redirect on /releases/latest and downloads that tag's tarballs, so a stable release without assets fails every fresh curl | sh.

So the gate covers develop and PRs, and the master path moves to its own ungated workflow. If you would rather keep #189 open for the release-path idea, drop the Fixes lines before merging.

How a failure behaves

No failure direction ships a stale artifact:

  • The list is inverted, so an unrecognised path builds.
  • The skip verdict is exit status 3, because bash hands out 1, 2 and 127 itself. An accident cannot read as a skip.
  • Gated jobs skip only on an explicit build=false. A failed gate leaves that unset and ends the run red, with fmt and test presence run and clippy and everything below it skipped, so it cannot wave a PR through green.
  • --no-renames throughout: rename detection reports only the destination, so moving an embedded file into docs/ would otherwise look inert on a commit that no longer compiles.

What stays a build input

Some paths look like docs or tooling but are not:

  • hooks/**: src/hooks/init/ embeds files from it, .md ones included. A bare :(exclude)*.md would swallow them, because without ,glob a pathspec * also matches /.
  • docs/guide/pipelines/, docs/guide/proxy/, docs/guide/resources/: tests embed these pages and check them. The rest of docs/ is inert.
  • .claude/hooks/: tests/hook_decision_protocol_test.rs runs .claude/hooks/rtk-rewrite.sh.

check-embed-scope.sh enforces the embedded cases. It resolves every include_str! and include_bytes! target in tracked .rs files, literal or concat!(env!("CARGO_MANIFEST_DIR"), "/…"), and fails if one is excluded, missing, or in a form it cannot resolve. It runs ungated, so it still fires on the PRs that skip everything else. It cannot see a file a test reads at runtime, like the hook above, so those are kept off the list by hand.

Other changes

  • stable-release.yml: the master path moves out of cd.yml, so a bug in the develop gate cannot reach a release.
  • verify-assets in release.yml: asserts all 27 stable-named assets uploaded non-empty and that checksums.txt names nothing that failed to upload. On failure it demotes the release out of /releases/latest, so installs fall back to the last good tag. Discord, the Homebrew tap and the winget manifest wait on it. It detects and demotes but cannot prevent, see Stable releases are 'Latest' for ~6-7 minutes before their assets exist, breaking install.sh #3759.
  • cd.yml diffs from the last RC rather than github.event.before: develop runs are cancel-in-progress, and a docs push landing on a cancelled source build would otherwise skip and strand that source change. A manual dispatch always builds.
  • RCs upload as a draft and publish last. Publishing is what creates the tag, and the gate reads the newest RC tag as "this tree has binaries", so a cancelled or failed upload leaves a draft to delete by hand and no tag, and the next push rebuilds.
  • Security scan diff range: three steps diffed origin/master...HEAD, which on a PR into develop spans every merge since the last release, and reported files the PR never touched as critical. All scans now diff HEAD^1 HEAD, a failing git fails the step instead of passing as clean, and a new step scans changed shell scripts.
  • pr-target-check.yml gains branches: [master], since every PR into develop started a run that only skipped while holding a pull-requests:write token. It also stops flagging release-please's version-bump PR as wrong-base. Both exemptions are keyed by branch and require the branch to live in this repo, since a fork's head branch name is the contributor's to choose.

Test plan

  • changed-scope.sh --self-test, 41 cases, run in CI.
  • check-embed-scope.sh --self-test, 17 fixture cases, run in CI. Breaking the script 14 different ways fails it each time.
  • Overwrote all 74 files the inert list covers: cargo test --all (5508 passed), cargo test --no-default-features and cargo doc results unchanged. Not run for the proxy/ tests, semgrep or benchmark.sh, where a search finds no reference to those paths.
  • Overwrote .claude/hooks/rtk-rewrite.sh: affirmative_allow_hooks_ignore_an_inherited_host fails. A broken page under docs/guide/ fails the tests that embed it.
  • Replayed the last 100 merges into develop: 97 build, 3 skip, all markdown.
  • verify-assets comparison replayed against the real dev-1.2.0-rc.619: nothing missing, nothing dropped.
  • Both self-tests leave the repository untouched with GIT_DIR aimed at it.
  • Real runs on a fork with this commit as a temporary develop:
    • A docs-only PR gets build=false: fmt and everything below it skip, doc review runs, and the run is green.
    • A docs-only push on top of an RC tag skips the pre-release build, and the run is green.
    • softprops/action-gh-release with draft: true, then gh release edit --draft=false: no tag through two uploads, the second upload reuses the draft, publishing creates the tag on the branch tip, and it stays one prerelease with both assets.
  • Those fork runs used GITHUB_TOKEN, not this repo's App token. The first push to develop after merging covers it: a failure shows as a red run with a draft and no tag, and stable releases are not affected.

Known limitations

🤖 Generated with Claude Code

@amandeavor amandeavor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the path classifier, embedded-file guard, CI dependency graph, prerelease range selection, and stable-release asset verification. The classifier passes all 40 self-test cases, the PR checks pass across Linux, Windows, and macOS, and the gate consistently fails open when it cannot prove a change is inert. I also checked the release demotion and downstream notification/Homebrew dependencies. I did not find a correctness blocker.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Solid PR overall — the design write-up and the ,glob trap section in particular are great, and the self-test/replay verification approach is exactly right.

One correctness bug worth fixing before merge, on the notify-discord/homebrew gate:

notify-discord:
  needs: [verify-assets]
  if: ${{ !inputs.prerelease }}

needs: changed from [release] to [verify-assets], but if: didn't change with it. GitHub Actions only applies an implicit success() check on needs when a job has no custom if: — the moment you add your own condition, that implicit gate is gone and you have to write the success check yourself:

"The success() function ... this status check function will cause a job to be skipped unless a previous job's status is success. It is recommended to use this expression whenever you use a custom condition alongside needs."
— GitHub Docs: Using conditions to control job execution

So as written, both jobs run as soon as verify-assets completes — success or failure — as long as !inputs.prerelease holds. Since verify-assets demotes a broken release via gh release edit --prerelease and then exits 1 (rather than flipping inputs.prerelease, which is just the original workflow input), the demotion doesn't stop either downstream job: Discord announces the release and Homebrew's formula gets updated pointing at assets that were just flagged incomplete — the exact scenario "Discord and the Homebrew tap wait on it" in the PR description says this prevents.

Fix:

if: ${{ !inputs.prerelease && needs.verify-assets.result == 'success' }}

on both notify-discord and homebrew.

(Rest of the review — duplicated merge-ref guard, hardcoded asset list in verify-assets, inconsistent diff ranges between the two security-job steps, changed-scope.sh reimplementing what dorny/paths-filter already does — are cleanup/simplification notes, not blockers.)

@KuSh
KuSh force-pushed the ci/path-filtering-189 branch 6 times, most recently from c26851c to ecada25 Compare August 31, 2026 23:12
@KuSh

KuSh commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks — two of the cleanup notes turned out to be worth more than the blocker, and both are now fixed in the PR. On the blocker itself I think the rule is the other way round, and I'd rather not add the condition.

The implicit success() is not removed by a custom if:

The quote is real, but it says the opposite of the reading. From Expressions → status check functions:

A default status check of success() is applied unless you include one of these functions.

"These functions" is the status-check set — success(), always(), cancelled(), failure(). What drops the default is including one of those, not writing a custom condition. jobs.<job_id>.needs says the same from the other side:

If a job fails or is skipped, all jobs that need it are skipped unless the jobs use a conditional expression that causes the job to continue.

and its worked example of such an expression is always().

if: ${{ !inputs.prerelease }} contains no status check function, so success() still applies and both jobs skip when verify-assets fails.

The strongest evidence is inside the PR. verify-assets is the job that does have to run on failure, and the only reason it can is the !cancelled():

verify-assets:
  needs: [release]
  if: ${{ !cancelled() && !inputs.prerelease }}

If a custom if: already removed the implicit success(), that !cancelled() would be dead weight — !inputs.prerelease alone would run it on a failed release. It isn't dead weight: without it the job is skipped exactly when a release is incomplete, which was a HIGH finding in an earlier round here. The two facts are one rule seen from both ends — !cancelled() on verify-assets is load-bearing because the plain if: downstream is sufficient.

So needs.verify-assets.result == 'success' would be a no-op: both checks would have to pass and the implicit one already does the work. I'd rather leave it out, because a redundant success check sitting beside a deliberate !cancelled() reads as if the implicit gate were unreliable — which is what would invite someone to "fix" verify-assets the same way and quietly break the demotion path.

Happy to be shown wrong by a run: if you can point at one where a job with needs and a status-function-free if: ran after its dependency failed, I'll take the change.

Diff ranges — you were right, and it was worse than inconsistent

Fixed in the PR. Measured on this PR's own merge ref: origin/master...HEAD resolved to 88 files against the PR's 10, because on a PR into develop it spans every merge since the last release. The critical-files scan was reporting

.github/workflows/stale.yml
Cargo.toml
src/core/tracking.rs
src/hooks/init.rs

as modified by this PR, which touches none of them, and then demanding "Manual security review by 2 maintainers". Misattribution rather than noise — and a scan that cries wolf every time is one people learn to click past.

All four scans now share one BASE_SHA resolved once. It is also target-aware, which the old range was not: on a PR into develop it is the PR alone, and on a PR into master it is the whole release delta. (On the last release PR the old range even pulled in the previous release's CHANGELOG.md and .release-please-manifest.json, since merge-base(master, develop) predates release-please's own commits on master.)

That surfaced a second thing: grep returns 1 on no-match, so each step needed || true, which also swallowed a failing git diff and turned a broken scan into "No dangerous patterns detected". Each scan now separates its git call from the grep, so git failure fails the step. Verified by running them with BASE_SHA unset — all four exit 128 instead of reporting clean.

Duplicated merge-ref guard — your note is what made it worth doing

I had this as not worth factoring: one line of plumbing across two jobs, with opposite responses. Fixing the diff ranges changed the arithmetic — four steps needed the same base — so it now lives once, in a Resolve the PR diff base step placed before the toolchain install so a broken assumption costs seconds rather than minutes. The shell scan lost its private copy.

Hardcoded asset list — deliberate, and now commented

Deriving want.txt from the build matrix would drop a vanished matrix entry from both sides of the comm, so the check would agree nothing was missing. The independence is the point. Adding a target only grows have, which is ignored, so it cannot cause a false demotion.

dorny/paths-filter

Considered and rejected in the design, for a reason specific to this use: a file matching no filter yields all filters false, so an unclassified new path reads as "nothing to build" and skips. The fail-safe direction is inverted from what this gate needs. changed-scope.sh subtracts an inert list instead, so anything unlisted builds — which is also why the classification lives in one file both workflows read rather than in either workflow.

@KuSh
KuSh force-pushed the ci/path-filtering-189 branch 2 times, most recently from e31dba6 to 51ad5d4 Compare September 17, 2026 22:50
@KuSh
KuSh force-pushed the ci/path-filtering-189 branch from 51ad5d4 to 46fcbd2 Compare October 9, 2026 23:31
@KuSh
KuSh force-pushed the ci/path-filtering-189 branch from 46fcbd2 to 76a574b Compare October 19, 2026 16:21
@KuSh
KuSh force-pushed the ci/path-filtering-189 branch 3 times, most recently from 14fa302 to 9fb9f6a Compare November 4, 2026 23:38
@KuSh
KuSh force-pushed the ci/path-filtering-189 branch from 9fb9f6a to 394691f Compare November 7, 2026 13:34
There was no path filtering anywhere in .github/. Every push to develop ran
pre-release plus the whole release build and published a dev-*-rc.N prerelease,
and every PR ran the whole CI matrix. Replaying the last 100 merges into
develop, 8 were pure markdown and paid for all of it.

.github/inert-paths.conf holds git pathspecs for the paths that cannot change
the binary or CI. changed-scope.sh subtracts them from a diff range and answers
through its exit status. Git does the matching, so there is no glob engine of
ours to get wrong.

No failure direction ships a stale artifact:

- The list is inverted, so an unrecognised path builds.
- The skip verdict is status 3, not 1, because bash hands out the low statuses
  itself -- 1 for a set -u violation or a failed command, 2 for a syntax error,
  127 for a missing one. An accident cannot be mistaken for a skip.
- Gated jobs skip only on an explicit build=false. A failed gate leaves that
  unset and ends the run red, with clippy and everything below it skipped, so it
  cannot wave a PR through green.
- --no-renames throughout: rename detection reports only a rename's
  destination, so moving an embedded file into docs/ would otherwise look inert
  on a commit that no longer compiles.

hooks/** is deliberately not excluded: src/hooks/init/ include_str!s files out
of hooks/, .md ones included. A bare :(exclude)*.md would swallow them,
because without `,glob` a pathspec `*` also matches `/`. check-embed-scope.sh
fails the build if that ever happens, and runs ungated so it still fires on the
docs-only PRs that skip everything else.

docs/ is listed piecemeal for the same reason: engine/tests/guide_examples.rs
and tests/agent_coverage_doc_test.rs embed the pages under
docs/guide/{pipelines,proxy,resources}/ to check their examples, so those
directories build and the rest of docs/ stays inert.

.claude/hooks/ stays a build input: tests/hook_decision_protocol_test.rs runs
.claude/hooks/rtk-rewrite.sh. The security job's pattern scan was Rust-only, so
it gains a shell scan.

check-embed-scope.sh splits each macro onto its own line before matching.
grep -o does not match overlapping windows, so the 80 characters trailing a
literal embed swallowed whichever embed followed it, and that one was dropped
as literal and never reported -- the exact concat!(env!(..)) form the guard
exists to catch was invisible whenever a plain include_str! preceded it.
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/x")), which engine/ uses for
its fixtures, is resolved against the nearest Cargo.toml and checked like a
literal; every other non-literal form is still reported.
It runs against fixtures through --self-test as well as against the tree.

pr-target-check.yml stops flagging release-please. Its only exemption was the
develop->master promotion, so release-please's own version-bump PR was labelled
wrong-base and told to target develop on every release since 0.37.1. Both
maintainer routes are now keyed by branch, because the account behind them is
not stable: the promotion has been opened by a human and by two different apps.
Replayed over the last 100 PRs into master, that flips 17 verdicts, all of them
release-please's, and exempts nothing else. Both exemptions are conditioned on
the branch living in this repo, because a fork's head branch name is the
contributor's to choose; every exempt route already satisfies that, so the
clause changes no verdict.

pr-target-check.yml also gains the matching base-branch filter. Its job only acts
on a PR into master, so every PR into develop was starting a run that skipped;
the last 20 runs did nothing. It also holds a pull-requests:write app token on
pull_request_target, so a run it cannot act on is exposure with no upside.

That job's three existing scans diffed origin/master...HEAD, which on a PR into
develop spans every merge since the last release rather than the PR. They now
diff HEAD^1 HEAD like the new shell scan, so they report the PR's own changes
instead of naming files the author never touched. Each scan also separates its
git call from the grep that needs `|| true` for a no-match, so a git failure
fails the step rather than passing as a clean verdict.

A manual dispatch of cd.yml always builds. Otherwise it diffs from the last RC
rather than from github.event.before: develop
runs are cancel-in-progress, and a docs push landing on a cancelled source
build would otherwise skip and strand that source change with no RC.
release.yml therefore uploads an RC as a draft and publishes it last, so the
tag only exists once every asset does.

The master path moves to its own workflow, stable-release.yml, and is not
gated. install.sh follows the redirect on /releases/latest and downloads that
tag's tarballs, so a stable release without assets breaks every fresh install;
a bug in the develop gate must not be able to cause that. release.yml gains a
verify-assets job that asserts all 27 assets uploaded non-empty and that
checksums.txt names nothing that failed to upload, demoting the release out of
/releases/latest if not, with Discord, the Homebrew tap and the winget manifest
waiting on it.

Fixes rtk-ai#189

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@KuSh
KuSh force-pushed the ci/path-filtering-189 branch from 394691f to 49e60cd Compare November 7, 2026 15:26
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.

Release pipeline should skip binary builds for non-code changes

3 participants