Skip to content

Add submodule-aware changed-paths action - #11

Merged
kei-nan merged 3 commits into
mainfrom
jk-changed-paths
Oct 4, 2026
Merged

kei-nan merged 3 commits into
mainfrom
jk-changed-paths

Conversation

@kei-nan

@kei-nan kei-nan commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Purpose

Adds .github/actions/changed-paths, a drop-in for the tj-actions/changed-files + any_modified path 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 with git diff --name-status --ignore-submodules=all (getAllChangedFiles in its src/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…"). With fail_on_submodule_diff_error: false the 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; changed is 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 from github.action_path), needs no secrets, and all event values reach the script through env:.

How it works

  1. Runs changed-files (SHA-pinned) with files / files_ignore.
  2. Resolves the range: pull_request merge-base(base, head)..head; push before..sha; merge_group base_sha..head_sha; overrides win.
  3. Lists the moved gitlinks with 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.
    • Because it reads modes, not .gitmodules, it covers added and removed submodules, gitlinks with no .gitmodules entry, names containing spaces, and non-ASCII paths.
    • --ignore-submodules=none overrides a .gitmodules ignore = all.
  4. Matches the moved gitlinks against the globs using git itself: git diff --name-only -z … -- ':(glob)<files>'… ':(glob,exclude)<ignore>'…, then intersects with the moved list.
    • Each git call runs on its own, and any nonzero exit fails closed.
    • There is no hand-rolled glob matching.

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:

  • Wildcard-free patterns: git prefix-matches a wildcard-free pathspec, while micromatch matches only that exact path. The action rewrites one character as a one-char class (deps → [d]eps) so git also matches only the exact path. Without this, files_ignore: deps would wrongly drop deps/X.
  • X/**: micromatch also matches X itself, unless the last segment of X contains a * other than **. The action adds an X pathspec only in that case, so deps/*/** and */** get no bridge.

These cases have no faithful git equivalent. Each one counts every moved submodule as matching, with a warning:

  • braces, parentheses, |, \
  • [!…] (micromatch reads it differently from git)
  • !!
  • a wildcard-free pattern with no ASCII letter, digit, . or _
  • a positive files pattern 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=true with a ::warning:::

  • any event other than pull_request / push / merge_group without both overrides, e.g. pull_request_target, workflow_dispatch, schedule
  • a forced push (changed-files then compares HEAD^..HEAD, not before..sha)
  • an all-zero before (a new branch's first push)
  • an unresolvable SHA or a missing merge base
  • any git error
  • an untranslatable glob

Path bytes are untrusted. Newlines and CRs are replaced in every stdout line and output value that carries a path, and changed is 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@… for uses: redislabsdev/redisearch-ci-common/.github/actions/changed-paths@v1, keep files / files_ignore, and read outputs.changed instead of outputs.any_modified. Drop fetch_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 of action.yml and runs it with the env a runner would set and ANY_MODIFIED=false.

Differential test. For 54 files / files_ignore combinations, the harness compares the action's submodules output with micromatch 4 run through a port of changed-files' getFilePatterns. It uses two synthetic repos of gitlinks (no .gitmodules, apart from one ignore = all entry), including a space path, a non-ASCII path, a bare deps gitlink, and an added and a removed submodule. The cases include ./sub, ././sub, ./deps/**, ./**, and files_ignore: ./sub / ././deps.

  • 50 EQUAL, 4 fail closed (intended), 0 mismatches.
  • The fail-closed four: {deps,src}/**, deps/[!R]*, src/**,!src/x/**,src/x/keep, and files_ignore: /sub (git exits 128).

Real history:

Case Result
Downstream deps/RediSearch-only bump (push and merge_group), ** + its 17-entry ignore list changed=true submodules=deps/RediSearch
same range, docs/** changed=false
same range, files_ignore: deps / deps/*/** changed=true submodules=deps/RediSearch
same range, files_ignore: /sub changed=true + warning (git exit 128)
same range, forced=true changed=true + warning
RediSearch PR #10646 (deps/VectorSimilarity-only), merge-base..head, check-code globs changed=true submodules=deps/VectorSimilarity
same PR, check-tests globs changed=false
code-only commits (both repos) changed=false submodules=
bad base override, all-zero before, unreachable PR base changed=true + warning
workflow_dispatch / schedule / pull_request_target changed=true + warning
workflow_dispatch with both overrides changed=true submodules=deps/VectorSimilarity
gitlink named evil\nchanged=false submodules=evil?changed=false, then changed=true
gitlink named nl\n::warning::x logged as nl?::warning::x; no stdout line starts with ::
files: ./deps/** on the bump changed=true submodules=deps/RediSearch
empty files / files_ignore under bash 4.0 and 4.3 (set -u) runs, changed=true

Also: 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-paths composite action that wraps SHA-pinned tj-actions/changed-files and extends path-based CI gating so submodule pointer moves (gitlink mode 160000) count as changes when they match the same files / files_ignore globs—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 optional base/head overrides), detects moved gitlinks via git 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=true plus a warning). Outputs are changed (OR of any_modified and matching submodule moves), submodules, and passthrough any_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.

kei-nan and others added 3 commits October 4, 2026 17:34
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>
@kei-nan
kei-nan merged commit 57d84e8 into main Oct 4, 2026
2 checks passed
@kei-nan
kei-nan deleted the jk-changed-paths branch October 5, 2026 15:33
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