Skip to content

Commit

Permalink
Replace newlines with awk. (#20)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jeschkies and iainlane authored Nov 16, 2021
1 parent 74d619c commit 242fe39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
20 changes: 9 additions & 11 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# shellcheck shell=dash
#
# Interact with the Cortex Ruler API using the cortextool

Expand All @@ -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
Expand All @@ -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=$?
;;
Expand All @@ -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}"
Expand Down

0 comments on commit 242fe39

Please sign in to comment.