-
Notifications
You must be signed in to change notification settings - Fork 1.1k
CI - add job for shellcheck #5948
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,71 @@ | ||
#!/usr/bin/env bash | ||
|
||
############################################################################### | ||
# Execute shellcheck for all shell scripts in this repository | ||
# | ||
# Usage: | ||
# check/shellcheck [--dry-run] [shellcheck-arguments] | ||
# | ||
# Use the '--dry-run' option to print out the shellcheck command line without | ||
# running it. This displays all shell script files found in the repository. | ||
# | ||
################################################################################ | ||
|
||
# Change working directory to the repository root. | ||
thisdir="$(dirname "${BASH_SOURCE[0]}")" || exit $? | ||
topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $? | ||
cd "${topdir}" || exit $? | ||
|
||
# Process command line arguments | ||
opt_dry_run=0 | ||
typeset -a shellcheck_options | ||
typeset -a our_shell_scripts | ||
|
||
for arg in "$@"; do | ||
if [[ "${arg}" == "--dry-run" ]]; then | ||
opt_dry_run=1 | ||
else | ||
shellcheck_options+=( "${arg}" ) | ||
fi | ||
done | ||
|
||
# Find all shell scripts in this repository. | ||
IFS=$'\n' read -r -d '' -a our_shell_scripts < \ | ||
<(git ls-files -z -- \ | ||
':(exclude)*.'{py,json,json_inward,repr,repr_inward,ipynb,txt,md} \ | ||
':(exclude)*.'{yaml,ts,tst,rst,pyi,cfg} | \ | ||
xargs -0 file | grep -i 'shell script' | cut -d: -f1) | ||
|
||
# Verify our_shell_scripts array - require it must contain files below. | ||
typeset -a required_shell_scripts | ||
required_shell_scripts=( | ||
# items below must be sorted | ||
check/all | ||
check/doctest | ||
check/format-incremental | ||
check/mypy | ||
check/nbformat | ||
check/pylint | ||
check/pytest | ||
dev_tools/pypath | ||
) | ||
|
||
scripts_not_found="$(comm -13 \ | ||
<(printf "%s\n" "${our_shell_scripts[@]}") \ | ||
<(printf "%s\n" "${required_shell_scripts[@]}") )" | ||
|
||
if [[ -n "${scripts_not_found}" ]]; then | ||
echo "Identification of shell scripts failed - files not found:" >&2 | ||
printf "\n%s\n\n" "${scripts_not_found}" >&2 | ||
echo "Please fix $0." >&2 | ||
exit 2 | ||
fi | ||
|
||
# Ready to run here. | ||
if (( opt_dry_run )); then | ||
printf '%s ' '>>' 'shellcheck' "${shellcheck_options[@]}" | ||
printf '\\\n %s ' "${our_shell_scripts[@]}" | ||
printf '\\\n;\n' | ||
else | ||
shellcheck "${shellcheck_options[@]}" "${our_shell_scripts[@]}" | ||
fi |
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.
No action needed: Eventually, we can add shellcheck itself ;-)
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.
It should be already included. :-) This list is to verify the shell scripts search command (ie,
git ls-files ... | xargs file | ...
) works as expected. Would be disappointing to have a passing check that checks zero files. :-/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.
I understand why you've done it and I think it's a great sanity check. I just meant to say that the sanity check could be self-referential since as you say
git ls-files
invoked byshellcheck
should findshellcheck
itself :-)