Skip to content

Commit 39f1dbc

Browse files
authored
add shellcheck test (#27)
* add shellcheck test * constrain the bash grep
1 parent 27f8ff6 commit 39f1dbc

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
- stage: Test
1919
script: make spellcheck
2020
name: Markdown Spellcheck
21+
- stage: Test
22+
script: make shellcheck
23+
name: Shell Script Check
2124
- stage: Test
2225
script: make homebrew-sync-dry-run
2326
name: Homebrew Sync Dry-Run

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ go-report-card-test:
6969
spellcheck:
7070
${MAKEFILE_PATH}/test/readme-test/run-readme-spellcheck
7171

72+
shellcheck:
73+
${MAKEFILE_PATH}/test/shellcheck/run-shellcheck
74+
7275
## requires aws credentials
7376
readme-codeblock-test:
7477
${MAKEFILE_PATH}/test/readme-test/run-readme-codeblocks
@@ -101,8 +104,8 @@ build: compile
101104

102105
release: build-binaries build-docker-images push-docker-images upload-resources-to-github
103106

104-
test: spellcheck unit-test license-test go-report-card-test output-validation-test readme-codeblock-test
107+
test: spellcheck shellcheck unit-test license-test go-report-card-test output-validation-test readme-codeblock-test
105108

106109
help:
107110
@echo $(CURDIR)
108-
@grep -E '^[a-zA-Z_-]+:.*$$' $(MAKEFILE_LIST) | sort
111+
@grep -E '^[a-zA-Z_-]+:.*$$' $(MAKEFILE_LIST) | sort

test/readme-test/run-readme-codeblocks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trap exit_and_fail INT ERR
1313
docker build --target=builder --build-arg="GOPROXY=direct" -t codeblocks -f $SCRIPTPATH/../../Dockerfile $SCRIPTPATH/../../
1414
docker build -t rundoc -f $SCRIPTPATH/rundoc-Dockerfile $SCRIPTPATH/
1515
function rd() {
16-
docker run -it --rm -v $SCRIPTPATH/../../:/aeis rundoc rundoc $@
16+
docker run -it --rm -v $SCRIPTPATH/../../:/aeis rundoc rundoc "$@"
1717
}
1818

1919
rundoc_output=$(rd list-blocks /aeis/README.md)

test/readme-test/run-readme-spellcheck

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/bash
2-
set -euo errexit
2+
set -euo pipefail
33

44
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
55

66
function exit_and_fail() {
77
echo "❌ Test Failed! Found a markdown file with spelling errors."
88
exit 1
99
}
10-
trap exit_and_fail INT ERR
10+
trap exit_and_fail INT ERR TERM
1111

1212
docker build -t misspell -f $SCRIPTPATH/spellcheck-Dockerfile $SCRIPTPATH/
1313
docker run -i --rm -v $SCRIPTPATH/../../:/aeis misspell /bin/bash -c 'find /aeis/ -type f -name "*.md" -not -path "build" | grep -v "/build/" | xargs misspell -error -debug'

test/shellcheck/run-shellcheck

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
6+
BUILD_DIR="${SCRIPTPATH}/../../build"
7+
8+
KERNEL=$(uname -s | tr '[:upper:]' '[:lower:]')
9+
SHELLCHECK_VERSION="0.7.1"
10+
11+
function exit_and_fail() {
12+
echo "❌ Test Failed! Found a shell script with errors."
13+
exit 1
14+
}
15+
trap exit_and_fail INT ERR TERM
16+
17+
curl -Lo ${BUILD_DIR}/shellcheck.tar.xz https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${KERNEL}.x86_64.tar.xz
18+
tar -C ${BUILD_DIR} -xvf "${BUILD_DIR}/shellcheck.tar.xz"
19+
export PATH="${BUILD_DIR}/shellcheck-v${SHELLCHECK_VERSION}:$PATH"
20+
21+
shellcheck -S error $(grep -Rn -e '#!.*/bin/bash' -e '#!.*/usr/bin/env bash' ${SCRIPTPATH}/../../ | grep ":[1-5]:" | cut -d':' -f1)
22+
23+
echo "✅ All shell scripts look good! 😎"

0 commit comments

Comments
 (0)