Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions shellcheck/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
name: ShellCheck GitHub Action
description: |
Execute ShellCheck in a GitHub Action.

inputs:
shellcheck-version:
description: |
ShellCheck version to use. This should match a Docker Hub tag.
See https://hub.docker.com/r/koalaman/shellcheck/tags for a list of
available tags.
required: false
default: "v0.11.0"

shellcheck-severity:
description: |
ShellCheck severity to use.
One of 'error', 'warning', 'info', or 'style'.
required: false
default: style

files:
description: |
List of files to scan.
Comment thread
EtienneM marked this conversation as resolved.
When unset, defaults to recursively scanning all .sh files in the repo.
Use the following syntax to specify a list of files:

with:
files: |
first.sh
second file.sh
third file

required: false
default: ""

runs:
using: "composite"
steps:
- uses: actions/checkout@v5

- name: Run ShellCheck
shell: bash
env:
FILES: ${{ inputs.files }}
SEVERITY: ${{ inputs.shellcheck-severity }}
VERSION: ${{ inputs.shellcheck-version }}
run: |
docker run --rm \
--env FILES \
--env SEVERITY \
--volume "${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE}:ro" \
--volume "${GITHUB_ACTION_PATH}:${GITHUB_ACTION_PATH}:ro" \
--workdir "${GITHUB_WORKSPACE}" \
koalaman/shellcheck-alpine:${VERSION} \
/bin/sh "${GITHUB_ACTION_PATH}/scripts/run-shellcheck.sh"
25 changes: 25 additions & 0 deletions shellcheck/scripts/run-shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

set -o errexit
set -o nounset

if [ -n "${FILES}" ]; then
# Reset argv ($@):
set --

# Fill argv with the files provided. Keeps spaces.
while IFS= read -r file; do
[ -n "${file}" ] && set -- "$@" "${file}"
done <<-EOF
${FILES}
EOF

# Run ShellCheck
shellcheck -S "${SEVERITY}" -s bash "$@"
else
# Default behavior
# Finds all .sh files and pass them to ShellCheck.
# Ignores those in the `.git` directory.
find . -type f -name '*.sh' -not -path './.git/*' \
-exec shellcheck -S "${SEVERITY}" -s bash {} +
fi
Loading