1
1
Fork 0
mirror of https://github.com/appleboy/ssh-action.git synced 2025-03-28 14:46:19 +01:00

make capturing optional

This commit is contained in:
GammaGames 2024-11-22 16:56:52 -07:00
parent fbf2b7866a
commit 4172428f49
2 changed files with 30 additions and 7 deletions

View file

@ -77,6 +77,12 @@ inputs:
description: "pass all environment variable to shell script." description: "pass all environment variable to shell script."
request_pty: request_pty:
description: "Request a pseudo-terminal from the server." description: "Request a pseudo-terminal from the server."
capture_stdout:
description: "Capture the stdout of the commands."
default: "false"
capture_stderr:
description: "Capture the stderr of the commands."
default: "false"
outputs: outputs:
stdout: stdout:

View file

@ -68,11 +68,28 @@ chmod +x ${TARGET}
echo "======= CLI Version =======" echo "======= CLI Version ======="
sh -c "${TARGET} --version" # print version sh -c "${TARGET} --version" # print version
echo "===========================" echo "==========================="
{ if [ ${{ inputs.capture_stdout }} == 'true' ] || [ "${{ inputs.capture_stderr }}" == 'true' ]; then
sh -c "${TARGET} $*" # run the command _stdout=/dev/stdout
} 2> /tmp/errFile | tee /tmp/outFile _stderr=/dev/stderr
if [ "${{ inputs.capture_stdout }}" == 'true' ]; then
_stdout=/tmp/outFile
fi
if [ "${{ inputs.capture_stderr }}" == 'true' ]; then
_stderr=/tmp/errFile
fi
stdout=$(cat /tmp/outFile) {
stderr=$(cat /tmp/errFile) sh -c "${TARGET} $*" # run the command
echo "stdout=${stdout//$'\n'/\\n}" >> $GITHUB_OUTPUT } 2> $_stderr | tee $_stdout
echo "stderr=${stderr//$'\n'/\\n}" >> $GITHUB_OUTPUT
if [ "${{ inputs.capture_stdout }}" == 'true' ]; then
stdout=$(cat $_stdout)
echo "stdout=${stdout//$'\n'/\\n}" >> $GITHUB_OUTPUT
fi
if [ "${{ inputs.capture_stderr }}" == 'true' ]; then
stderr=$(cat $_stderr)
echo "stderr=${stderr//$'\n'/\\n}" >> $GITHUB_OUTPUT
fi
else
sh -c "${TARGET} $*" # run the command
fi