From 4172428f490821c7e8e42fab851ab64a002eda90 Mon Sep 17 00:00:00 2001 From: GammaGames Date: Fri, 22 Nov 2024 16:56:52 -0700 Subject: [PATCH 01/11] make capturing optional --- action.yml | 6 ++++++ entrypoint.sh | 31 ++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index ce55154..83deeed 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/entrypoint.sh b/entrypoint.sh index 482a0c9..d78e6aa 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 From 765833ffce00afac0f2d125d9d25ce3b6353bc99 Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 10:19:44 -0700 Subject: [PATCH 02/11] fix substitution? --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index d78e6aa..aa72e59 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -68,7 +68,7 @@ chmod +x ${TARGET} echo "======= CLI Version =======" sh -c "${TARGET} --version" # print version echo "===========================" -if [ ${{ inputs.capture_stdout }} == 'true' ] || [ "${{ inputs.capture_stderr }}" == 'true' ]; then +if [ "${{ inputs.capture_stdout }}" == 'true' ] || [ "${{ inputs.capture_stderr }}" == 'true' ]; then _stdout=/dev/stdout _stderr=/dev/stderr if [ "${{ inputs.capture_stdout }}" == 'true' ]; then From 1a1adf6ba5e155e6a70309d617fc0e676e60b97f Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 10:29:44 -0700 Subject: [PATCH 03/11] use env --- action.yml | 2 ++ entrypoint.sh | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 83deeed..2811a42 100644 --- a/action.yml +++ b/action.yml @@ -136,6 +136,8 @@ runs: INPUT_PROXY_USE_INSECURE_CIPHER: ${{ inputs.proxy_use_insecure_cipher }} INPUT_PROXY_CIPHER: ${{ inputs.proxy_cipher }} INPUT_SYNC: ${{ inputs.sync }} + INPUT_CAPTURE_STDOUT: ${{ inputs.capture_stdout }} + INPUT_CAPTURE_STDERR: ${{ inputs.capture_stderr }} branding: icon: "terminal" diff --git a/entrypoint.sh b/entrypoint.sh index aa72e59..4545c53 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -68,13 +68,13 @@ chmod +x ${TARGET} echo "======= CLI Version =======" sh -c "${TARGET} --version" # print version echo "===========================" -if [ "${{ inputs.capture_stdout }}" == 'true' ] || [ "${{ inputs.capture_stderr }}" == 'true' ]; then +if [ "$INPUT_CAPTURE_STDOUT" == 'true' ] || [ "$INPUT_CAPTURE_STDERR" == 'true' ]; then _stdout=/dev/stdout _stderr=/dev/stderr - if [ "${{ inputs.capture_stdout }}" == 'true' ]; then + if [ "$INPUT_CAPTURE_STDOUT" == 'true' ]; then _stdout=/tmp/outFile fi - if [ "${{ inputs.capture_stderr }}" == 'true' ]; then + if [ "$INPUT_CAPTURE_STDERR" == 'true' ]; then _stderr=/tmp/errFile fi @@ -82,11 +82,11 @@ if [ "${{ inputs.capture_stdout }}" == 'true' ] || [ "${{ inputs.capture_stderr sh -c "${TARGET} $*" # run the command } 2> $_stderr | tee $_stdout - if [ "${{ inputs.capture_stdout }}" == 'true' ]; then + if [ "$INPUT_CAPTURE_STDOUT" == 'true' ]; then stdout=$(cat $_stdout) echo "stdout=${stdout//$'\n'/\\n}" >> $GITHUB_OUTPUT fi - if [ "${{ inputs.capture_stderr }}" == 'true' ]; then + if [ "$INPUT_CAPTURE_STDERR" == 'true' ]; then stderr=$(cat $_stderr) echo "stderr=${stderr//$'\n'/\\n}" >> $GITHUB_OUTPUT fi From 4819506395147258cd3fd214f7fa527fb7597863 Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 10:34:29 -0700 Subject: [PATCH 04/11] attempt tests --- .github/workflows/stable.yml | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/.github/workflows/stable.yml b/.github/workflows/stable.yml index 9209737..43f47b9 100644 --- a/.github/workflows/stable.yml +++ b/.github/workflows/stable.yml @@ -484,3 +484,65 @@ jobs: script: | whoami && echo 'hello world' && touch todo.txt sudo whoami + + testing-with-stdouterr: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: create new ssh server + run: | + docker run -d \ + --name=openssh-server \ + --hostname=openssh-server \ + -p 2222:2222 \ + -e SUDO_ACCESS=false \ + -e PASSWORD_ACCESS=true \ + -e USER_PASSWORD=password \ + -e USER_NAME=linuxserver.io \ + --restart unless-stopped \ + lscr.io/linuxserver/openssh-server:latest + docker exec openssh-server sh -c "hostname -i" > ip.txt + echo "REMOTE_HOST<> $GITHUB_ENV + cat ip.txt >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + echo "======= container ip address =========" + cat ip.txt + echo "======================================" + sleep 2 + + - name: ssh command with stdout + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{ env.REMOTE_HOST }} + username: linuxserver.io + password: password + port: 2222 + capture_stdout: 'true' + script: | + #!/usr/bin/env bash + set -e + whoami + + - name: check stdout + run: | + echo "stdout: ${{ steps.ssh-command-with-stdout.outputs.stdout }}" + + - name: ssh command with stderr + uses: appleboy/ssh-action@v1.2.0 + continue-on-error: true + with: + host: ${{ env.REMOTE_HOST }} + username: linuxserver.io + password: password + port: 2222 + capture_stderr: 'true' + script: | + #!/usr/bin/env bash + set -e + ls /root + + - name: check stderr + run: | + echo "stderr: ${{ steps.ssh-command-with-stderr.outputs.stderr }}" From bd67bfa8815808a496557497ed5cb12d09667a2f Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 11:47:21 -0700 Subject: [PATCH 05/11] remove stderr, stdout works --- .github/workflows/main.yml | 45 ++++++++++++++++++++++++++ .github/workflows/stable.yml | 62 ------------------------------------ action.yml | 6 ---- entrypoint.sh | 23 +++++-------- testdata/test.sh | 1 + 5 files changed, 54 insertions(+), 83 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6c35463..0e0fa68 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -523,3 +523,48 @@ jobs: command_timeout: 30s script: | whoami + + testing-capturing-output: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: create new ssh server + run: | + docker run -d \ + --name=openssh-server \ + --hostname=openssh-server \ + -p 2222:2222 \ + -e SUDO_ACCESS=false \ + -e PASSWORD_ACCESS=true \ + -e USER_PASSWORD=password \ + -e USER_NAME=linuxserver.io \ + --restart unless-stopped \ + lscr.io/linuxserver/openssh-server:latest + docker exec openssh-server sh -c "hostname -i" > ip.txt + echo "REMOTE_HOST<> $GITHUB_ENV + cat ip.txt >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + echo "======= container ip address =========" + cat ip.txt + echo "======================================" + sleep 2 + + - id: stdout + name: ssh command with stdout + uses: ./ + with: + host: ${{ env.REMOTE_HOST }} + username: linuxserver.io + password: password + port: 2222 + capture_stdout: 'true' + script: | + #!/usr/bin/env bash + set -e + whoami + + - name: check stdout + run: | + echo "stdout: ${{ steps.stdout.outputs.stdout }}" diff --git a/.github/workflows/stable.yml b/.github/workflows/stable.yml index 43f47b9..9209737 100644 --- a/.github/workflows/stable.yml +++ b/.github/workflows/stable.yml @@ -484,65 +484,3 @@ jobs: script: | whoami && echo 'hello world' && touch todo.txt sudo whoami - - testing-with-stdouterr: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: create new ssh server - run: | - docker run -d \ - --name=openssh-server \ - --hostname=openssh-server \ - -p 2222:2222 \ - -e SUDO_ACCESS=false \ - -e PASSWORD_ACCESS=true \ - -e USER_PASSWORD=password \ - -e USER_NAME=linuxserver.io \ - --restart unless-stopped \ - lscr.io/linuxserver/openssh-server:latest - docker exec openssh-server sh -c "hostname -i" > ip.txt - echo "REMOTE_HOST<> $GITHUB_ENV - cat ip.txt >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - echo "======= container ip address =========" - cat ip.txt - echo "======================================" - sleep 2 - - - name: ssh command with stdout - uses: appleboy/ssh-action@v1.2.0 - with: - host: ${{ env.REMOTE_HOST }} - username: linuxserver.io - password: password - port: 2222 - capture_stdout: 'true' - script: | - #!/usr/bin/env bash - set -e - whoami - - - name: check stdout - run: | - echo "stdout: ${{ steps.ssh-command-with-stdout.outputs.stdout }}" - - - name: ssh command with stderr - uses: appleboy/ssh-action@v1.2.0 - continue-on-error: true - with: - host: ${{ env.REMOTE_HOST }} - username: linuxserver.io - password: password - port: 2222 - capture_stderr: 'true' - script: | - #!/usr/bin/env bash - set -e - ls /root - - - name: check stderr - run: | - echo "stderr: ${{ steps.ssh-command-with-stderr.outputs.stderr }}" diff --git a/action.yml b/action.yml index 2811a42..2f8594c 100644 --- a/action.yml +++ b/action.yml @@ -80,15 +80,10 @@ inputs: capture_stdout: description: "Capture the stdout of the commands." default: "false" - capture_stderr: - description: "Capture the stderr of the commands." - default: "false" outputs: stdout: description: 'Standard output of the executed commands.' - stderr: - description: 'Standard error of the executed commands.' runs: using: "composite" @@ -137,7 +132,6 @@ runs: INPUT_PROXY_CIPHER: ${{ inputs.proxy_cipher }} INPUT_SYNC: ${{ inputs.sync }} INPUT_CAPTURE_STDOUT: ${{ inputs.capture_stdout }} - INPUT_CAPTURE_STDERR: ${{ inputs.capture_stderr }} branding: icon: "terminal" diff --git a/entrypoint.sh b/entrypoint.sh index 4545c53..62c1d76 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -68,27 +68,20 @@ chmod +x ${TARGET} echo "======= CLI Version =======" sh -c "${TARGET} --version" # print version echo "===========================" -if [ "$INPUT_CAPTURE_STDOUT" == 'true' ] || [ "$INPUT_CAPTURE_STDERR" == 'true' ]; then +if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then _stdout=/dev/stdout - _stderr=/dev/stderr - if [ "$INPUT_CAPTURE_STDOUT" == 'true' ]; then - _stdout=/tmp/outFile - fi - if [ "$INPUT_CAPTURE_STDERR" == 'true' ]; then - _stderr=/tmp/errFile + if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then + _stdout=/tmp/_stdout fi { sh -c "${TARGET} $*" # run the command - } 2> $_stderr | tee $_stdout + } | tee $_stdout - if [ "$INPUT_CAPTURE_STDOUT" == 'true' ]; then - stdout=$(cat $_stdout) - echo "stdout=${stdout//$'\n'/\\n}" >> $GITHUB_OUTPUT - fi - if [ "$INPUT_CAPTURE_STDERR" == 'true' ]; then - stderr=$(cat $_stderr) - echo "stderr=${stderr//$'\n'/\\n}" >> $GITHUB_OUTPUT + if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then + echo 'stdout<> $GITHUB_OUTPUT + cat $_stdout >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT fi else sh -c "${TARGET} $*" # run the command diff --git a/testdata/test.sh b/testdata/test.sh index a229cae..def0e24 100644 --- a/testdata/test.sh +++ b/testdata/test.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash set -e +echo "Hello, World!" whoami From 5ec72068f5b07c9dfd2e3342b604b07db517be79 Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 11:49:07 -0700 Subject: [PATCH 06/11] test variables --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 62c1d76..3d9c1d2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -68,6 +68,7 @@ chmod +x ${TARGET} echo "======= CLI Version =======" sh -c "${TARGET} --version" # print version echo "===========================" +echo "STDOUT: $INPUT_CAPTURE_STDOUT" if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then _stdout=/dev/stdout if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then @@ -79,6 +80,7 @@ if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then } | tee $_stdout if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then + echo 'CAPTURING STDOUT' echo 'stdout<> $GITHUB_OUTPUT cat $_stdout >> $GITHUB_OUTPUT echo 'EOF' >> $GITHUB_OUTPUT From c14811a802058978f4c5b42a75516d463fe798d3 Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 11:53:18 -0700 Subject: [PATCH 07/11] tesing --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3d9c1d2..96ec81e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -80,7 +80,8 @@ if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then } | tee $_stdout if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then - echo 'CAPTURING STDOUT' + echo "CAPTURING STDOUT $_stdout" + cat $_stdout echo 'stdout<> $GITHUB_OUTPUT cat $_stdout >> $GITHUB_OUTPUT echo 'EOF' >> $GITHUB_OUTPUT From 4188bdc3ce9e1aeffd222f17813a09fbfd34424e Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 11:59:10 -0700 Subject: [PATCH 08/11] capturing stdout --- entrypoint.sh | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 96ec81e..fca589b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -68,24 +68,10 @@ chmod +x ${TARGET} echo "======= CLI Version =======" sh -c "${TARGET} --version" # print version echo "===========================" -echo "STDOUT: $INPUT_CAPTURE_STDOUT" if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then - _stdout=/dev/stdout - if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then - _stdout=/tmp/_stdout - fi - - { - sh -c "${TARGET} $*" # run the command - } | tee $_stdout - - if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then - echo "CAPTURING STDOUT $_stdout" - cat $_stdout - echo 'stdout<> $GITHUB_OUTPUT - cat $_stdout >> $GITHUB_OUTPUT - echo 'EOF' >> $GITHUB_OUTPUT - fi + echo 'stdout<> $GITHUB_OUTPUT # use a heredoc for multiline output + sh -c "${TARGET} $*" >> $GITHUB_OUTPUT # run the command + echo 'EOF' >> $GITHUB_OUTPUT else sh -c "${TARGET} $*" # run the command fi From 058ddd1a69974c188e33f94f7d077d64e0533140 Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 12:03:35 -0700 Subject: [PATCH 09/11] test --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index fca589b..113a459 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -72,6 +72,8 @@ if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then echo 'stdout<> $GITHUB_OUTPUT # use a heredoc for multiline output sh -c "${TARGET} $*" >> $GITHUB_OUTPUT # run the command echo 'EOF' >> $GITHUB_OUTPUT + + echo 'stdout=foobar' >> $GITHUB_OUTPUT else sh -c "${TARGET} $*" # run the command fi From 210ea25b055a34b9335a3c38534c08cb0b281721 Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 12:16:14 -0700 Subject: [PATCH 10/11] cleanup --- entrypoint.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 113a459..b2a33d4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -69,11 +69,9 @@ echo "======= CLI Version =======" sh -c "${TARGET} --version" # print version echo "===========================" if [[ "$INPUT_CAPTURE_STDOUT" == 'true' ]]; then - echo 'stdout<> $GITHUB_OUTPUT # use a heredoc for multiline output + echo 'stdout<> $GITHUB_OUTPUT # use heredoc for multiline output sh -c "${TARGET} $*" >> $GITHUB_OUTPUT # run the command echo 'EOF' >> $GITHUB_OUTPUT - - echo 'stdout=foobar' >> $GITHUB_OUTPUT else sh -c "${TARGET} $*" # run the command fi From d855b8ad7c32a666d5635f17cc852dcf05f3bf04 Mon Sep 17 00:00:00 2001 From: GammaGames Date: Mon, 25 Nov 2024 12:18:08 -0700 Subject: [PATCH 11/11] cleanup --- testdata/test.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/testdata/test.sh b/testdata/test.sh index def0e24..a229cae 100644 --- a/testdata/test.sh +++ b/testdata/test.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash set -e -echo "Hello, World!" whoami