From a265d4df72224b92d01ebd9f73b7e0ade7216388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstro=CC=88m?= Date: Tue, 20 Feb 2024 20:10:32 -0300 Subject: [PATCH 1/4] chore: add test for checking hadolint_output --- .github/workflows/test-e2e.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 533c906..8d60349 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -101,3 +101,24 @@ jobs: echo "::error::Version mismatch: \"${HADOLINT_VERSION}\" does not equal \"${REQUESTED_VERSION}\"" exit 1 fi + + gh-action-output: + name: Action populates output if configured + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: ./ + id: action-output + with: + dockerfile: "test/fixtures/Dockerfile-valid" + annotate: false + output_format: json + - name: Compare output + env: + OUTPUT: ${{ steps.action-output.outputs.hadolint_output }} + ASSERT: '[{"code":"DL3018","column":1,"file":"test/fixtures/Dockerfile-warning","level":"warning","line":3,"message":"Pin versions in apk add. Instead of `apk add ` use `apk add =`"}]' + run: | + if [[ "${OUTPUT}" != "${ASSERT}" ]]; then + echo "::error::Output mismatch: \"${OUTPUT}\" does not equal \"${ASSERT}\"" + exit 1 + fi From f96921113b33371f2f5a7b1e3b88b6a4540438ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstro=CC=88m?= Date: Tue, 20 Feb 2024 20:17:53 -0300 Subject: [PATCH 2/4] fix: change variable notation --- lib/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.sh b/lib/main.sh index 9613722..f301ed0 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -49,7 +49,7 @@ function run() { # to how output formatting works. if [[ -n "${OUTPUT_FORMAT}" ]]; then OUTPUT=$(eval "${HADOLINT_PATH}" --no-fail --no-color "${CONFIG}" -f "${OUTPUT_FORMAT}" "${DOCKERFILE}") - echo "hadolint_output=${OUTPUT//$'\n'/'%0A'} >> \$GITHUB_OUTPUT" + echo "hadolint_output=${OUTPUT//$'\n'/'%0A'} >> ${GITHUB_OUTPUT}" fi # Eval to remove empty vars From 60f7f54109e54b9ee3271407a150cb6694931ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstro=CC=88m?= Date: Tue, 20 Feb 2024 20:27:49 -0300 Subject: [PATCH 3/4] fix: properly quote output --- lib/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.sh b/lib/main.sh index f301ed0..8270605 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -49,7 +49,7 @@ function run() { # to how output formatting works. if [[ -n "${OUTPUT_FORMAT}" ]]; then OUTPUT=$(eval "${HADOLINT_PATH}" --no-fail --no-color "${CONFIG}" -f "${OUTPUT_FORMAT}" "${DOCKERFILE}") - echo "hadolint_output=${OUTPUT//$'\n'/'%0A'} >> ${GITHUB_OUTPUT}" + echo hadolint_output="${OUTPUT//$'\n'/'%0A'}" >> "${GITHUB_OUTPUT}" fi # Eval to remove empty vars From aa6c7fd4809d579ee36924d81b3891b21a978d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstro=CC=88m?= Date: Sun, 3 Mar 2024 16:40:41 -0300 Subject: [PATCH 4/4] wip: test --- lib/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.sh b/lib/main.sh index 8270605..f20a83f 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -49,7 +49,7 @@ function run() { # to how output formatting works. if [[ -n "${OUTPUT_FORMAT}" ]]; then OUTPUT=$(eval "${HADOLINT_PATH}" --no-fail --no-color "${CONFIG}" -f "${OUTPUT_FORMAT}" "${DOCKERFILE}") - echo hadolint_output="${OUTPUT//$'\n'/'%0A'}" >> "${GITHUB_OUTPUT}" + echo \"hadolint_output="${OUTPUT//$'\n'/'%0A'}"\" >>"${GITHUB_OUTPUT}" fi # Eval to remove empty vars