From dc3def82bc40bc0a5aa5031b270cf761b8f4760d Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Thu, 30 Jul 2026 09:06:11 -0400 Subject: [PATCH] fix(scripts): resolve composite shell dialect by basename, not bare name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Decision (option 2 of the issue's three, per triage's default): exceed actionlint's own shell-dialect resolution rather than mirror it exactly. actionlint's rule_shellcheck.go resolves a custom shell by its literal leading word, so a path-qualified custom shell (`shell: /usr/bin/bash --noprofile {0}`, which GitHub documents and runs as bash) falls through actionlint's own check unanalysed — and composite-run-shellcheck.sh, which exists specifically to judge a composite step under the same contract actionlint applies to a workflow step, inherited that same gap. composite-run-shellcheck.sh now resolves the leading command's BASENAME (strip to the first whitespace-delimited word, then to what follows the last `/`) instead of matching the bare name/word only, so a path-qualified shell of either dialect is classified and checked rather than silently skipped. The `expected` yq guard's regex was updated in lockstep (`^([^ ]*/)?(bash|sh)( |$)`) so the independent-count guard doesn't itself fire on every path-qualified shell. The header restates the check's invariant as "at least as strictly as actionlint", not "identically" — this is a deliberate, documented divergence. fixtures/composite-action/custom-shell/action.yml gains a path-qualified bash step; the test suite asserts it is checked (not skipped) and bumps the checked-block count from three to four. Fixes #264 Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01RhS3T7ShwJgKTrvk2Mvd3C --- .github/scripts/composite-run-shellcheck.sh | 49 +++++++++++++------ .../scripts/composite-run-shellcheck.test.sh | 10 +++- .../composite-action/custom-shell/action.yml | 16 ++++-- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/.github/scripts/composite-run-shellcheck.sh b/.github/scripts/composite-run-shellcheck.sh index 5579d3a1..147bd278 100644 --- a/.github/scripts/composite-run-shellcheck.sh +++ b/.github/scripts/composite-run-shellcheck.sh @@ -10,7 +10,16 @@ # # This extracts each bash/sh `run:` block and hands it to ShellCheck under the # same contract actionlint applies to workflow `run:` blocks, so a step is -# judged identically whether it lives in a workflow or a composite. It also +# judged AT LEAST AS STRICTLY whether it lives in a workflow or a composite — +# not merely identically. actionlint's own dialect resolution (rule_shellcheck +# .go) matches only a bare "bash"/"sh" or its literal leading word in GitHub's +# custom-shell form ("bash [options] {0}"), so a path-qualified custom shell +# (`shell: /usr/bin/bash --noprofile {0}`, which GitHub documents and runs as +# bash) falls through actionlint's own check unanalysed. This check resolves +# by the leading command's BASENAME instead, so a path-qualified shell of +# either dialect is analysed here too rather than silently skipped as it is +# upstream — a composite step is therefore never LESS covered than the +# identical workflow step would be, only ever equally or more so. It also # makes the in-place `# shellcheck disable=` directives those blocks already # carry take effect. # @@ -173,9 +182,14 @@ for file in "${files[@]}"; do # Counted with an expression independent of the extraction query below, so a # selector that silently matches nothing is caught rather than passing as a - # zero-block success — the false green this check exists to prevent. + # zero-block success — the false green this check exists to prevent. The + # regex resolves the same basename the case below does — an optional + # slash-terminated path prefix, then a bare "bash"/"sh" followed by a space + # or end-of-string — so the two selectors must stay in lockstep; letting + # them drift would make this guard fire on every path-qualified shell + # instead of only on a genuine selector regression. expected="$(yq -r \ - '[.runs.steps[] | select(has("run")) | select((.shell // "") | test("^(bash|sh)( |$)"))] | length' \ + '[.runs.steps[] | select(has("run")) | select((.shell // "") | test("^([^ ]*/)?(bash|sh)( |$)"))] | length' \ "$file")" produced=0 @@ -192,20 +206,27 @@ for file in "${files[@]}"; do exit 1 fi - # actionlint's own dialect resolution (rule_shellcheck.go): the bare names, - # plus GitHub's custom-shell form `command [...options] {0}`, whose dialect - # is the leading command word. Matching only the bare names would leave a - # block GitHub runs with bash unchecked while the job stayed green — the + # DELIBERATELY exceeds actionlint's own dialect resolution + # (rule_shellcheck.go), which matches only a bare name or its literal + # leading word in GitHub's custom-shell form (`command [...options] {0}`). + # This resolves by the leading command's BASENAME instead, so a + # path-qualified custom shell (`shell: /usr/bin/bash --noprofile {0}`, + # which GitHub documents and runs as bash) is classified too, rather than + # silently skipped as it is upstream — narrower coverage would leave a + # block GitHub runs with bash/sh unchecked while the job stayed green, the # coverage hole this check exists to close. Only the case sees the raw - # scalar; everything downstream uses the resolved dialect, so no option text - # reaches a filename. - case "$shell" in - bash | 'bash '*) dialect='bash' ;; - sh | 'sh '*) dialect='sh' ;; - '') + # scalar; everything downstream uses the resolved dialect, so no option + # text reaches a filename. Parameter expansion (not `basename`) to avoid a + # subprocess per step. + if [[ -z "$shell" ]]; then echo "::error file=$file::composite-run-shellcheck: runs.steps[$index] has a run: block with no shell:; refusing to guess the dialect." exit 1 - ;; + fi + leading="${shell%% *}" + leading="${leading##*/}" + case "$leading" in + bash) dialect='bash' ;; + sh) dialect='sh' ;; *) printf 'skip %s runs.steps[%s]: shell is %s, not bash/sh\n' "$file" "$index" "$shell" continue diff --git a/.github/scripts/composite-run-shellcheck.test.sh b/.github/scripts/composite-run-shellcheck.test.sh index ddc0cfb3..f384b346 100644 --- a/.github/scripts/composite-run-shellcheck.test.sh +++ b/.github/scripts/composite-run-shellcheck.test.sh @@ -88,8 +88,14 @@ cat -- "$custom" grep -F 'runs.steps[1] (shell: bash)' "$custom" grep -F 'runs.steps[2] (shell: sh)' "$custom" grep -F 'runs.steps[3]: shell is pwsh, not bash/sh' "$custom" -if [[ "$(grep -c '^check fixtures/composite-action/custom-shell/' "$custom")" -ne 3 ]]; then - echo 'Expected exactly three checked blocks in the custom-shell fixture.' >&2 +# A PATH-QUALIFIED custom shell (`/usr/bin/bash --noprofile {0}`) is run as +# bash too, but its leading word is the full path, not the bare name — the +# selector must resolve by the leading command's basename, one step further +# than actionlint's own bare-name/leading-word resolution, or this step falls +# to the same silent skip a path-qualified shell gets upstream. +grep -F 'runs.steps[4] (shell: bash)' "$custom" +if [[ "$(grep -c '^check fixtures/composite-action/custom-shell/' "$custom")" -ne 4 ]]; then + echo 'Expected exactly four checked blocks in the custom-shell fixture.' >&2 exit 1 fi diff --git a/fixtures/composite-action/custom-shell/action.yml b/fixtures/composite-action/custom-shell/action.yml index ed7b31c5..8fea0754 100644 --- a/fixtures/composite-action/custom-shell/action.yml +++ b/fixtures/composite-action/custom-shell/action.yml @@ -2,11 +2,13 @@ name: custom-shell-composite description: >- Every shell shape the selector must classify, in one file: the two bare names, GitHub's custom-shell form (`command [...options] {0}`) for each of - them, and a dialect ShellCheck cannot read. The custom forms are the point — - GitHub runs them with bash and sh, so an exact-name selector would skip them - while the job stayed green. composite-run-shellcheck.test.sh asserts the two - custom forms are checked rather than skipped, and that the independent block - count agrees with what extraction produced. + them, a PATH-QUALIFIED custom shell, and a dialect ShellCheck cannot read. + The custom and path-qualified forms are the point — GitHub runs all of them + with bash or sh, so a selector matching only the bare name (actionlint's own + behaviour) would skip them while the job stayed green. + composite-run-shellcheck.test.sh asserts every non-pwsh form here is checked + rather than skipped, and that the independent block count agrees with what + extraction produced. runs: using: composite @@ -26,3 +28,7 @@ runs: - name: Not a shell ShellCheck handles shell: pwsh run: Write-Output 'skipped out loud' + + - name: Path-qualified bash + shell: /usr/bin/bash --noprofile --norc -eo pipefail {0} + run: echo 'path-qualified bash'