Skip to content

Commit

Permalink
make capturing optional
Browse files Browse the repository at this point in the history
  • Loading branch information
GammaGames committed Nov 22, 2024
1 parent fbf2b78 commit 4172428
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ inputs:
description: "pass all environment variable to shell script."
request_pty:
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:
stdout:
Expand Down
31 changes: 24 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,28 @@ chmod +x ${TARGET}
echo "======= CLI Version ======="
sh -c "${TARGET} --version" # print version
echo "==========================="
{
sh -c "${TARGET} $*" # run the command
} 2> /tmp/errFile | tee /tmp/outFile
if [ ${{ inputs.capture_stdout }} == 'true' ] || [ "${{ inputs.capture_stderr }}" == 'true' ]; then
_stdout=/dev/stdout
_stderr=/dev/stderr
if [ "${{ inputs.capture_stdout }}" == 'true' ]; then
_stdout=/tmp/outFile
fi
if [ "${{ inputs.capture_stderr }}" == 'true' ]; then
_stderr=/tmp/errFile
fi

{
sh -c "${TARGET} $*" # run the command
} 2> $_stderr | tee $_stdout

stdout=$(cat /tmp/outFile)
stderr=$(cat /tmp/errFile)
echo "stdout=${stdout//$'\n'/\\n}" >> $GITHUB_OUTPUT
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

0 comments on commit 4172428

Please sign in to comment.