fix(cicd): keep branch follower debug JSON parseable
This commit is contained in:
@@ -3,8 +3,6 @@ set -eu
|
||||
|
||||
cd /work
|
||||
rm -rf /work/unidesk
|
||||
started_at=$(date -Iseconds)
|
||||
echo "branch-follower one-shot started ${started_at}" >&2
|
||||
|
||||
/etc/unidesk-cicd-branch-follower/sync-source.sh \
|
||||
"${UNIDESK_CONTROLLER_SOURCE_REPOSITORY}" \
|
||||
@@ -16,6 +14,34 @@ git clone --branch "${UNIDESK_CONTROLLER_SOURCE_BRANCH}" "/cache/${UNIDESK_CONTR
|
||||
cp /etc/unidesk-cicd-branch-follower/cicd-branch-followers.yaml /work/unidesk/config/cicd-branch-followers.yaml
|
||||
cd /work/unidesk
|
||||
|
||||
"$@"
|
||||
machine_output=false
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--json|--raw|json)
|
||||
machine_output=true
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "branch-follower one-shot finished $(date -Iseconds)" >&2
|
||||
if [ "${machine_output}" = true ]; then
|
||||
output_file=$(mktemp)
|
||||
if "$@" >"${output_file}"; then
|
||||
node - "${output_file}" <<'NODE'
|
||||
const { readFileSync } = require("node:fs");
|
||||
const path = process.argv[2];
|
||||
const text = readFileSync(path, "utf8").trim();
|
||||
if (text.length === 0) process.exit(0);
|
||||
try {
|
||||
process.stdout.write(JSON.stringify(JSON.parse(text)));
|
||||
} catch {
|
||||
process.stdout.write(text);
|
||||
}
|
||||
NODE
|
||||
else
|
||||
status=$?
|
||||
cat "${output_file}"
|
||||
exit "${status}"
|
||||
fi
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user