Repository navigation
Add submodule-aware changed-paths action - #11
Merged
Merged
Conversation
tj-actions/changed-files diffs the superproject with --ignore-submodules=all and only detects a submodule move by diffing inside the submodule, which fails silently when submodules are not checked out. A submodule-only bump then reads as "no code changed". changed-paths wraps changed-files and also diffs the gitlinks in the superproject, matching moved submodules against the same globs via git :(glob) pathspecs. It fails closed: an unresolvable range or unknown event reports changed=true. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Run git diff on its own and fail closed on any nonzero exit, so a git error can no longer read as "no match" through a pipeline. - Detect moved submodules from gitlink modes in `git diff --raw -z` instead of parsing .gitmodules: handles names with spaces, non-ASCII paths and gitlinks without a .gitmodules entry. NUL-separated output throughout. - Match micromatch more closely: wildcard-free patterns match only the exact path, the X/** -> X bridge is skipped when X's last segment has a `*`, and a positive `files` pattern after a `!` fails closed. - Fail closed on forced pushes, where changed-files diffs HEAD^..HEAD. - Sanitize the submodules output against newline forging. - Document the fail-closed events and the bash 4+ requirement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Drop a leading ./ from every pattern before building pathspecs, as picomatch does; the one-char-class rewrite otherwise kept it and git stopped normalising it, so `./sub` no longer matched gitlink `sub`. - Replace newlines/CR in every stdout line that carries a path or pattern, so a crafted gitlink name can't emit a workflow command. - Guard the possibly-empty pathspec array so `set -u` works on bash 4.0-4.3 as documented. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Purpose
Adds
.github/actions/changed-paths, a drop-in for thetj-actions/changed-files+any_modifiedpath gate that also notices submodule pointer moves. Nothing consumes it yet; consumers are not changed here.The bug
changed-files (v47.0.6,
9426d40) lists the superproject's changes withgit diff --name-status --ignore-submodules=all(getAllChangedFilesin itssrc/utils.ts), so a gitlink change is never reported as a path. It only finds submodule changes by diffing inside each submodule, which needs that submodule checked out with history for both commits. Path-gate jobs don't check out submodules, so that diff fails with warnings ("Unable to find merge base…", "Invalid revision range…"). Withfail_on_submodule_diff_error: falsethe path is then silently dropped, and a submodule-only bump looks like "no code changed". RediSearch/RediSearch#11759 is an inline stop-gap for this; this action is the reusable version of the same idea.Interface
Inputs:
files,files_ignore: passed to changed-files unchanged.base,head(optional): override the compare range for the submodule check.Outputs:
changed: changed-files'any_modified == 'true'OR a moved submodule matches the globs.submodules: space-separated matched submodule paths, for logs. A path containing a space is ambiguous here;changedis not affected.any_modified: changed-files' raw value.Requirements: the caller checks out with
fetch-depth: 0, the same requirement changed-files already has, and the job needs bash 4.0+ (checked on 4.0 and 4.3; a bare Alpine container has no bash). The action is inline bash only (nothing read fromgithub.action_path), needs no secrets, and all event values reach the script throughenv:.How it works
files/files_ignore.pull_requestmerge-base(base, head)..head;pushbefore..sha;merge_groupbase_sha..head_sha; overrides win.git -c core.quotePath=false diff --raw -z --no-renames --ignore-submodules=none <base> <head>, keeping entries where the old or new mode is 160000..gitmodules, it covers added and removed submodules, gitlinks with no.gitmodulesentry, names containing spaces, and non-ASCII paths.--ignore-submodules=noneoverrides a.gitmodulesignore = all.git diff --name-only -z … -- ':(glob)<files>'… ':(glob,exclude)<ignore>'…, then intersects with the moved list.Glob semantics
Patterns are built the way changed-files builds its micromatch list (
dot: true, noext: true): a trailing/becomes/**, a leading!excludes, and a leading./is dropped (as picomatch does). git and micromatch differ in two places, and the action bridges both:deps→[d]eps) so git also matches only the exact path. Without this,files_ignore: depswould wrongly dropdeps/X.X/**: micromatch also matchesXitself, unless the last segment ofXcontains a*other than**. The action adds anXpathspec only in that case, sodeps/*/**and*/**get no bridge.These cases have no faithful git equivalent. Each one counts every moved submodule as matching, with a warning:
|,\[!…](micromatch reads it differently from git)!!.or_filespattern after a!one (micromatch lets it re-include, git can't)Fails closed (deliberately)
The best-effort units in this repo never fail the job. This one fails closed instead, because for a skip-CI gate the safe failure is to run CI. The following each set
changed=truewith a::warning:::pull_request/push/merge_groupwithout both overrides, e.g.pull_request_target,workflow_dispatch,scheduleHEAD^..HEAD, notbefore..sha)before(a new branch's first push)Path bytes are untrusted. Newlines and CRs are replaced in every stdout line and output value that carries a path, and
changedis written last, so a crafted gitlink name can forge neither an output nor a workflow command.Migrating a consumer
Swap
uses: tj-actions/changed-files@…foruses: redislabsdev/redisearch-ci-common/.github/actions/changed-paths@v1, keepfiles/files_ignore, and readoutputs.changedinstead ofoutputs.any_modified. Dropfetch_additional_submodule_history: it's no longer needed.Local verification
changed-files itself can't run locally, so this checks only the new logic. A harness pulls the second step's
run:straight out ofaction.ymland runs it with the env a runner would set andANY_MODIFIED=false.Differential test. For 54
files/files_ignorecombinations, the harness compares the action'ssubmodulesoutput with micromatch 4 run through a port of changed-files'getFilePatterns. It uses two synthetic repos of gitlinks (no.gitmodules, apart from oneignore = allentry), including a space path, a non-ASCII path, a baredepsgitlink, and an added and a removed submodule. The cases include./sub,././sub,./deps/**,./**, andfiles_ignore: ./sub/././deps.{deps,src}/**,deps/[!R]*,src/**,!src/x/**,src/x/keep, andfiles_ignore: /sub(git exits 128).Real history:
deps/RediSearch-only bump (push and merge_group),**+ its 17-entry ignore listchanged=true submodules=deps/RediSearchdocs/**changed=falsefiles_ignore: deps/deps/*/**changed=true submodules=deps/RediSearchfiles_ignore: /subchanged=true+ warning (git exit 128)forced=truechanged=true+ warningdeps/VectorSimilarity-only), merge-base..head,check-codeglobschanged=true submodules=deps/VectorSimilaritycheck-testsglobschanged=falsechanged=false submodules=baseoverride, all-zerobefore, unreachable PR basechanged=true+ warningworkflow_dispatch/schedule/pull_request_targetchanged=true+ warningworkflow_dispatchwith both overrideschanged=true submodules=deps/VectorSimilarityevil\nchanged=falsesubmodules=evil?changed=false, thenchanged=truenl\n::warning::xnl?::warning::x; no stdout line starts with::files: ./deps/**on the bumpchanged=true submodules=deps/RediSearchfiles/files_ignoreunder bash 4.0 and 4.3 (set -u)changed=trueAlso: actionlint 1.7.7, the strict duplicate-key YAML check, and shellcheck of the extracted script are all clean.
🤖 Generated with Claude Code
Note
Medium Risk
New CI gate logic affects whether downstream jobs run; deliberate fail-closed behavior may increase CI runs on edge cases, but no existing workflows are wired to it in this PR.
Overview
Adds a new
changed-pathscomposite action that wraps SHA-pinnedtj-actions/changed-filesand extends path-based CI gating so submodule pointer moves (gitlink mode 160000) count as changes when they match the samefiles/files_ignoreglobs—fixing the case where submodule-only bumps are invisible because changed-files ignores superproject gitlinks and can't diff inside unchecked-out submodules.The bash step resolves compare ranges per event (
pull_request,push,merge_group, with optionalbase/headoverrides), detects moved gitlinks viagit diff --raw, and matches them using git:(glob)pathspecs with bridges for micromatch vs git semantics; untranslatable globs, git errors, forced pushes, and unknown events fail closed (changed=trueplus a warning). Outputs arechanged(OR ofany_modifiedand matching submodule moves),submodules, and passthroughany_modified. README documents the unit; no workflows consume it yet.Reviewed by Cursor Bugbot for commit 190499c. Bugbot is set up for automated code reviews on this repo. Configure here.