From 0ff4204d59e8e51228ff73bce53f80d53301dee2 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 28 Jan 2026 10:18:18 +0800 Subject: [PATCH] refactor: streamline output handling for GITHUB_OUTPUT in workflows (#404) * refactor: streamline output handling for GITHUB_OUTPUT in workflows - Write the stdout< * 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 * 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 --------- Signed-off-by: appleboy --- .github/workflows/main.yml | 96 ++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 8 ++-- 2 files changed, 99 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aa01707..753a0a6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -609,6 +609,102 @@ jobs: - name: check stdout run: | echo "stdout: ${{ steps.stdout.outputs.stdout }}" + if [ -z "${{ steps.stdout.outputs.stdout }}" ]; then + echo "Error: stdout is empty" + exit 1 + fi + + - id: stdout-multiline + name: capture multiline output + uses: ./ + with: + host: ${{ env.REMOTE_HOST }} + username: linuxserver.io + password: password + port: 2222 + capture_stdout: true + script: | + #!/usr/bin/env bash + set -e + echo "Line 1" + echo "Line 2" + echo "Line 3" + whoami + pwd + + - name: check multiline output + run: | + echo "stdout: ${{ steps.stdout-multiline.outputs.stdout }}" + # Check if all lines are present + if ! echo "${{ steps.stdout-multiline.outputs.stdout }}" | grep -q "Line 1"; then + echo "Error: 'Line 1' not found in output" + exit 1 + fi + if ! echo "${{ steps.stdout-multiline.outputs.stdout }}" | grep -q "Line 2"; then + echo "Error: 'Line 2' not found in output" + exit 1 + fi + if ! echo "${{ steps.stdout-multiline.outputs.stdout }}" | grep -q "Line 3"; then + echo "Error: 'Line 3' not found in output" + exit 1 + fi + if ! echo "${{ steps.stdout-multiline.outputs.stdout }}" | grep -q "linuxserver.io"; then + echo "Error: username not found in output" + exit 1 + fi + + # Check for duplicates - each unique line should appear exactly once + OUTPUT="${{ steps.stdout-multiline.outputs.stdout }}" + LINE1_COUNT=$(echo "$OUTPUT" | grep -c "^Line 1$" || true) + LINE2_COUNT=$(echo "$OUTPUT" | grep -c "^Line 2$" || true) + LINE3_COUNT=$(echo "$OUTPUT" | grep -c "^Line 3$" || true) + + echo "Line 1 count: $LINE1_COUNT" + echo "Line 2 count: $LINE2_COUNT" + echo "Line 3 count: $LINE3_COUNT" + + if [ "$LINE1_COUNT" -ne 1 ]; then + echo "Error: 'Line 1' appears $LINE1_COUNT times (expected 1)" + exit 1 + fi + if [ "$LINE2_COUNT" -ne 1 ]; then + echo "Error: 'Line 2' appears $LINE2_COUNT times (expected 1)" + exit 1 + fi + if [ "$LINE3_COUNT" -ne 1 ]; then + echo "Error: 'Line 3' appears $LINE3_COUNT times (expected 1)" + exit 1 + fi + + echo "✓ No duplicate lines detected" + + - id: stdout-with-special-chars + name: capture output with special characters + uses: ./ + with: + host: ${{ env.REMOTE_HOST }} + username: linuxserver.io + password: password + port: 2222 + capture_stdout: true + script: | + #!/usr/bin/env bash + set -e + echo "Test with special chars: @#$%^&*()" + echo "Path: /home/user/test" + echo "JSON: {\"key\": \"value\"}" + + - name: check special characters output + run: | + echo "stdout: ${{ steps.stdout-with-special-chars.outputs.stdout }}" + if ! echo "${{ steps.stdout-with-special-chars.outputs.stdout }}" | grep -q "special chars"; then + echo "Error: special characters test failed" + exit 1 + fi + if ! echo "${{ steps.stdout-with-special-chars.outputs.stdout }}" | grep -q "/home/user/test"; then + echo "Error: path not found in output" + exit 1 + fi testing-script-stop: runs-on: ubuntu-latest diff --git a/entrypoint.sh b/entrypoint.sh index d5d56b6..123c26d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -71,11 +71,9 @@ if ! "${TARGET}" --version; then fi echo "=======================================" if [[ "${INPUT_CAPTURE_STDOUT}" == 'true' ]]; then - { - echo 'stdout<>"${GITHUB_OUTPUT}" + echo 'stdout<> "${GITHUB_OUTPUT}" + "${TARGET}" "$@" | tee -a "${GITHUB_OUTPUT}" + echo 'EOF' >> "${GITHUB_OUTPUT}" else "${TARGET}" "$@" fi