Skip to content

ci(harness): shellcheck the actions' run: scripts and scripts/*.sh in the gate (#100) - #266

Merged
mmcky merged 3 commits into
mainfrom
ci/100-shellcheck-run-scripts
Nov 6, 2026
Merged

mmcky merged 3 commits into
mainfrom
ci/100-shellcheck-run-scripts

Conversation

@mmcky

@mmcky mmcky commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

This builds on #265 (merged as ea01c01), which moved every ${{ }} in the actions' run: scripts into env:. It was stacked on #265, and is now rebased onto main at 8c12d4f, after #268 (#236).

actionlint lints a workflow's run: scripts, and since #264 the gate runs it over .github/workflows/. But it never reads an action.yml, so the 56 run: scripts in the eight actions, which are what lecture repositories actually run, had no static check at all. This is the second of the two checks in #100's M5 comment. A new scripts/lint-shell.py shellchecks each action's run: scripts at --severity=warning, reporting each finding at its line in the action.yml. Then it shellchecks scripts/*.sh at the same severity. It also fails on any ${{ }} in a run: script, whether an action's or a workflow's. #265 moved every one in the actions into env:, and the six workflows' run: scripts had none. So from here on AGENTS.md's rule ("Pass values to run: scripts through env:") is enforced, not just written down.

How it works

