Skip to content

Commit

Permalink
main: error check against json array
Browse files Browse the repository at this point in the history
If `error_level` is set to 2, any output from hadolint
should be seen as an error. Since hadolint emits an array
when output is set to json, this is seen as our happy path.

Fixes: #24
  • Loading branch information
jbergstroem committed May 14, 2021
1 parent 6b24ec4 commit 455e94a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ function run() {
[[ "${ERRORLEVEL}" == "1" ]] && echo "${OUTPUT}" | exit_if_found_in_json "warning"
[[ "${ERRORLEVEL}" == "1" ]] && echo "${OUTPUT}" | exit_if_found_in_json "error"

# Any output would imply an error
[[ "${ERRORLEVEL}" == "2" && "${OUTPUT}" != "" ]] && exit 1
# An empty json array would imply an error
[[ "${ERRORLEVEL}" == "2" && "${OUTPUT}" != "[]" ]] && exit 1

# You either did well or chose to become a better person
exit 0
Expand Down
1 change: 1 addition & 0 deletions test/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ test_override_errorlevel() {
assert "error_level=-1 dockerfile=fixtures/Dockerfile-error ${HL}"
assert_fail "dockerfile=fixtures/Dockerfile-error ${HL}"
assert_fail "error_level=2 dockerfile=fixtures/Dockerfile-error ${HL}"
assert "error_level=2 dockerfile=fixtures/Dockerfile-valid ${HL}"
assert "dockerfile=fixtures/Dockerfile-warning ${HL}"
assert_fail "error_level=1 dockerfile=fixtures/Dockerfile-warning ${HL}"
}
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/Dockerfile-valid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:3.12

RUN ls

0 comments on commit 455e94a

Please sign in to comment.