Skip to content

Commit 0ff4204

Browse files
authored
refactor: streamline output handling for GITHUB_OUTPUT in workflows (#404)
* refactor: streamline output handling for GITHUB_OUTPUT in workflows - Write the stdout<<EOF and EOF markers directly to GITHUB_OUTPUT instead of using a group command - Simplify the process for capturing and appending command output to GITHUB_OUTPUT fix #403 fix #397 Signed-off-by: appleboy <appleboy.tw@gmail.com> * test: enhance stdout capture and verification in tests - Add a check to ensure captured stdout is not empty - Add steps to capture and verify multiline stdout output - Add verification that specific lines and the username are present in captured output - Add steps to handle and verify stdout containing special characters and file paths Signed-off-by: appleboy <appleboy.tw@gmail.com> * ci: enforce unique occurrence of lines in multiline output validation - Add a step to verify that lines "Line 1", "Line 2", and "Line 3" each appear exactly once in the multiline output - Fail the workflow if any line is missing or duplicated - Confirm successful validation with a message when no duplicates are found Signed-off-by: appleboy <appleboy.tw@gmail.com> --------- Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 8e460a2 commit 0ff4204

File tree

2 files changed

+99
-5
lines changed

2 files changed

+99
-5
lines changed

.github/workflows/main.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,102 @@ jobs:
609609
- name: check stdout
610610
run: |
611611
echo "stdout: ${{ steps.stdout.outputs.stdout }}"
612+
if [ -z "${{ steps.stdout.outputs.stdout }}" ]; then
613+
echo "Error: stdout is empty"
614+
exit 1
615+
fi
616+
617+
- id: stdout-multiline
618+
name: capture multiline output
619+
uses: ./
620+
with:
621+
host: ${{ env.REMOTE_HOST }}
622+
username: linuxserver.io
623+
password: password
624+
port: 2222
625+
capture_stdout: true
626+
script: |
627+
#!/usr/bin/env bash
628+
set -e
629+
echo "Line 1"
630+
echo "Line 2"
631+
echo "Line 3"
632+
whoami
633+
pwd
634+
635+
- name: check multiline output
636+
run: |
637+
echo "stdout: ${{ steps.stdout-multiline.outputs.stdout }}"
638+
# Check if all lines are present
639+
if ! echo "${{ steps.stdout-multiline.outputs.stdout }}" | grep -q "Line 1"; then
640+
echo "Error: 'Line 1' not found in output"
641+
exit 1
642+
fi
643+
if ! echo "${{ steps.stdout-multiline.outputs.stdout }}" | grep -q "Line 2"; then
644+
echo "Error: 'Line 2' not found in output"
645+
exit 1
646+
fi
647+
if ! echo "${{ steps.stdout-multiline.outputs.stdout }}" | grep -q "Line 3"; then
648+
echo "Error: 'Line 3' not found in output"
649+
exit 1
650+
fi
651+
if ! echo "${{ steps.stdout-multiline.outputs.stdout }}" | grep -q "linuxserver.io"; then
652+
echo "Error: username not found in output"
653+
exit 1
654+
fi
655+
656+
# Check for duplicates - each unique line should appear exactly once
657+
OUTPUT="${{ steps.stdout-multiline.outputs.stdout }}"
658+
LINE1_COUNT=$(echo "$OUTPUT" | grep -c "^Line 1$" || true)
659+
LINE2_COUNT=$(echo "$OUTPUT" | grep -c "^Line 2$" || true)
660+
LINE3_COUNT=$(echo "$OUTPUT" | grep -c "^Line 3$" || true)
661+
662+
echo "Line 1 count: $LINE1_COUNT"
663+
echo "Line 2 count: $LINE2_COUNT"
664+
echo "Line 3 count: $LINE3_COUNT"
665+
666+
if [ "$LINE1_COUNT" -ne 1 ]; then
667+
echo "Error: 'Line 1' appears $LINE1_COUNT times (expected 1)"
668+
exit 1
669+
fi
670+
if [ "$LINE2_COUNT" -ne 1 ]; then
671+
echo "Error: 'Line 2' appears $LINE2_COUNT times (expected 1)"
672+
exit 1
673+
fi
674+
if [ "$LINE3_COUNT" -ne 1 ]; then
675+
echo "Error: 'Line 3' appears $LINE3_COUNT times (expected 1)"
676+
exit 1
677+
fi
678+
679+
echo "✓ No duplicate lines detected"
680+
681+
- id: stdout-with-special-chars
682+
name: capture output with special characters
683+
uses: ./
684+
with:
685+
host: ${{ env.REMOTE_HOST }}
686+
username: linuxserver.io
687+
password: password
688+
port: 2222
689+
capture_stdout: true
690+
script: |
691+
#!/usr/bin/env bash
692+
set -e
693+
echo "Test with special chars: @#$%^&*()"
694+
echo "Path: /home/user/test"
695+
echo "JSON: {\"key\": \"value\"}"
696+
697+
- name: check special characters output
698+
run: |
699+
echo "stdout: ${{ steps.stdout-with-special-chars.outputs.stdout }}"
700+
if ! echo "${{ steps.stdout-with-special-chars.outputs.stdout }}" | grep -q "special chars"; then
701+
echo "Error: special characters test failed"
702+
exit 1
703+
fi
704+
if ! echo "${{ steps.stdout-with-special-chars.outputs.stdout }}" | grep -q "/home/user/test"; then
705+
echo "Error: path not found in output"
706+
exit 1
707+
fi
612708
613709
testing-script-stop:
614710
runs-on: ubuntu-latest

entrypoint.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ if ! "${TARGET}" --version; then
7171
fi
7272
echo "======================================="
7373
if [[ "${INPUT_CAPTURE_STDOUT}" == 'true' ]]; then
74-
{
75-
echo 'stdout<<EOF'
76-
"${TARGET}" "$@" | tee -a "${GITHUB_OUTPUT}"
77-
echo 'EOF'
78-
} >>"${GITHUB_OUTPUT}"
74+
echo 'stdout<<EOF' >> "${GITHUB_OUTPUT}"
75+
"${TARGET}" "$@" | tee -a "${GITHUB_OUTPUT}"
76+
echo 'EOF' >> "${GITHUB_OUTPUT}"
7977
else
8078
"${TARGET}" "$@"
8179
fi

0 commit comments

Comments
 (0)