Part What it does
Finding the scripts Every */action.yml, read with PyYAML (yaml.compose, so each node keeps its position), then each step of runs.steps that has a run:. 56 scripts on #265's branch
${{ Any ${{ in a run: script fails, at its line and column, with "Pass the value through the step's env: and read it as "$NAME"". No placeholder: #265 leaves none by design. A script that holds one isn't shellchecked until it's gone, since shellcheck can't parse the expression
Shell shell: bash (also bash -l {0}) is linted as bash, and sh as POSIX sh. Any other shell fails, rather than go unchecked: keep that code in a file that bash runs, as build-lectures does with check-error-outputs.py. None exists today
shellcheck One run per dialect over every script, with --norc --severity=warning --format=json1. --norc keeps a contributor's ~/.shellcheckrc from changing what it reports
Positions A run: | block starts on the line after the indicator, at the block's indent, so every finding lands on its own line and column in action.yml. A one-line plain run: maps exactly too. A quoted or folded one, where quotes and folding move the text, is reported at its start. None of the 56 is quoted or folded
Workflows Each step's run: in .github/workflows/*.yml, 133 today, is checked for ${{ alone, with the same message and positions. It isn't shellchecked here, because actionlint, the step before, does that. The organiser asked for this once the first version had shown the workflows had no violations
scripts/*.sh The 9 files, shellchecked as their shebang's dialect, at the same severity
Output path:line:col: SC<code> (<level>): <message>. In Actions, each is an ::error file=…,line=…,col=…:: annotation, so it shows on the diff
Version It prints the shellcheck version it ran. The gate's install step also logs it (#264)

A finding that is wrong for one command takes # shellcheck disable=SC<code> # <reason> on the line before it, in a run: script just as in a file. #264 used the same form in the workflows.

Severity: warning

As the brief and the M5 comment set it. On #265's branch, at warning, there is nothing to fix. At shellcheck's default severity, issue228 found eight info-level findings in steps #265 doesn't otherwise touch. Six are unquoted >> $GITHUB_OUTPUT (SC2086). One is build-lectures' deliberately split $EXTRA_ARGS (SC2086). The last is sed -e '$a\' (SC1003, a false positive). None fails at warning, so I asked issue228 to leave them, and #265 stays limited to its steps. Moving to info later would mean quoting the six and adding two directives.

Changes

File Change
scripts/lint-shell.py New. The check, as above
.github/workflows/test-actions.yml A gate step, "Lint the actions' run scripts and scripts/*.sh with shellcheck", after #264's actionlint step. It uses the gate's venv (PyYAML) and the runner's shellcheck, which #264's install step already requires. scripts/lint-shell.py joins IGNORED, and the self-test's list of paths it must keep ignoring, beside generate-docs.py (see below)
docs/dev/TESTING.md The gate's checks gain the shell lint; "Locally" gains python3 scripts/lint-shell.py
AGENTS.md "Checks to run before a pull request" gains python3 scripts/lint-shell.py
CONTRIBUTING.md The CI section names the shell lint, and the ${{ }} rule it enforces in actions and workflows
CHANGELOG.md One entry under Unreleased, Added, CI, after #264's

IGNORED. No harness job runs scripts/lint-shell.py: only the gate does, so a change to it alone runs the gate, whose own step is its test, and skips the rest. That's the reason the gate's comment gives for generate-docs.py and requirements.txt, and the comment now names the shell lint too. The self-test asserts that IGNORED keeps matching it. Nothing that exists today runs any differently.

What I checked

  • The premises, on 9407085 and 7f50cd7. 55 run: blocks in the eight actions on main (the M5 comment said 50), and 56 on fix: pass every value to the actions' run: scripts through env: (#228) #265's branch. There are 9 scripts/*.sh, not 10: the other files in scripts/ are generate-docs.py, preview-comment.cjs and requirements.txt. On fix: pass every value to the actions' run: scripts through env: (#228) #265's branch the shells are bash (53) and bash -l {0} (3), and the scalars are 49 literal blocks and 7 one-line plain values: none quoted, folded or plain over several lines.
  • On main, the check fails as it should: exactly 58 ${{ findings, the count issue228 found, all in build-jupyter-cache, build-lectures, publish-gh-pages, restore-jupyter-cache and setup-environment. The 43 scripts without one, and the 9 scripts/*.sh, are clean at warning.
  • fix(restore-jupyter-cache): refuse values outside each input's accepted set, and an empty path (#236) #268's restore-jupyter-cache changes, which merged ahead of this PR: the rewritten input checks pass at warning, with no ${{, so this check needs no change there.
  • On this branch, on 8c12d4f: python3 scripts/lint-shell.py reports 56 run: scripts in the actions, 133 in the workflows (fix(restore-jupyter-cache): refuse values outside each input's accepted set, and an empty path (#236) #268 added two harness steps) and 9 scripts/*.sh, clean. actionlint and generate-docs.py --check --check-examples --actionlint are clean too.
  • Positions, against a scratch action.yml with each case: a literal block (SC2034 at 10:9), a one-line plain run: (SC2046 at 16:17), a ${{ in a block (20:15), a folded block (reported at the >), shell: python (refused), shell: sh (SC3010, POSIX), a # shellcheck disable directive (honoured), and a scripts/*.sh (SC2045). For the workflows, a scratch workflow had a ${{ in a run: | block (14:17), one in a plain run: (16:19), one in env: (accepted, as it should be), and a reusable-workflow job with no steps (skipped). Each line and column checked by hand against the file. On main I also checked four of the 58 ${{ positions by hand: each lands on the $.
  • The check can fail in CI. A throwaway branch, ci/100-shellcheck-demo, put this branch plus three plants: echo "…${{ github.run_id }}" in a setup-environment block, an unquoted $(date) in a publish-gh-pages block, and for f in $(ls) at the end of scripts/check-latex-versions.sh. I dispatched the harness on it so the red wouldn't land here: run 42203241420. The gate failed at the new step with exactly those three, each also an annotation at its line and column: setup-environment/action.yml:88:40 (the ${{), publish-gh-pages/action.yml:94:49 (SC2046, warning) and scripts/check-latex-versions.sh:46:10 (SC2045, error). Action harness: all checks failed with it. A second branch, ci/100-shellcheck-demo2, tested the workflow rule. It planted only echo "…${{ github.run_id }}" in a check-latex-versions.yml step, which actionlint passes. In run 42203828010 the gate failed at the new step with the one annotation .github/workflows/check-latex-versions.yml:24:42. Both branches are deleted.
  • The tools. shellcheck 0.11.0 locally, from shellcheck-py in a scratch venv. CI's runner, ubuntu-26.04 under ubuntu-latest, logs ShellCheck 0.11.0 too (ci(harness): lint .github/workflows/ with actionlint in the gate (#100) #264's demo run), so the two agree.
  • containers/ is left out, as the brief says: a change there rebuilds both images. Its two scripts, containers/quantecon/tests/smoke-test.sh and run-local-tests.sh, are clean at warning. At default severity they have one SC2012 and one SC2016, both info, for whenever someone next changes them.

What to watch after merge

  • Any PR that edits an action's run: script now has to pass shellcheck at warning and use env: for every value. The annotation points at the line in action.yml.
  • A newer shellcheck on the runner can report findings that 0.11.0 doesn't. The gate logs the version, so a new red with no code change can be traced to an image update.
  • No action changes, so nothing for the canary or a staged release.

Not in this PR

  • The eight info-level findings listed above, which pass at warning.
  • containers/' two scripts, clean at warning, as above.

Part of #100.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 6, 2026 10:32
Base automatically changed from fix/228-run-script-expressions to main November 6, 2026 10:35
@mmcky
mmcky force-pushed the ci/100-shellcheck-run-scripts branch from 39b037b to 4da1b62 Compare November 6, 2026 10:35

Copilot AI 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.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

Indent detection for literal-block run scripts in scripts/lint-shell.py can miscompute indentation when the block starts with blank lines or is empty, leading to incorrect action.yml line/column mapping for shellcheck findings.

1 open issue
What changed in this PR

This pull request adds a CI gate check to ShellCheck composite actions’ run: scripts (from */action.yml) and scripts/*.sh, and enforces the repository rule that ${{ }} expressions must not appear inside action run: blocks.

Changes:

  • Add scripts/lint-shell.py to extract and lint action run: scripts, fail on ${{ }} in those scripts, and ShellCheck scripts/*.sh (warning severity) with file/line/col mapping back to source.
  • Run the new lint in the harness gate (.github/workflows/test-actions.yml) and update the gate’s ignore/self-test expectations accordingly.
  • Document the new check in developer/contributor docs and record it in the changelog.

Open review comments to address:

  • scripts/lint-shell.py: literal-block indent detection may scan beyond the scalar when the block starts with blanks/is empty, causing incorrect line/column mapping for findings. (moderate)
  • scripts/lint-shell.py: handle yaml.compose() parse errors more gracefully (emit a clean, annotated error instead of a traceback). (nit)
File Summary
scripts/​lint-shell.py New linter that parses composite actions’ run: blocks and lints them (and scripts/*.sh) with ShellCheck, including source mapping and ${{ }} enforcement.
docs/​dev/​TESTING.md Documents the new gate check and how to run it locally.
CONTRIBUTING.md Updates CI guidance to include the new shell lint and the ${{ }} restriction in action run: scripts.
CHANGELOG.md Adds an Unreleased CI entry for the new shell lint check.
AGENTS.md Adds python3 scripts/lint-shell.py to the recommended pre-PR checks.
.github/​workflows/​test-actions.yml Adds a gate step to run the new shell lint and updates related ignore/self-test expectations.

This pull request requires changes.

Review effort: Balanced

Comment thread scripts/lint-shell.py Outdated
Comment on lines +76 to +78
body = text.splitlines()[mark.line + 1:]
first = next((s for s in body if s.strip()), "")
self.indent = len(first) - len(first.lstrip(" "))

@mmcky mmcky Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 004a5ab. You're right that the scan wasn't bounded by the block. For an empty or blank-only run: |, the first non-blank line after the | belongs to the next key, so the indent came out wrong. No finding can come from such a block, so no report was wrong, but the mapping was.

The script now finds the block's first non-blank line in the scalar's own value, and takes the indent from that line of the file. An empty block gets 0. I tried bounding the scan by the scalar's end_mark first, but that breaks a block at the end of a file with no final newline, where the end mark sits on the last content line. Checked against five cases: an empty block, a blank-only block, a leading blank line, the last block in a file with no newline, and a deeper second line. The previous code failed the first two, and the bounded scan failed the fourth. On 9407085's tree, all 58 ${{ positions are identical before and after, and the scratch fixture's positions are unchanged.

The overview also suggests catching yaml.compose() errors. I've left that: generate-docs.py --check, two steps earlier in the gate, loads every action.yml the same way, so a malformed one fails there first, and actionlint, the step just before, does the same for a workflow.

Claude Code (on behalf of mmcky)

mmcky added a commit that referenced this pull request Nov 6, 2026
Script took a literal block's indent from the first non-blank line
after the | indicator, scanning on through the rest of the file. For
an empty or blank-only block, that line belongs to the next key, so
the indent came out wrong (Copilot's review on #266). No finding can
come from such a block, so no report was wrong, but the mapping would
have been.

It now finds the block's first non-blank line in the scalar's own
value, and takes the indent from that line in the file. An empty
block gets 0. Unlike bounding the scan by the scalar's end mark, this
also holds for a block at the end of a file with no final newline.
On 9407085's tree, the 58 expression positions are identical before
and after.

Part of #100.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMYUdoizTYHvPmmUUN2
mmcky and others added 3 commits November 6, 2026 21:46
… the gate

actionlint lints a workflow's run: scripts but never reads an
action.yml, so the run: scripts in the eight actions, 56 with #228, had no static
check (#100, review M5). scripts/lint-shell.py reads every
*/action.yml with PyYAML and runs shellcheck at --severity=warning on
each run: script whose shell is bash or sh, reporting each finding at
its line and column in action.yml (as an annotation in Actions). Then
it runs shellcheck on scripts/*.sh at the same severity.

It fails on any ${{ in an action's run: script, instead of masking it
with a placeholder: #228 moved every expression into env:, so this
holds AGENTS.md's rule from here on. A step whose shell it cannot lint
fails too, rather than go unchecked.

The gate runs it after the actionlint step. The script is on the
gate's IGNORED list beside generate-docs.py, since no harness job uses
it and the gate's own step is its test. containers/ is left out: a
change there rebuilds both images.

Part of #100.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMYUdoizTYHvPmmUUN2
AGENTS.md's rule, "Pass values to run: scripts through env:", covers
every run: script, and none of the six workflows' 131 has a ${{ }}
today. scripts/lint-shell.py now checks them for it as well, with the
same message and positions as for the actions, so a new one fails the
gate. It doesn't shellcheck them: actionlint, the step before, does.

Part of #100.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMYUdoizTYHvPmmUUN2
Script took a literal block's indent from the first non-blank line
after the | indicator, scanning on through the rest of the file. For
an empty or blank-only block, that line belongs to the next key, so
the indent came out wrong (Copilot's review on #266). No finding can
come from such a block, so no report was wrong, but the mapping would
have been.

It now finds the block's first non-blank line in the scalar's own
value, and takes the indent from that line in the file. An empty
block gets 0. Unlike bounding the scan by the scalar's end mark, this
also holds for a block at the end of a file with no final newline.
On 9407085's tree, the 58 expression positions are identical before
and after.

Part of #100.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMYUdoizTYHvPmmUUN2
@mmcky
mmcky force-pushed the ci/100-shellcheck-run-scripts branch from 004a5ab to 65ef0c8 Compare November 6, 2026 10:46
@mmcky
mmcky merged commit 19890f8 into main Nov 6, 2026
54 checks passed
@mmcky
mmcky deleted the ci/100-shellcheck-run-scripts branch November 6, 2026 10:53
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.

2 participants