Repository navigation
ci(harness): shellcheck the actions' run: scripts and scripts/*.sh in the gate (#100) - #266
Conversation
39b037b to
4da1b62
Compare
There was a problem hiding this comment.
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.pyto extract and lint actionrun:scripts, fail on${{ }}in those scripts, and ShellCheckscripts/*.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: handleyaml.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
| body = text.splitlines()[mark.line + 1:] | ||
| first = next((s for s in body if s.strip()), "") | ||
| self.indent = len(first) - len(first.lstrip(" ")) |
There was a problem hiding this comment.
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)
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
… 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
004a5ab to
65ef0c8
Compare

This builds on #265 (merged as
ea01c01), which moved every${{ }}in the actions'run:scripts intoenv:. It was stacked on #265, and is now rebased ontomainat8c12d4f, after #268 (#236).actionlint lints a workflow's
run:scripts, and since #264 the gate runs it over.github/workflows/. But it never reads anaction.yml, so the 56run: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 newscripts/lint-shell.pyshellchecks each action'srun:scripts at--severity=warning, reporting each finding at its line in theaction.yml. Then it shellchecksscripts/*.shat the same severity. It also fails on any${{ }}in arun:script, whether an action's or a workflow's. #265 moved every one in the actions intoenv:, and the six workflows'run:scripts had none. So from here on AGENTS.md's rule ("Pass values torun:scripts throughenv:") is enforced, not just written down.How it works
*/action.yml, read with PyYAML (yaml.compose, so each node keeps its position), then each step ofruns.stepsthat has arun:. 56 scripts on #265's branch${{${{in arun: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 expressionshell: bash(alsobash -l {0}) is linted as bash, andshas POSIX sh. Any other shell fails, rather than go unchecked: keep that code in a file that bash runs, asbuild-lecturesdoes withcheck-error-outputs.py. None exists today--norc --severity=warning --format=json1.--norckeeps a contributor's~/.shellcheckrcfrom changing what it reportsrun: |block starts on the line after the indicator, at the block's indent, so every finding lands on its own line and column inaction.yml. A one-line plainrun: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 foldedrun: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 violationsscripts/*.shpath:line:col: SC<code> (<level>): <message>. In Actions, each is an::error file=…,line=…,col=…::annotation, so it shows on the diffA finding that is wrong for one command takes
# shellcheck disable=SC<code> # <reason>on the line before it, in arun: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 isbuild-lectures' deliberately split$EXTRA_ARGS(SC2086). The last issed -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
scripts/lint-shell.py.github/workflows/test-actions.ymlscripts/lint-shell.pyjoinsIGNORED, and the self-test's list of paths it must keep ignoring, besidegenerate-docs.py(see below)docs/dev/TESTING.mdpython3 scripts/lint-shell.pyAGENTS.mdpython3 scripts/lint-shell.pyCONTRIBUTING.md${{ }}rule it enforces in actions and workflowsCHANGELOG.mdIGNORED. No harness job runsscripts/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 forgenerate-docs.pyandrequirements.txt, and the comment now names the shell lint too. The self-test asserts thatIGNOREDkeeps matching it. Nothing that exists today runs any differently.What I checked
9407085and7f50cd7. 55run:blocks in the eight actions onmain(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 9scripts/*.sh, not 10: the other files inscripts/aregenerate-docs.py,preview-comment.cjsandrequirements.txt. On fix: pass every value to the actions' run: scripts through env: (#228) #265's branch the shells arebash(53) andbash -l {0}(3), and the scalars are 49 literal blocks and 7 one-line plain values: none quoted, folded or plain over several lines.main, the check fails as it should: exactly 58${{findings, the count issue228 found, all inbuild-jupyter-cache,build-lectures,publish-gh-pages,restore-jupyter-cacheandsetup-environment. The 43 scripts without one, and the 9scripts/*.sh, are clean at warning.restore-jupyter-cachechanges, which merged ahead of this PR: the rewritten input checks pass at warning, with no${{, so this check needs no change there.8c12d4f:python3 scripts/lint-shell.pyreports 56run: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 9scripts/*.sh, clean.actionlintandgenerate-docs.py --check --check-examples --actionlintare clean too.action.ymlwith each case: a literal block (SC2034 at10:9), a one-line plainrun:(SC2046 at16:17), a${{in a block (20:15), a folded block (reported at the>),shell: python(refused),shell: sh(SC3010, POSIX), a# shellcheck disabledirective (honoured), and ascripts/*.sh(SC2045). For the workflows, a scratch workflow had a${{in arun: |block (14:17), one in a plainrun:(16:19), one inenv:(accepted, as it should be), and a reusable-workflow job with no steps (skipped). Each line and column checked by hand against the file. OnmainI also checked four of the 58${{positions by hand: each lands on the$.ci/100-shellcheck-demo, put this branch plus three plants:echo "…${{ github.run_id }}"in asetup-environmentblock, an unquoted$(date)in apublish-gh-pagesblock, andfor f in $(ls)at the end ofscripts/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) andscripts/check-latex-versions.sh:46:10(SC2045, error).Action harness: all checksfailed with it. A second branch,ci/100-shellcheck-demo2, tested the workflow rule. It planted onlyecho "…${{ github.run_id }}"in acheck-latex-versions.ymlstep, 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.shellcheck-pyin a scratch venv. CI's runner,ubuntu-26.04underubuntu-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.shandrun-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
run:script now has to pass shellcheck at warning and useenv:for every value. The annotation points at the line inaction.yml.Not in this PR
containers/' two scripts, clean at warning, as above.Part of #100.
🤖 Generated with Claude Code