GitHub Action that fails when shell scripts use syntax the Bash shipped with macOS cannot run. That Bash is 3.2.
bash -n on Bash 3.2 still accepts some Bash 4 commands, because names such as mapfile look like ordinary commands. This action rejects those tokens, then parses every selected script with Bash 3.2.
- uses: actions/checkout@v4
- uses: hellosign/bash32-action@v1
with:
paths: |
bin/**
scripts/**/*.shpaths is newline-separated globs relative to the repository root. A file is checked when its shebang contains bash. Other files matched by a glob, including sh and PHP scripts, are skipped. Each glob must match at least one Bash script.
The runner needs Docker. GitHub-hosted runners already have it.
| Name | Description | Default |
|---|---|---|
paths |
Newline-separated globs of files to consider. | Required |
bash-image |
Docker image that provides Bash 3.2. | bash:3.2 |
Bash 4 and newer syntax that bash -n does not catch on Bash 3.2:
mapfileandreadarraydeclare -Acoproc[[ -v${var^^},${var,,}, and${var@Q}- negative array indexes such as
${arr[-1]} &>>and|&
It also fails when Bash 3.2 itself cannot parse a script.
An empty array expanded under set -u ("${items[@]}" before any element is added) is a runtime error on Bash 3.2, not a parse error. This action does not execute the scripts, so it does not catch that case.