-
Notifications
You must be signed in to change notification settings - Fork 2k
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
shellcheck: Add CI check script #9063
Conversation
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.
Very useful, thanks!
Do you think it would make sense to add this script to the list of static tests (in dist/tools/ci/build_and_test.sh) ?
I tested it locally and since another script with issues is touched, shellcheck reports errors.
You may also want to install shellcheck riotbuild docker image and travis.yml
dist/tools/shellcheck/check.sh
Outdated
fi | ||
|
||
${SHELLCHECK_CMD} --version &> /dev/null || { | ||
printf "%s%s: cannot execute \"%s\"!%s\n" "${CERROR}" "$0" "${SHELLCHECK_CMD}" "${CRESET}" |
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.
IIUC, python
because the command is python -m flake8 ...
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 would use the following:
printf "%sError: \"%s\" is missing%s\n" "${CERROR}" "${SHELLCHECK_CMD}" "${CRESET}"
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.
Ack
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.
fixed
dist/tools/shellcheck/check.sh
Outdated
exit 1 | ||
} | ||
|
||
ERRORS=$("${SHELLCHECK_CMD}" --format=gcc ${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.
This line is reporting the following error for me: dist/tools/shellcheck/check.sh:38:43: note: Double quote to prevent globbing and word splitting. [SC2086]
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.
The only way at the moment to fix this is to make FILES
an bash array, which requires modifications of the dist/tools/ci/changed_files.sh
. Those modification would cascade to many other scripts which is out of scope for this PR.
Now that the 'RIOTTOLS' variable has been added, could you try replacing 'dist/tools' by 'RIOTTOLS' as done in some of the commits here: https://github.com/RIOT-OS/RIOT/pull/8821 ? Edit: or more precisely this one now: #9070 |
6ae813a
to
b3d8970
Compare
Done! |
b3d8970
to
b5cd1f6
Compare
dist/tools/shellcheck/check.sh
Outdated
fi | ||
|
||
${SHELLCHECK_CMD} --version &> /dev/null || { | ||
printf "%sError: \"%s\" is missing%s\n" "${CERROR}" "${SHELLCHECK_CMD}" "${CRESET}" |
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.
this doesn't work when spellcheck
is not installed this error message reads: Error: "" is missing
, which is no surprise. Hence, you need to write shellcheck
in the error string because the SHELLCHECK_CMD
variable is empty
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.
You're right, fixed!
dist/tools/shellcheck/check.sh
Outdated
: "${RIOTTOOLS:=${PWD}/dist/tools}" | ||
. "${RIOTTOOLS}"/ci/changed_files.sh | ||
|
||
FILES=$(FILEREGEX='(?=*.sh$)' changed_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.
this regex doesn't work with macOS, and also is no proper/standard? regex anyway. Using FILES=$(FILEREGEX='(.*\.sh$)' changed_files)
it works, allowing any file name which ends on .sh
.
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.
Thanks for testing this, I've replaced it with your suggestion.
@smlng thanks for the review, I've adapted your suggestions |
@aabadie @smlng do you like the changes can he squash ? After discussing IRL about the changes, I personally just want referenced in the commit message why it is not passing its own test right now #9063 (comment) I would merge after this. |
re-tested on macOS, works as expected: ACK. |
clear to squash |
dist/tools/shellcheck/check.sh
Outdated
# directory for more details. | ||
# | ||
|
||
SHELLCHECK_CMD="$(which shellcheck)" |
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 thought the agreed upon and portable way to check if a command is available was determined to be command -v
.
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.
good point, oversaw that one
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.
So remove the which shellcheck
and assume that executing shellcheck
works?
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, just use command -v
instead of which
;-)
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.
Something like that is already here :-)
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.
But then you don't have the absolute path (in case that is required).
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.
Never mind, I was not aware that command
is an actual command and that it can be used as an alternative for which
😑
You can squash when you want. |
8340f76
to
c5c3903
Compare
squashed! |
Outdated and adding by default will be another PR
Contribution description
Check script for shellcheck in a similar way as the flake8 script. SC1090 is excluded from the checks.
Issues/PRs references
#8212