fix(output): close capture record before returning failures

A nonzero drone-ssh pipeline previously exited under errexit before writing the closing GITHUB_OUTPUT delimiter.

Capture the pipefail status inside an if condition, finish the record, then return that status. Add a separator only when stdout lacks a final newline so successful captured values retain their existing shape.
This commit is contained in:
Bonobo 2026-08-10 03:07:22 +02:00
parent b838bc2f27
commit f39ff00725

View File

@ -72,8 +72,17 @@ fi
echo "======================================="
if [[ "${INPUT_CAPTURE_STDOUT}" == 'true' ]]; then
echo 'stdout<<EOF' >> "${GITHUB_OUTPUT}"
"${TARGET}" "$@" | tee -a "${GITHUB_OUTPUT}"
if "${TARGET}" "$@" | tee -a "${GITHUB_OUTPUT}"; then
capture_status=0
else
capture_status=$?
fi
output_last_byte_newline_count="$(tail -c 1 "${GITHUB_OUTPUT}" | wc -l)"
if [[ "${output_last_byte_newline_count}" -eq 0 ]]; then
echo >> "${GITHUB_OUTPUT}"
fi
echo 'EOF' >> "${GITHUB_OUTPUT}"
exit "${capture_status}"
else
"${TARGET}" "$@"
fi