Merge pull request #57 from koenrh/filter-preview-output

Reduce preview PR comment size
This commit is contained in:
Koen Rouwhorst 2021-07-24 13:38:15 +02:00 committed by GitHub
commit 7d2c2d7629
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 8 deletions

View file

@ -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"]

View file

@ -105,7 +105,7 @@ GitHub Action.
with:
msg: |
```
${{ steps.dnscontrol_preview.outputs.output }}
${{ steps.dnscontrol_preview.outputs.preview_comment }}
```
check_for_duplicate_msg: true
```

9
bin/filter-preview-output.sh Executable file
View file

@ -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:'

View file

@ -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}")"
@ -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