Skip to content

Commit eecda89

Browse files
authored
Lint the action's run body with the pinned shellcheck (#5)
ci.yml checks the .sh files with a digest-pinned shellcheck, while tests/lint-action.sh checked the extracted run: body with whatever shellcheck the runner had. The script now writes the body inside the checkout and takes the checker from $SHELLCHECK, as action-debian-build's shellcheck-composite.py does, and CI points that at the same pinned image. Unset, it is plain shellcheck, so local runs are unchanged. Checked locally through the container: the current body passes, and a seeded unquoted expansion fails with SC2086.
1 parent b5086e9 commit eecda89

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
commit-branch.sh tests/*.sh
3636
3737
- name: Lint the action metadata and its inline shell
38+
env:
39+
SHELLCHECK: >-
40+
docker run --rm --volume ${{ github.workspace }}:/repo --workdir /repo
41+
koalaman/shellcheck@sha256:61862eba1fcf09a484ebcc6feea46f1782532571a34ed51fedf90dd25f925a8d
3842
run: tests/lint-action.sh
3943

4044
- name: Test

‎tests/lint-action.sh‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ shopt -s inherit_errexit
1717
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
1818
cd "$ROOT"
1919

20-
body="$(mktemp)"
20+
# Inside the checkout, so the containerised checker CI uses can see it;
21+
# prefixed, so a killed run's leftover names itself in git status.
22+
body="$(mktemp -p . .lint-action-body.XXXXXX)"
2123
trap 'rm -f "$body"' EXIT
2224

2325
python3 - "$body" <<'PY'
@@ -85,6 +87,9 @@ with open(sys.argv[1], "w") as out:
8587
print(" ok action.yml parses, one bash step, every input piped, no inline expressions")
8688
PY
8789

90+
# $SHELLCHECK selects the checker. CI points it at the digest-pinned container
91+
# the .sh files go through, so one version judges every line of shell here.
92+
read -ra shellcheck <<< "${SHELLCHECK:-shellcheck}"
8893
# SC2154: the variables come from the step's env:, which shellcheck cannot see.
89-
shellcheck -S style -e SC2154 "$body"
94+
"${shellcheck[@]}" -S style -e SC2154 "$body"
9095
echo " ok the run body is shellcheck-clean"

0 commit comments

Comments
 (0)