Skip to content
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

Check scripts with shellcheck before accepting new commands #781

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ jobs:
- name: Linux Install
if: matrix.platform == 'ubuntu-18.04'
run: |
sudo apt-get install -y bsdmainutils
sudo apt-get install -y bsdmainutils shellcheck
- name: Script
run: |
./check_integrity.sh $(find bin | cut -b 5- | xargs)
./check_changed_files.sh
- name: Brew release
if: matrix.platform == 'macos-latest'
run: |
Expand Down
13 changes: 13 additions & 0 deletions check_changed_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

err() {
echo >&2 "$1"
exit 1
}

if command -v shellcheck > /dev/null ; then
# Check all changed shell scripts
if ! git diff -z --name-only "$TRAVIS_BRANCH...HEAD" | xargs -0 ./shellcheck.sh ; then
err "Please fix the shellcheck issues"
fi
fi
17 changes: 17 additions & 0 deletions shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
files=()
for f ; do
if [ -r "$f" ] ; then
file --mime-type -r0 "$f" |
cut -d "" -f 2 |
grep -q "^: text/x-shellscript$" &&
files+=("$f")
fi
done
if [ ${#files[@]} -gt 0 ] ; then
shellcheck "${files[@]}"
ret=$?
if [ $ret -eq 1 ] || [ $ret -eq 2 ] ; then
exit 1
fi
fi