Skip to content

Commit

Permalink
feature: support custom hadolint path
Browse files Browse the repository at this point in the history
Fixes: #13
  • Loading branch information
jbergstroem committed Apr 11, 2021
1 parent f33da64 commit 407e24b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions lib/hadolint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
4 changes: 2 additions & 2 deletions lib/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion test/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

Expand Down

0 comments on commit 407e24b

Please sign in to comment.