From 242fe39ec1dbe2614a80ba67ce8fc845084ce5dd Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Tue, 16 Nov 2021 10:56:15 +0100 Subject: [PATCH] Replace newlines with `awk`. (#20) Summary: - #16 introduced a bug. The `entrypoint.sh` was not compatible with ash. - Replace Bash string replacement with `awk`. Closes #19 Co-authored-by: Ian --- .github/workflows/lint.yml | 9 +++++++++ entrypoint.sh | 20 +++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..43b8035 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,9 @@ +name: Lint Scripts +on: [pull_request] +jobs: + shellcheck: + name: Shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: azohra/shell-linter@v0.6.0 diff --git a/entrypoint.sh b/entrypoint.sh index e478e1b..c21664d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,5 @@ #!/bin/sh +# shellcheck shell=dash # # Interact with the Cortex Ruler API using the cortextool @@ -24,7 +25,7 @@ LINT_CMD=lint CHECK_CMD=check PREPARE_CMD=prepare SYNC_CMD=sync -DIFF_CMD=diff +DIFF_CMD="diff" PRINT_CMD=print if [ -z "${RULES_DIR}" ]; then @@ -38,29 +39,29 @@ if [ -z "${ACTION}" ]; then fi case "${ACTION}" in - $SYNC_CMD) + "$SYNC_CMD") verifyTenantAndAddress OUTPUT=$(/usr/bin/cortextool rules sync --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} "$@") STATUS=$? ;; - $DIFF_CMD) + "$DIFF_CMD") verifyTenantAndAddress OUTPUT=$(/usr/bin/cortextool rules diff --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} --disable-color "$@") STATUS=$? ;; - $LINT_CMD) + "$LINT_CMD") OUTPUT=$(/usr/bin/cortextool rules lint --rule-dirs="${RULES_DIR}" "$@") STATUS=$? ;; - $PREPARE_CMD) + "$PREPARE_CMD") OUTPUT=$(/usr/bin/cortextool rules prepare -i --rule-dirs="${RULES_DIR}" --label-excluded-rule-groups="${LABEL_EXCLUDED_RULE_GROUPS}" "$@") STATUS=$? ;; - $CHECK_CMD) + "$CHECK_CMD") OUTPUT=$(/usr/bin/cortextool rules check --rule-dirs="${RULES_DIR}" "$@") STATUS=$? ;; - $PRINT_CMD) + "$PRINT_CMD") OUTPUT=$(/usr/bin/cortextool rules print --disable-color "$@") STATUS=$? ;; @@ -70,10 +71,7 @@ case "${ACTION}" in ;; esac -echo "${OUTPUT}" -SINGLE_LINE_OUTPUT="${OUTPUT//'%'/'%25'}" -SINGLE_LINE_OUTPUT="${SINGLE_LINE_OUTPUT//$'\n'/'%0A'}" -SINGLE_LINE_OUTPUT="${SINGLE_LINE_OUTPUT//$'\r'/'%0D'}" +SINGLE_LINE_OUTPUT=$(echo "${OUTPUT}" | awk 'BEGIN { RS="" } { gsub(/%/, "%25"); gsub(/\r/, "%0D"); gsub(/\n/, "%0A") } { print }') echo ::set-output name=detailed::"${SINGLE_LINE_OUTPUT}" SUMMARY=$(echo "${OUTPUT}" | grep Summary) echo ::set-output name=summary::"${SUMMARY}"