File tree Expand file tree Collapse file tree 3 files changed +64
-2
lines changed Expand file tree Collapse file tree 3 files changed +64
-2
lines changed Original file line number Diff line number Diff line change @@ -549,3 +549,48 @@ jobs:
549549 #!/usr/bin/env bash
550550 set -e
551551 whoami
552+
553+ testing-capturing-output :
554+ runs-on : ubuntu-latest
555+ steps :
556+ - name : Checkout code
557+ uses : actions/checkout@v4
558+
559+ - name : create new ssh server
560+ run : |
561+ docker run -d \
562+ --name=openssh-server \
563+ --hostname=openssh-server \
564+ -p 2222:2222 \
565+ -e SUDO_ACCESS=false \
566+ -e PASSWORD_ACCESS=true \
567+ -e USER_PASSWORD=password \
568+ -e USER_NAME=linuxserver.io \
569+ --restart unless-stopped \
570+ lscr.io/linuxserver/openssh-server:latest
571+ docker exec openssh-server sh -c "hostname -i" > ip.txt
572+ echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
573+ cat ip.txt >> $GITHUB_ENV
574+ echo "EOF" >> $GITHUB_ENV
575+ echo "======= container ip address ========="
576+ cat ip.txt
577+ echo "======================================"
578+ sleep 2
579+
580+ - id : stdout
581+ name : ssh command with stdout
582+ uses : ./
583+ with :
584+ host : ${{ env.REMOTE_HOST }}
585+ username : linuxserver.io
586+ password : password
587+ port : 2222
588+ capture_stdout : true
589+ script : |
590+ #!/usr/bin/env bash
591+ set -e
592+ whoami
593+
594+ - name : check stdout
595+ run : |
596+ echo "stdout: ${{ steps.stdout.outputs.stdout }}"
Original file line number Diff line number Diff line change @@ -75,6 +75,14 @@ inputs:
7575 description : " pass all environment variable to shell script."
7676 request_pty :
7777 description : " Request a pseudo-terminal from the server."
78+ capture_stdout :
79+ description : " Capture the stdout of the commands."
80+ default : " false"
81+
82+ outputs :
83+ stdout :
84+ description : ' Standard output of the executed commands.'
85+ value : ${{ steps.entrypoint.outputs.stdout }}
7886
7987runs :
8088 using : " composite"
8492 shell : bash
8593 env :
8694 GITHUB_ACTION_PATH : ${{ github.action_path }}
87- - name : Run entrypoint.sh
95+ - id : entrypoint
96+ name : Run entrypoint.sh
8897 run : entrypoint.sh
8998 shell : bash
9099 env :
@@ -121,6 +130,7 @@ runs:
121130 INPUT_PROXY_USE_INSECURE_CIPHER : ${{ inputs.proxy_use_insecure_cipher }}
122131 INPUT_PROXY_CIPHER : ${{ inputs.proxy_cipher }}
123132 INPUT_SYNC : ${{ inputs.sync }}
133+ INPUT_CAPTURE_STDOUT : ${{ inputs.capture_stdout }}
124134
125135branding :
126136 icon : " terminal"
Original file line number Diff line number Diff line change @@ -64,7 +64,14 @@ TARGET="${GITHUB_ACTION_PATH}/${CLIENT_BINARY}"
6464echo " Will download ${CLIENT_BINARY} from ${DOWNLOAD_URL_PREFIX} "
6565curl -fsSL --retry 5 --keepalive-time 2 " ${DOWNLOAD_URL_PREFIX} /${CLIENT_BINARY} " -o ${TARGET}
6666chmod +x ${TARGET}
67+
6768echo " ======= CLI Version ======="
6869sh -c " ${TARGET} --version" # print version
6970echo " ==========================="
70- sh -c " ${TARGET} $* " # run the command
71+ if [[ " $INPUT_CAPTURE_STDOUT " == ' true' ]]; then
72+ echo ' stdout<<EOF' >> $GITHUB_OUTPUT # use heredoc for multiline output
73+ sh -c " ${TARGET} $* " | tee -a $GITHUB_OUTPUT # run the command
74+ echo ' EOF' >> $GITHUB_OUTPUT
75+ else
76+ sh -c " ${TARGET} $* " # run the command
77+ fi
You can’t perform that action at this time.
0 commit comments