2021-05-31 13:57:42 +02:00
|
|
|
#!/bin/bash
|
2020-12-05 19:38:01 +01:00
|
|
|
# The problem-matcher definition must be present in the repository
|
2021-12-08 17:26:25 +01:00
|
|
|
# checkout (outside the Docker container running hadolint). We copy
|
|
|
|
# problem-matcher.json to the home folder.
|
2020-12-06 20:10:45 +01:00
|
|
|
|
2023-01-19 20:09:05 +01:00
|
|
|
PROBLEM_MATCHER_FILE="/problem-matcher.json"
|
|
|
|
if [ -f "$PROBLEM_MATCHER_FILE" ]; then
|
2023-01-20 09:55:56 +01:00
|
|
|
cp "$PROBLEM_MATCHER_FILE" "$HOME/"
|
2023-01-19 20:09:05 +01:00
|
|
|
fi
|
2020-12-06 20:10:45 +01:00
|
|
|
# After the run has finished we remove the problem-matcher.json from
|
|
|
|
# the repository so we don't leave the checkout dirty. We also remove
|
|
|
|
# the matcher so it won't take effect in later steps.
|
2023-01-19 20:09:05 +01:00
|
|
|
# shellcheck disable=SC2317
|
2020-12-06 20:10:45 +01:00
|
|
|
cleanup() {
|
2023-01-20 09:55:56 +01:00
|
|
|
echo "::remove-matcher owner=brpaz/hadolint-action::"
|
2020-12-06 20:10:45 +01:00
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
2020-12-05 19:38:01 +01:00
|
|
|
|
2021-12-08 17:26:25 +01:00
|
|
|
echo "::add-matcher::$HOME/problem-matcher.json"
|
2020-12-05 18:34:32 +01:00
|
|
|
|
2021-05-08 13:08:16 +02:00
|
|
|
if [ -n "$HADOLINT_CONFIG" ]; then
|
|
|
|
HADOLINT_CONFIG="-c ${HADOLINT_CONFIG}"
|
|
|
|
fi
|
|
|
|
|
2022-03-24 15:28:03 +01:00
|
|
|
if [ -z "$HADOLINT_TRUSTED_REGISTRIES" ]; then
|
2023-01-20 09:55:56 +01:00
|
|
|
unset HADOLINT_TRUSTED_REGISTRIES
|
2022-03-24 15:28:03 +01:00
|
|
|
fi
|
|
|
|
|
2023-01-19 20:09:05 +01:00
|
|
|
COMMAND="hadolint $HADOLINT_CONFIG"
|
|
|
|
|
2021-05-31 13:57:42 +02:00
|
|
|
if [ "$HADOLINT_RECURSIVE" = "true" ]; then
|
|
|
|
shopt -s globstar
|
|
|
|
|
|
|
|
filename="${!#}"
|
2023-01-19 20:09:05 +01:00
|
|
|
flags="${*:1:$#-1}"
|
|
|
|
|
|
|
|
RESULTS=$(eval "$COMMAND $flags" -- **/"$filename")
|
2021-05-31 13:57:42 +02:00
|
|
|
else
|
2023-01-19 20:09:05 +01:00
|
|
|
flags=$*
|
|
|
|
RESULTS=$(eval "$COMMAND" "$flags")
|
2022-03-31 09:51:31 +02:00
|
|
|
fi
|
|
|
|
FAILED=$?
|
|
|
|
|
|
|
|
if [ -n "$HADOLINT_OUTPUT" ]; then
|
|
|
|
if [ -f "$HADOLINT_OUTPUT" ]; then
|
|
|
|
HADOLINT_OUTPUT="$TMP_FOLDER/$HADOLINT_OUTPUT"
|
|
|
|
fi
|
2023-01-20 09:55:56 +01:00
|
|
|
echo "$RESULTS" >"$HADOLINT_OUTPUT"
|
2021-05-31 13:57:42 +02:00
|
|
|
fi
|
2021-11-18 13:09:22 +01:00
|
|
|
|
2022-03-31 12:45:58 +02:00
|
|
|
RESULTS="${RESULTS//$'\\n'/''}"
|
2022-11-08 22:33:58 +01:00
|
|
|
|
2023-01-20 09:55:56 +01:00
|
|
|
{
|
|
|
|
echo "results<<EOF"
|
|
|
|
echo "$RESULTS"
|
|
|
|
echo "EOF"
|
|
|
|
} >>"$GITHUB_OUTPUT"
|
2022-03-31 11:14:55 +02:00
|
|
|
|
2023-01-20 09:55:56 +01:00
|
|
|
{
|
|
|
|
echo "HADOLINT_RESULTS<<EOF"
|
|
|
|
echo "$RESULTS"
|
|
|
|
echo "EOF"
|
|
|
|
} >>"$GITHUB_ENV"
|
2022-03-31 12:49:42 +02:00
|
|
|
|
2021-11-18 13:09:22 +01:00
|
|
|
[ -z "$HADOLINT_OUTPUT" ] || echo "Hadolint output saved to: $HADOLINT_OUTPUT"
|
2022-03-24 13:57:02 +01:00
|
|
|
|
|
|
|
exit $FAILED
|