-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add shellcheck composite action #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| name: shellcheck | ||
| description: Lint shell scripts with ShellCheck against a caller-supplied rcfile. | ||
|
|
||
| inputs: | ||
| paths: | ||
| description: >- | ||
| Roots to search for shell scripts (*.sh, *.bash), space-separated. | ||
| Default searches the whole repo. | ||
| default: '.' | ||
| rcfile: | ||
| description: Path to the .shellcheckrc ruleset in the caller repo. | ||
| default: modules/shellcheck/.shellcheckrc | ||
| exclude: | ||
| description: >- | ||
| Path substrings to skip, space-separated (e.g. intentionally-bad | ||
| fixtures). The .git directory is always skipped. | ||
| default: '' | ||
| version: | ||
| description: Exact ShellCheck version to install. | ||
| default: 0.11.0 | ||
| sha256: | ||
| description: >- | ||
| SHA-256 of the linux x86_64 .tar.gz release asset for `version`. Change | ||
| together with `version`. | ||
| default: b7af85e41cc99489dcc21d66c6d5f3685138f06d34651e6d34b42ec6d54fe6f6 | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install ShellCheck | ||
| shell: bash | ||
| env: | ||
| VERSION: ${{ inputs.version }} | ||
| SHA256: ${{ inputs.sha256 }} | ||
| run: | | ||
| set -euo pipefail | ||
| url="https://github.com/koalaman/shellcheck/releases/download/v${VERSION}/shellcheck-v${VERSION}.linux.x86_64.tar.gz" | ||
| curl -fsSL "$url" -o shellcheck.tar.gz | ||
| echo "${SHA256} shellcheck.tar.gz" | sha256sum -c - | ||
| tar -xzf shellcheck.tar.gz "shellcheck-v${VERSION}/shellcheck" | ||
| sudo install "shellcheck-v${VERSION}/shellcheck" /usr/local/bin/shellcheck | ||
| rm -rf shellcheck.tar.gz "shellcheck-v${VERSION}" | ||
| shellcheck --version | ||
|
|
||
| - name: Run ShellCheck | ||
| shell: bash | ||
| env: | ||
| PATHS: ${{ inputs.paths }} | ||
| RCFILE: ${{ inputs.rcfile }} | ||
| EXCLUDE: ${{ inputs.exclude }} | ||
| run: | | ||
| set -euo pipefail | ||
| # $PATHS unquoted so multiple roots word-split. | ||
| mapfile -t files < <(find $PATHS -type f \( -name '*.sh' -o -name '*.bash' \) -not -path '*/.git/*' | sort) | ||
| # Drop excluded substrings (space-separated, fixed-string match). | ||
| for sub in $EXCLUDE; do | ||
| mapfile -t files < <(printf '%s\n' "${files[@]}" | grep -vF -- "$sub" || true) | ||
| done | ||
| if [[ ${#files[@]} -eq 0 ]]; then | ||
| echo 'No shell scripts to check.' | ||
| exit 0 | ||
| fi | ||
| printf 'Checking %d file(s):\n' "${#files[@]}" | ||
| printf ' %s\n' "${files[@]}" | ||
| shellcheck --rcfile="$RCFILE" "${files[@]}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a caller mistypes or renames an input root,
findreports the missing path but exits inside this process substitution, somapfilestill returns success underset -e; the action then either lints only the remaining roots or printsNo shell scripts to check.and exits 0. This can let a misconfigured ShellCheck lane pass without checking the intended scripts, so validate eachpathsentry or otherwise propagatefindfailures before continuing.Useful? React with 👍 / 👎.