Skip to content

Commit

Permalink
ci: fix test script to recognize any non-zero exit as an error
Browse files Browse the repository at this point in the history
hack/linter.sh didn't properly install golangci-lint in hack/bin as I
already have another version of golangci-lint on my PATH, but then it
failed to execute because it was looking for it specifically in
hack/bin.

When the executable is not found, the exit code is 127 instead of 1,
and so test.sh ignored the error.

Two fixes:

1. `test.sh`:
  - Use `if (script) ...` instead of assigning / checking a result
    variable to determine if each validation script passed or failed.

2. `hack/linter.sh`:
  - Instead of checking for golangci-lint on the path, just
    specifically check for an executable file (`test -x`) in the
    expected location.
  • Loading branch information
wwade committed Oct 20, 2021
1 parent 72286d6 commit 376a520
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 4 additions & 4 deletions hack/linter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

set -e -o pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
BIN=${DIR}/bin

if ! [ -x "$(command -v golangci-lint)" ]; then
if [ ! -x "${BIN}/golangci-lint" ]; then
echo "Installing GolangCI-Lint"
${DIR}/install_golint.sh -b ${BIN} v1.23.7
"${DIR}/install_golint.sh" -b "${BIN}" v1.23.7
fi

${BIN}/golangci-lint run
"${BIN}/golangci-lint" run
10 changes: 3 additions & 7 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ fail=0
for s in "${scripts[@]}"
do
echo "RUN ${s}"
set +e
./$s
result=$?
set -e
if [[ $result -eq 1 ]]; then
if "./${s}"; then
echo -e "${GREEN}PASSED${RESET} ${s}"
else
echo -e "${RED}FAILED${RESET} ${s}"
fail=1
else
echo -e "${GREEN}PASSED${RESET} ${s}"
fi
done
exit $fail

0 comments on commit 376a520

Please sign in to comment.