How to Run ShellCheck on Scripts in GitHub Actions
Shell scripts hide quoting and word-splitting bugs that only break in production; ShellCheck finds them in CI.
Run ShellCheck against every tracked .sh file so warnings and errors fail the job.
Steps
- Collect the shell scripts to lint (a glob or
git ls-files). - Run
shellcheckagainst them, optionally with-S errorto gate only on errors at first. - Fix or annotate findings; tighten the severity over time.
Workflow
.github/workflows/shellcheck.yml
name: ShellCheck
on: [pull_request]
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck
run: |
mapfile -t files < <(git ls-files '*.sh')
shellcheck "${files[@]}"Notes
- ShellCheck ships preinstalled on GitHub-hosted Ubuntu images, so no install step is needed.
- On Latchkey managed runners script-lint jobs run cheaper and self-heal if a runner dies.
Related guides
How to Lint Dockerfiles with Hadolint in GitHub ActionsLint Dockerfiles in GitHub Actions with hadolint so unpinned base images and bad layer practices fail CI befo…
How to Lint YAML with yamllint in GitHub ActionsLint YAML files in GitHub Actions with yamllint so indentation and syntax mistakes fail CI before they break…