Skip to content

Commit

Permalink
Merge pull request #57 from koenrh/filter-preview-output
Browse files Browse the repository at this point in the history
Reduce preview PR comment size
  • Loading branch information
koenrh authored Jul 24, 2021
2 parents 8e71742 + a12c1b3 commit 7d2c2d7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ LABEL "com.github.actions.color"="yellow"

RUN apk add --no-cache bash

COPY README.md /

COPY entrypoint.sh /entrypoint.sh
COPY README.md entrypoint.sh bin/filter-preview-output.sh /
ENTRYPOINT ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ GitHub Action.
with:
msg: |
```
${{ steps.dnscontrol_preview.outputs.output }}
${{ steps.dnscontrol_preview.outputs.preview_comment }}
```
check_for_duplicate_msg: true
```
Expand Down
9 changes: 9 additions & 0 deletions bin/filter-preview-output.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# source: https://git.io/J86QD
grep -v -e '^\.\.\.0 corrections$' |\
grep -v -e '^0 corrections' |\
grep -v -e '\.\.\. (skipping)' |\
grep -v -e '^----- DNS Provider: ' |\
grep -v -e '^----- Registrar: ' |\
grep -v -e '^----- Getting nameservers from:'
22 changes: 18 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

set -o pipefail

escape() {
local input="$1"

# https://github.community/t/set-output-truncates-multiline-strings/16852/3
input="${input//'%'/'%25'}"
input="${input//$'\n'/'%0A'}"
input="${input//$'\r'/'%0D'}"

echo "$input"
}

# Resolve to full paths
CONFIG_ABS_PATH="$(readlink -f "${INPUT_CONFIG_FILE}")"
CREDS_ABS_PATH="$(readlink -f "${INPUT_CREDS_FILE}")"
Expand All @@ -25,10 +36,13 @@ EXIT_CODE="$?"

echo "$OUTPUT"

# https://github.community/t/set-output-truncates-multiline-strings/16852/3
OUTPUT="${OUTPUT//'%'/'%25'}"
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
# Filter output to reduce 'preview' PR comment length
FILTERED_OUTPUT="$(echo "$OUTPUT" | /filter-preview-output.sh)"

OUTPUT="$(escape "$OUTPUT")"
FILTERED_OUTPUT="$(escape "$FILTERED_OUTPUT")"

echo "::set-output name=output::$OUTPUT"
echo "::set-output name=preview_comment::$FILTERED_OUTPUT"

exit $EXIT_CODE

0 comments on commit 7d2c2d7

Please sign in to comment.