From 407e24b3f6930e36b60f7f35a435f261ecaf7104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstro=CC=88m?= Date: Sun, 11 Apr 2021 12:52:30 -0400 Subject: [PATCH] feature: support custom hadolint path Fixes: https://github.com/jbergstroem/hadolint-gh-action/issues/13 --- README.md | 1 + action.yml | 4 ++++ lib/hadolint.sh | 3 +++ lib/main.sh | 4 ++-- test/e2e.sh | 7 ++++++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b37bce1..c9077a6 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ jobs: | error_level | `0` | Fail CI if hadolint emits output (`-1`: never, `0`: error, `1`: warning, `2`: info) | | annotate | true | Annotate code inline in the github PR viewer (`true`/`false`) | | output_format | | Set output format (choose between `tty`, `json`, `checkstyle`, `codeclimate` or `gitlab_codeclimate`) | +| hadolint_path | | Absolute path to hadolint binary. If unset, it is assumed to exist in `$PATH` | ## Hadolint version diff --git a/action.yml b/action.yml index 952fa81..68e306f 100644 --- a/action.yml +++ b/action.yml @@ -23,6 +23,10 @@ inputs: description: Set output format (choose between `tty`, `json`, `checkstyle`, `codeclimate` or `gitlab_codeclimate`) required: false default: + hadolint_path: + description: Absolute path to hadolint binary. If unset, it is assumed to exist in `$PATH` + required: false + default: outputs: hadolint_output: diff --git a/lib/hadolint.sh b/lib/hadolint.sh index 5f43c9e..013d49b 100644 --- a/lib/hadolint.sh +++ b/lib/hadolint.sh @@ -2,6 +2,9 @@ function output_hadolint_version() { local HADOLINT_VERSION="" + # I cannot pass path directly here; both tests and invoking `hadolint` + # directly would fail. + alias hadolint='${HADOLINT_PATH}' HADOLINT_VERSION="$(hadolint --version | cut -d " " -f 4)" echo "::set-output name=hadolint_version::${HADOLINT_VERSION}" } \ No newline at end of file diff --git a/lib/main.sh b/lib/main.sh index 58ab174..9d114d2 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -5,7 +5,7 @@ CONFIG_FILE=${config_file:-} ERRORLEVEL=${error_level:=0} ANNOTATE=${annotate:="true"} OUTPUT_FORMAT=${output_format:-} - +HADOLINT_PATH=${hadolint_path:="hadolint"} function exit_with_error() { echo "${1}" @@ -14,7 +14,7 @@ function exit_with_error() { function run() { # Check for dependencies - for executable in hadolint jq; do + for executable in "${HADOLINT_PATH}" jq; do if ! command -v ${executable} &> /dev/null; then echo "Cannot find required binary ${executable}. Is it in \$PATH?" exit 1 diff --git a/test/e2e.sh b/test/e2e.sh index b568b80..e2ae31c 100755 --- a/test/e2e.sh +++ b/test/e2e.sh @@ -12,7 +12,12 @@ test_default_path_with_dockerfile() { assert_status_code 0 "../../${HL}" } -test_custom_path() { +test_custom_hadolint_path() { + # Since test runners should have jq installed, lets find path and set it + assert_status_code 0 "hadolint_path=$(which hadolint) dockerfile=fixtures/default-path/Dockerfile ${HL}" +} + +test_custom_dockerfile_path() { assert_status_code 0 "dockerfile=fixtures/default-path/Dockerfile ${HL}" }