diff --git a/README.md b/README.md index cd4121d..5affe47 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ steps: | Name | Description | Default | |------------------ |------------------------------------------ |----------------- | | dockerfile | The path to the Dockerfile to be tested | ./Dockerfile | +| recursive | Search for specified dockerfile | false | +| | recursively, from the project root | | | format | The output format. One of [tty \| json \| | tty | | | checkstyle \| codeclimate \| | | | | gitlab_codeclimate] | | diff --git a/action.yml b/action.yml index e5163ab..aff7df6 100644 --- a/action.yml +++ b/action.yml @@ -6,6 +6,10 @@ inputs: required: false description: 'The path to the Dockerfile to lint' default: 'Dockerfile' + recursive: + required: false + description: 'Search for specified dockerfile recursively, from the project root' + default: 'false' format: required: false description: | @@ -39,6 +43,7 @@ runs: env: HADOLINT_CONFIG: ${{ inputs.config }} HADOLINT_IGNORE: ${{ inputs.ignore }} + HADOLINT_RECURSIVE: ${{ inputs.recursive }} branding: icon: 'layers' color: 'purple' diff --git a/hadolint.sh b/hadolint.sh index e74c807..243bc86 100755 --- a/hadolint.sh +++ b/hadolint.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # The problem-matcher definition must be present in the repository # checkout (outside the Docker container running hadolint). We create @@ -27,5 +27,14 @@ for i in $HADOLINT_IGNORE; do HADOLINT_IGNORE_CMDLINE="${HADOLINT_IGNORE_CMDLINE} --ignore=${i}" done -# shellcheck disable=SC2086 -hadolint $HADOLINT_IGNORE_CMDLINE $HADOLINT_CONFIG "$@" +if [ "$HADOLINT_RECURSIVE" = "true" ]; then + shopt -s globstar + + filename="${!#}" + flags="${@:1:$#-1}" + + hadolint $HADOLINT_IGNORE_CMDLINE $HADOLINT_CONFIG $flags **/$filename +else + # shellcheck disable=SC2086 + hadolint $HADOLINT_IGNORE_CMDLINE $HADOLINT_CONFIG "$@" +fi