2019-01-05 19:24:28 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-01-29 03:31:15 +08:00
|
|
|
set -o pipefail
|
2019-01-05 19:24:28 +08:00
|
|
|
|
2021-07-14 00:21:01 +08:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2021-01-17 01:11:39 +08:00
|
|
|
# Resolve to full paths
|
2021-01-17 01:22:27 +08:00
|
|
|
CONFIG_ABS_PATH="$(readlink -f "${INPUT_CONFIG_FILE}")"
|
|
|
|
CREDS_ABS_PATH="$(readlink -f "${INPUT_CREDS_FILE}")"
|
2021-01-17 01:11:39 +08:00
|
|
|
|
|
|
|
WORKING_DIR="$(dirname "${CONFIG_ABS_PATH}")"
|
2021-02-08 01:01:42 +08:00
|
|
|
cd "$WORKING_DIR" || exit
|
2020-11-16 22:34:38 +08:00
|
|
|
|
2021-01-21 04:05:48 +08:00
|
|
|
ARGS=(
|
2021-01-29 03:31:15 +08:00
|
|
|
"$@"
|
2021-01-21 04:05:48 +08:00
|
|
|
--config "$CONFIG_ABS_PATH"
|
|
|
|
)
|
|
|
|
|
|
|
|
# 'check' sub-command doesn't require credentials
|
|
|
|
if [ "$1" != "check" ]; then
|
|
|
|
ARGS+=(--creds "$CREDS_ABS_PATH")
|
|
|
|
fi
|
|
|
|
|
2020-06-24 23:08:32 +08:00
|
|
|
IFS=
|
2021-01-21 04:05:48 +08:00
|
|
|
OUTPUT="$(dnscontrol "${ARGS[@]}")"
|
2021-01-29 03:31:15 +08:00
|
|
|
EXIT_CODE="$?"
|
2020-06-22 01:46:35 +08:00
|
|
|
|
|
|
|
echo "$OUTPUT"
|
|
|
|
|
2021-07-14 00:21:01 +08:00
|
|
|
# Filter output to reduce 'preview' PR comment length
|
|
|
|
FILTERED_OUTPUT="$(echo "$OUTPUT" | /filter-preview-output.sh)"
|
|
|
|
|
|
|
|
OUTPUT="$(escape "$OUTPUT")"
|
|
|
|
FILTERED_OUTPUT="$(escape "$FILTERED_OUTPUT")"
|
2020-06-22 01:46:35 +08:00
|
|
|
|
|
|
|
echo "::set-output name=output::$OUTPUT"
|
2021-07-14 00:21:01 +08:00
|
|
|
echo "::set-output name=preview_comment::$FILTERED_OUTPUT"
|
|
|
|
|
2021-01-29 03:31:15 +08:00
|
|
|
exit $EXIT_CODE
|