From 336952b864c3ac05a459fcb6a1e811ebe455fade Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Thu, 2 Oct 2025 19:43:25 -0400 Subject: [PATCH 01/69] Create scripts.yaml --- .github/workflows/scripts.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/scripts.yaml diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml new file mode 100644 index 0000000..1ed6111 --- /dev/null +++ b/.github/workflows/scripts.yaml @@ -0,0 +1,15 @@ +# Test the scripts. + +on: + pull_request: + branches: + - main + +jobs: + + run-with-summary: + runs-on: ubuntu-latest + steps: + - name: run-with-summary + run: | + ./src/run-with-summary ping google.com -5 From 22e77a74be1ec91081442963efef0883f8261012 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Thu, 2 Oct 2025 21:42:58 -0400 Subject: [PATCH 02/69] Update scripts.yaml --- .github/workflows/scripts.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 1ed6111..b7bc74e 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -10,6 +10,7 @@ jobs: run-with-summary: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - name: run-with-summary run: | ./src/run-with-summary ping google.com -5 From d7943128aef8b653a7aea264d13ef115ba21a3ec Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:09:57 -0400 Subject: [PATCH 03/69] Format dates properly. --- src/run-with-summary | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index c6f7686..ebadd7e 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -36,6 +36,9 @@ format_output() { local start_time="$4" local end_time="$5" local duration=$((end_time - start_time)) + + local start_date=$(date -d "@$start_time" '+%Y-%m-%d %H:%M:%S %Z' 2>/dev/null || date -r $start_time '+%Y-%m-%d %H:%M:%S %Z') + local end_date=$(date -d "@$end_time" '+%Y-%m-%d %H:%M:%S %Z' 2>/dev/null || date -r $end_time '+%Y-%m-%d %H:%M:%S %Z') local heading_message="$error_message" if [ "$exit_code" -eq 0 ]; then @@ -54,8 +57,8 @@ format_output() { echo "| Command | \`$command\`" echo "|------------|-----------------------" echo "| Exit Code | \`$exit_code\`" - echo "| Start Time | $(date -r $start_time '+%Y-%m-%d %H:%M:%S %Z')" - echo "| End Time | $(date -r $end_time '+%Y-%m-%d %H:%M:%S %Z')" + echo "| Start Time | $start_date" + echo "| End Time | $start_date" echo "| Duration | ${duration}s" if [[ -n $debug ]]; then @@ -85,7 +88,7 @@ start_time=$(date '+%s') # Execute command and show output in real time while capturing it echo "Executing: $command" set -o pipefail -output=$(eval "$command" 2>&1 | tee >(cat >&2)) +output=$(eval "$command" 2>&1 | tr -d '\r' | tee >(cat >&2)) exit_code=$? # Record end time From 58b6bb61be20396dadd1adbfdcca298417718466 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:13:42 -0400 Subject: [PATCH 04/69] New attempt at realtime output. --- src/run-with-summary | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index ebadd7e..890915b 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -87,9 +87,18 @@ start_time=$(date '+%s') # Execute command and show output in real time while capturing it echo "Executing: $command" -set -o pipefail -output=$(eval "$command" 2>&1 | tr -d '\r' | tee >(cat >&2)) -exit_code=$? + +# Use a temporary file to store output +temp_output_file=$(mktemp) + +# Execute command and capture output while displaying it +$command 2>&1 | tee "$temp_output_file" +exit_code=${PIPESTATUS[0]} + +# Read the output from temporary file +output=$(<"$temp_output_file") +rm "$temp_output_file" + # Record end time end_time=$(date '+%s') From 84a5c811c52760209b52daabdb16bece988fc0b7 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:14:22 -0400 Subject: [PATCH 05/69] Fix script run. --- .github/workflows/scripts.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index b7bc74e..b34db7a 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -11,6 +11,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: run-with-summary + - name: run-with-summary + env: + SUCCESS: "Pinging Google Passed" + FAILURE: "Ping Failed" + SUMMARY: yes run: | - ./src/run-with-summary ping google.com -5 + ./src/run-with-summary ping google.com -n5 From d703a31e4c5d9ffbb858656688d099d6e6ddd82c Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:26:55 -0400 Subject: [PATCH 06/69] Add FILE env var, better example. --- src/run-with-summary | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index 890915b..6baf948 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -9,22 +9,30 @@ debug=${DEBUG:-""} # Print the markdown summary after the command output. echo_summary=${SUMMARY:-""} +temp_report_file=${FILE:-""} usage() { cat <<'USAGE' -Usage: run-with-summary [options] -- +Usage: run-with-summary -Executes the given command, streams its output, and writes a Markdown summary to /tmp/summary.md. +Executes the given command, streams its output, and writes a Markdown summary to $FILE. Environment variables: SUCCESS Custom success heading (default: "Command executed"). ERROR Custom error heading (default: "Command failed"). DEBUG If set (non-empty), include User/Host/Directory in the summary. SUMMARY If set (non-empty), echo the Markdown summary to stdout after execution. + FILE Markdown report file (default: /tmp/summary.md Examples: run-with-summary ls -la - SUCCESS="Deploy complete" SUMMARY=1 run-with-summary -- make deploy + + SUCCESS="Deploy complete" \ + ERROR="Deploy failed" \ + DEBUG=1 \ + SUMMARY=1 \ + run-with-summary ping w3.org -c3 + USAGE } @@ -105,12 +113,12 @@ end_time=$(date '+%s') # Generate markdown report formatted_output=$(format_output "$command" "$output" "$exit_code" "$start_time" "$end_time") -echo "$formatted_output" > /tmp/summary.md +echo "$formatted_output" > $temp_report_file if [[ -n $echo_summary ]]; then echo "$formatted_output" fi echo -echo "Markdown report saved to /tmp/summary.md" +echo "Markdown report saved to $temp_report_file" exit "$exit_code" \ No newline at end of file From 8f901959446771af460fd0b66488ba347ddeed16 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:28:30 -0400 Subject: [PATCH 07/69] Add FILE env var, better example. --- README.md | 64 ++++++++++++++++++++++++++++---------------- src/run-with-summary | 4 +-- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index af7193c..9ba7c30 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,60 @@ # goatscripts Bash to basics. -# Example +# Run With Summary + +`run-with-summary ` + +## Example ```shell -run-with-summary ping google.com -c2 +SUCCESS="Deploy complete" \ +ERROR="Deploy failed" \ +DEBUG=1 \ +SUMMARY=1 \ + run-with-summary ping w3.org -c3 ``` -DEBUG=1 SUMMARY=1 ./src/run-with-summary ping google.com -c2 -PING google.com (142.250.81.238): 56 data bytes -64 bytes from 142.250.81.238: icmp_seq=0 ttl=119 time=10.933 ms -64 bytes from 142.250.81.238: icmp_seq=1 ttl=119 time=9.472 ms - ---- google.com ping statistics --- -2 packets transmitted, 2 packets received, 0.0% packet loss -round-trip min/avg/max/stddev = 9.472/10.203/10.933/0.730 ms -# Command executed + +## Output +```shell +Executing: ping w3.org -c5 +PING w3.org (104.18.22.19): 56 data bytes +64 bytes from 104.18.22.19: icmp_seq=0 ttl=59 time=9.480 ms +64 bytes from 104.18.22.19: icmp_seq=1 ttl=59 time=13.510 ms +64 bytes from 104.18.22.19: icmp_seq=2 ttl=59 time=12.989 ms +64 bytes from 104.18.22.19: icmp_seq=3 ttl=59 time=15.017 ms +64 bytes from 104.18.22.19: icmp_seq=4 ttl=59 time=13.225 ms + +--- w3.org ping statistics --- +5 packets transmitted, 5 packets received, 0.0% packet loss +round-trip min/avg/max/stddev = 9.480/12.844/15.017/1.825 ms +# Deploy complete ``` -ping google.com -c2 +ping w3.org -c5 ``` ``` -PING google.com (142.250.81.238): 56 data bytes -64 bytes from 142.250.81.238: icmp_seq=0 ttl=119 time=10.933 ms -64 bytes from 142.250.81.238: icmp_seq=1 ttl=119 time=9.472 ms +PING w3.org (104.18.22.19): 56 data bytes +64 bytes from 104.18.22.19: icmp_seq=0 ttl=59 time=9.480 ms +64 bytes from 104.18.22.19: icmp_seq=1 ttl=59 time=13.510 ms +64 bytes from 104.18.22.19: icmp_seq=2 ttl=59 time=12.989 ms +64 bytes from 104.18.22.19: icmp_seq=3 ttl=59 time=15.017 ms +64 bytes from 104.18.22.19: icmp_seq=4 ttl=59 time=13.225 ms ---- google.com ping statistics --- -2 packets transmitted, 2 packets received, 0.0% packet loss -round-trip min/avg/max/stddev = 9.472/10.203/10.933/0.730 ms +--- w3.org ping statistics --- +5 packets transmitted, 5 packets received, 0.0% packet loss +round-trip min/avg/max/stddev = 9.480/12.844/15.017/1.825 ms ``` -| Command | `ping google.com -c2` +| Command | `ping w3.org -c5` |------------|----------------------- | Exit Code | `0` -| Start Time | 2025-10-02 21:10:48 EDT -| End Time | 2025-10-02 21:10:49 EDT -| Duration | 1s +| Start Time | 2025-10-03 07:24:40 EDT +| End Time | 2025-10-03 07:24:40 EDT +| Duration | 4s | User | jonpugh | Host | macbookpro.lan | Directory | /Users/jonpugh/Work/Operations/goatscripts -Markdown report saved to /tmp/summary.md \ No newline at end of file +Markdown report saved to /tmp/summary.md +``` diff --git a/src/run-with-summary b/src/run-with-summary index 6baf948..407aad1 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -27,8 +27,8 @@ Environment variables: Examples: run-with-summary ls -la - SUCCESS="Deploy complete" \ - ERROR="Deploy failed" \ + SUCCESS="w3.org is online" \ + ERROR="w3.org unavailable!" \ DEBUG=1 \ SUMMARY=1 \ run-with-summary ping w3.org -c3 From 35b1b88e2dd61908178e496902c8d78194988c62 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:30:19 -0400 Subject: [PATCH 08/69] Better readme. --- README.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9ba7c30..57151c0 100644 --- a/README.md +++ b/README.md @@ -16,18 +16,9 @@ SUMMARY=1 \ ``` ## Output -```shell -Executing: ping w3.org -c5 -PING w3.org (104.18.22.19): 56 data bytes -64 bytes from 104.18.22.19: icmp_seq=0 ttl=59 time=9.480 ms -64 bytes from 104.18.22.19: icmp_seq=1 ttl=59 time=13.510 ms -64 bytes from 104.18.22.19: icmp_seq=2 ttl=59 time=12.989 ms -64 bytes from 104.18.22.19: icmp_seq=3 ttl=59 time=15.017 ms -64 bytes from 104.18.22.19: icmp_seq=4 ttl=59 time=13.225 ms ---- w3.org ping statistics --- -5 packets transmitted, 5 packets received, 0.0% packet loss -round-trip min/avg/max/stddev = 9.480/12.844/15.017/1.825 ms +This script renders the output of the command and a summary using markdown syntax. + # Deploy complete ``` ping w3.org -c5 @@ -57,4 +48,3 @@ round-trip min/avg/max/stddev = 9.480/12.844/15.017/1.825 ms | Directory | /Users/jonpugh/Work/Operations/goatscripts Markdown report saved to /tmp/summary.md -``` From 492a9685a517a963b25cdd03ef56cf09e1728ea5 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:31:36 -0400 Subject: [PATCH 09/69] Export to file and print to summary. --- .github/workflows/scripts.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index b34db7a..c2f690c 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -16,5 +16,7 @@ jobs: SUCCESS: "Pinging Google Passed" FAILURE: "Ping Failed" SUMMARY: yes + FILE: report-${{ github.run_id }}.md run: | ./src/run-with-summary ping google.com -n5 + cat $FILE >> $GITHUB_STEP_SUMMARY From ccaca9d470a277819f5bb8a4d96673a2fbcef9b6 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:32:17 -0400 Subject: [PATCH 10/69] file? --- .github/workflows/scripts.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index c2f690c..4e0040f 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -19,4 +19,5 @@ jobs: FILE: report-${{ github.run_id }}.md run: | ./src/run-with-summary ping google.com -n5 + ls -la $FILE cat $FILE >> $GITHUB_STEP_SUMMARY From 50eb572d8b929fe76bdcb9166c29e7529ec639e3 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:33:56 -0400 Subject: [PATCH 11/69] Don't errr --- .github/workflows/scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 4e0040f..ddbb8a5 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -18,6 +18,6 @@ jobs: SUMMARY: yes FILE: report-${{ github.run_id }}.md run: | - ./src/run-with-summary ping google.com -n5 + ./src/run-with-summary ping google.com -c5 ls -la $FILE cat $FILE >> $GITHUB_STEP_SUMMARY From 8bf9f6a1b83ae8e623f4c610395bdf5b71d22a32 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:39:02 -0400 Subject: [PATCH 12/69] Error code capture not happening on github. --- src/run-with-summary | 1 + 1 file changed, 1 insertion(+) diff --git a/src/run-with-summary b/src/run-with-summary index 407aad1..2c21396 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -100,6 +100,7 @@ echo "Executing: $command" temp_output_file=$(mktemp) # Execute command and capture output while displaying it +set -o pipefail $command 2>&1 | tee "$temp_output_file" exit_code=${PIPESTATUS[0]} From 3aeca69bda288d8c482632062acda0e46f538499 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:39:22 -0400 Subject: [PATCH 13/69] Change url to ping in tests. --- .github/workflows/scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index ddbb8a5..cec9c42 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -18,6 +18,6 @@ jobs: SUMMARY: yes FILE: report-${{ github.run_id }}.md run: | - ./src/run-with-summary ping google.com -c5 + ./src/run-with-summary ping w3.org -c5 ls -la $FILE cat $FILE >> $GITHUB_STEP_SUMMARY From 361bd6f9bd183a0346d04d053a5526f8eceb27cc Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:39:47 -0400 Subject: [PATCH 14/69] Don't announce the command. --- src/run-with-summary | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index 2c21396..595d8ef 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -94,8 +94,6 @@ fi start_time=$(date '+%s') # Execute command and show output in real time while capturing it -echo "Executing: $command" - # Use a temporary file to store output temp_output_file=$(mktemp) From ec50f562859297be58920c4da9291206461c0e60 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:47:55 -0400 Subject: [PATCH 15/69] Print summary even if failed. --- .github/workflows/scripts.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index cec9c42..71705bc 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -12,6 +12,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: run-with-summary + continue-on-error: true env: SUCCESS: "Pinging Google Passed" FAILURE: "Ping Failed" @@ -19,5 +20,11 @@ jobs: FILE: report-${{ github.run_id }}.md run: | ./src/run-with-summary ping w3.org -c5 - ls -la $FILE + + - name: Print Summary + run: | cat $FILE >> $GITHUB_STEP_SUMMARY + + - name: Exit + if: failure() + run: exit 1 \ No newline at end of file From d56f1ded307cbb38bf768170a0262bf0bd4a8b7a Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:49:41 -0400 Subject: [PATCH 16/69] Fix summary saving. --- .github/workflows/scripts.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 71705bc..4a3ae55 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -9,6 +9,9 @@ jobs: run-with-summary: runs-on: ubuntu-latest + env: + FILE: report-${{ github.run_id }}.md + steps: - uses: actions/checkout@v4 - name: run-with-summary @@ -17,7 +20,6 @@ jobs: SUCCESS: "Pinging Google Passed" FAILURE: "Ping Failed" SUMMARY: yes - FILE: report-${{ github.run_id }}.md run: | ./src/run-with-summary ping w3.org -c5 From 627d7aac6fdda55f741254784cdb0da54a41e237 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:53:36 -0400 Subject: [PATCH 17/69] Use bash to catch exit and print to summary. --- .github/workflows/scripts.yaml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 4a3ae55..2f459bb 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -15,18 +15,13 @@ jobs: steps: - uses: actions/checkout@v4 - name: run-with-summary - continue-on-error: true env: SUCCESS: "Pinging Google Passed" FAILURE: "Ping Failed" SUMMARY: yes run: | + set -eo pipefail ./src/run-with-summary ping w3.org -c5 - - - name: Print Summary - run: | + exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY - - - name: Exit - if: failure() - run: exit 1 \ No newline at end of file + exit $exit_code From b91f75711d0ee7087044cc9d3d12d6dd5d747032 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:55:04 -0400 Subject: [PATCH 18/69] Make sure script can't fail. --- .github/workflows/scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 2f459bb..86adeb4 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -21,7 +21,7 @@ jobs: SUMMARY: yes run: | set -eo pipefail - ./src/run-with-summary ping w3.org -c5 + ./src/run-with-summary ping w3.org -c5 | echo "" exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY exit $exit_code From 949610f003851a1ebc48ff26ba8adf17130fbfcd Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:55:51 -0400 Subject: [PATCH 19/69] or --- .github/workflows/scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 86adeb4..4818692 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -21,7 +21,7 @@ jobs: SUMMARY: yes run: | set -eo pipefail - ./src/run-with-summary ping w3.org -c5 | echo "" + ./src/run-with-summary ping w3.org -c5 || echo "" exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY exit $exit_code From 05bdc226744cae32124c88de9ae37f59a4c04ca5 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 07:57:35 -0400 Subject: [PATCH 20/69] Set +e so the script fail doesn't fail the step. --- .github/workflows/scripts.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 4818692..9482900 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -20,8 +20,9 @@ jobs: FAILURE: "Ping Failed" SUMMARY: yes run: | - set -eo pipefail - ./src/run-with-summary ping w3.org -c5 || echo "" + set -o pipefail + set +e + ./src/run-with-summary ping w3.org -c5 exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY exit $exit_code From 16ca3811f76434203f2ec53e3ca898c71eaeeed2 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:00:54 -0400 Subject: [PATCH 21/69] Add a non-failing job. --- .github/workflows/scripts.yaml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 9482900..c945526 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -9,16 +9,33 @@ jobs: run-with-summary: runs-on: ubuntu-latest + + # Settings for run-with-summary script. env: FILE: report-${{ github.run_id }}.md + SUCCESS: "Ping Successful" + FAILURE: "Ping Failed" + SUMMARY: yes steps: - uses: actions/checkout@v4 - name: run-with-summary - env: - SUCCESS: "Pinging Google Passed" - FAILURE: "Ping Failed" - SUMMARY: yes + run: | + set -o pipefail + set +e + ./src/run-with-summary ping github.com -c5 + exit_code=$? + cat $FILE >> $GITHUB_STEP_SUMMARY + exit $exit_code + + run-with-summary-fail: + runs-on: ubuntu-latest + env: + FILE: report-${{ github.run_id }}.md + + steps: + - uses: actions/checkout@v4 + - name: run-with-summary failure run: | set -o pipefail set +e From e8d3b1e83d0245af5ff9c4c5e4aad49af1f174ce Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:03:56 -0400 Subject: [PATCH 22/69] Allow pipes --- src/run-with-summary | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run-with-summary b/src/run-with-summary index 595d8ef..c701da3 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -99,7 +99,7 @@ temp_output_file=$(mktemp) # Execute command and capture output while displaying it set -o pipefail -$command 2>&1 | tee "$temp_output_file" +eval "$command" 2>&1 | tee "$temp_output_file" exit_code=${PIPESTATUS[0]} # Read the output from temporary file From ec3e42402608006f519fb98a97c8b6c252aa0c1f Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:08:26 -0400 Subject: [PATCH 23/69] Get a failure check working. --- .github/workflows/scripts.yaml | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index c945526..892e73f 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -5,28 +5,25 @@ on: branches: - main +# Settings for run-with-summary script. +env: + FILE: report-${{ github.run_id }}.md + SUMMARY: yes + jobs: run-with-summary: runs-on: ubuntu-latest - - # Settings for run-with-summary script. - env: - FILE: report-${{ github.run_id }}.md - SUCCESS: "Ping Successful" - FAILURE: "Ping Failed" - SUMMARY: yes - steps: - uses: actions/checkout@v4 - name: run-with-summary run: | set -o pipefail set +e - ./src/run-with-summary ping github.com -c5 + ./src/run-with-summary ps -a exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY - exit $exit_code + echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV run-with-summary-fail: runs-on: ubuntu-latest @@ -39,7 +36,16 @@ jobs: run: | set -o pipefail set +e - ./src/run-with-summary ping w3.org -c5 + ./src/run-with-summary ping w3.org -c1 exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY - exit $exit_code + echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV + + - name: Exit + run: | + if [ "$EXIT_CODE" -eq 0 ]; then + echo "Exit code is not 0, as expected." + else + echo "Exit code was expected to fail. Something is wrong." + exit 1 + fi From d4e682fc6f9d368d4d5d78e0769a85b16ed4857f Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:10:02 -0400 Subject: [PATCH 24/69] Get a failure check working. --- .github/workflows/scripts.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 892e73f..a5e31d8 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -41,11 +41,11 @@ jobs: cat $FILE >> $GITHUB_STEP_SUMMARY echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV - - name: Exit run: | - if [ "$EXIT_CODE" -eq 0 ]; then - echo "Exit code is not 0, as expected." - else - echo "Exit code was expected to fail. Something is wrong." + if [ "$EXIT_CODE" == "0" ]; then + echo "Script was expected to fail. Something is wrong." exit 1 + else + echo "Exit code is not 0, as expected." fi + - name: Exit From 515e389819c58d9c96bf42783a8532a64e690b18 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:10:38 -0400 Subject: [PATCH 25/69] Get a failure check working. --- .github/workflows/scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index a5e31d8..3b1f43f 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -40,7 +40,7 @@ jobs: exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV - + - name: exit run: | if [ "$EXIT_CODE" == "0" ]; then echo "Script was expected to fail. Something is wrong." From 83c17a7ab9da19a609896d0beb4def609333d405 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:11:02 -0400 Subject: [PATCH 26/69] Get a failure check working. --- .github/workflows/scripts.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 3b1f43f..f74eee7 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -48,4 +48,3 @@ jobs: else echo "Exit code is not 0, as expected." fi - - name: Exit From 1c5ad599cac823069c6d4845d86f915ffa52dea3 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:11:45 -0400 Subject: [PATCH 27/69] This one should pass. --- .github/workflows/scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index f74eee7..d7ba4b4 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -23,7 +23,7 @@ jobs: ./src/run-with-summary ps -a exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY - echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV + exit $exit_code run-with-summary-fail: runs-on: ubuntu-latest From e9053c418c0d81d6a676ce30ba7b0c82358e5de1 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:13:51 -0400 Subject: [PATCH 28/69] Fix messages and exits --- .github/workflows/scripts.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index d7ba4b4..d537645 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -17,6 +17,9 @@ jobs: steps: - uses: actions/checkout@v4 - name: run-with-summary + env: + SUCCESS: "Test Command Succeeded :check:" + ERROR: "Test Command Failed! :x:" run: | set -o pipefail set +e @@ -27,12 +30,12 @@ jobs: run-with-summary-fail: runs-on: ubuntu-latest - env: - FILE: report-${{ github.run_id }}.md - steps: - uses: actions/checkout@v4 - name: run-with-summary failure + env: + SUCCESS: "Ping Succeeded :check:" + ERROR: "Ping Failed :x:" run: | set -o pipefail set +e From d83bd7bdac55729d74df1cce1d78a0c2a69b4ecc Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:15:11 -0400 Subject: [PATCH 29/69] Fix messages and exits --- .github/workflows/scripts.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index d537645..bdd8505 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -23,7 +23,7 @@ jobs: run: | set -o pipefail set +e - ./src/run-with-summary ps -a + ./src/run-with-summary ls -la exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY exit $exit_code @@ -35,7 +35,7 @@ jobs: - name: run-with-summary failure env: SUCCESS: "Ping Succeeded :check:" - ERROR: "Ping Failed :x:" + ERROR: "Ping Failed, as expected :x:" run: | set -o pipefail set +e From 608892ed7b6359a75db0b3195eae0421e4cecdde Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:16:17 -0400 Subject: [PATCH 30/69] Wrong variable. --- src/run-with-summary | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run-with-summary b/src/run-with-summary index c701da3..10324e6 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -66,7 +66,7 @@ format_output() { echo "|------------|-----------------------" echo "| Exit Code | \`$exit_code\`" echo "| Start Time | $start_date" - echo "| End Time | $start_date" + echo "| End Time | $end_date" echo "| Duration | ${duration}s" if [[ -n $debug ]]; then From ac568a1eeb045e5c67d9358fefb9f21c6c14cfdc Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:29:39 -0400 Subject: [PATCH 31/69] Use debug --- .github/workflows/scripts.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index bdd8505..7125f74 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -9,6 +9,7 @@ on: env: FILE: report-${{ github.run_id }}.md SUMMARY: yes + DEBUG: yes jobs: From b64cdab71a4eeb702337037439d47854c837b353 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:30:19 -0400 Subject: [PATCH 32/69] Name the github --- .github/workflows/scripts.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.yaml index 7125f74..20039d7 100644 --- a/.github/workflows/scripts.yaml +++ b/.github/workflows/scripts.yaml @@ -1,5 +1,5 @@ # Test the scripts. - +name: Run with Summary on: pull_request: branches: From 747e9714ebdb567b1cb89141c772e3c358198516 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:30:55 -0400 Subject: [PATCH 33/69] Renamed --- .github/workflows/{scripts.yaml => scripts.run-with-summary.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{scripts.yaml => scripts.run-with-summary.yml} (100%) diff --git a/.github/workflows/scripts.yaml b/.github/workflows/scripts.run-with-summary.yml similarity index 100% rename from .github/workflows/scripts.yaml rename to .github/workflows/scripts.run-with-summary.yml From fbcd9ec06bfd308898862d47188d190441b09f99 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:32:53 -0400 Subject: [PATCH 34/69] Proper emoji. --- .github/workflows/scripts.run-with-summary.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index 20039d7..ad5807c 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v4 - name: run-with-summary env: - SUCCESS: "Test Command Succeeded :check:" + SUCCESS: "Test Command Succeeded :white_check_mark:" ERROR: "Test Command Failed! :x:" run: | set -o pipefail @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v4 - name: run-with-summary failure env: - SUCCESS: "Ping Succeeded :check:" + SUCCESS: "Ping Succeeded :white_check_mark:" ERROR: "Ping Failed, as expected :x:" run: | set -o pipefail From 547d17c2ff4e047becdf834b1fa6280a0fcb1b43 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:34:30 -0400 Subject: [PATCH 35/69] Simpler failure command. --- .github/workflows/scripts.run-with-summary.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index ad5807c..1346122 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -35,12 +35,12 @@ jobs: - uses: actions/checkout@v4 - name: run-with-summary failure env: - SUCCESS: "Ping Succeeded :white_check_mark:" - ERROR: "Ping Failed, as expected :x:" + SUCCESS: "Command Succeeded :white_check_mark:" + ERROR: "Command Failed, as expected :x:" run: | set -o pipefail set +e - ./src/run-with-summary ping w3.org -c1 + ./src/run-with-summary not-a-command exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV From 17eb22135ca7c3502dc619aa0cc203481c00cda3 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:35:52 -0400 Subject: [PATCH 36/69] Set path. --- .github/workflows/scripts.run-with-summary.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index 1346122..f32213c 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -10,6 +10,7 @@ env: FILE: report-${{ github.run_id }}.md SUMMARY: yes DEBUG: yes + PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin jobs: @@ -24,7 +25,7 @@ jobs: run: | set -o pipefail set +e - ./src/run-with-summary ls -la + run-with-summary ls -la exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY exit $exit_code @@ -40,7 +41,7 @@ jobs: run: | set -o pipefail set +e - ./src/run-with-summary not-a-command + run-with-summary not-a-command exit_code=$? cat $FILE >> $GITHUB_STEP_SUMMARY echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV From 23b54478c1eaecef22de8e7b6f4c0f2897e0c53d Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:36:26 -0400 Subject: [PATCH 37/69] Name jobs. --- .github/workflows/scripts.run-with-summary.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index f32213c..eb29759 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -15,6 +15,7 @@ env: jobs: run-with-summary: + name: run-with-summary success runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -31,6 +32,7 @@ jobs: exit $exit_code run-with-summary-fail: + name: run-with-summary failure runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 0aec0d672cd550854c6c3a4c93ef7faebf7f7911 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:38:50 -0400 Subject: [PATCH 38/69] Set default summary file. --- src/run-with-summary | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run-with-summary b/src/run-with-summary index 10324e6..37fad1d 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -9,7 +9,7 @@ debug=${DEBUG:-""} # Print the markdown summary after the command output. echo_summary=${SUMMARY:-""} -temp_report_file=${FILE:-""} +temp_report_file=${FILE:-"/tmp/summary.md"} usage() { cat <<'USAGE' From d9520b4c241b5b2451e61224febc2d862184633d Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:42:37 -0400 Subject: [PATCH 39/69] Long fail. --- .../workflows/scripts.run-with-summary.yml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index eb29759..cd2d94c 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -55,3 +55,28 @@ jobs: else echo "Exit code is not 0, as expected." fi + + run-with-summary-fail-long: + name: run-with-summary long failure + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: run-with-summary failure + env: + SUCCESS: "Ping Succeeded :white_check_mark:" + ERROR: "Ping Failed, as expected :x:" + run: | + set -o pipefail + set +e + run-with-summary ping w3.org -c4 + exit_code=$? + cat $FILE >> $GITHUB_STEP_SUMMARY + echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV + - name: exit + run: | + if [ "$EXIT_CODE" == "0" ]; then + echo "Script was expected to fail. Something is wrong." + exit 1 + else + echo "Exit code is not 0, as expected." + fi From c9d47e1f6a32542232372581e70f00c3515ec912 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:45:49 -0400 Subject: [PATCH 40/69] > output is not shown in realtime for non-interactive sessions --- src/run-with-summary | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index 37fad1d..1c99502 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -97,9 +97,10 @@ start_time=$(date '+%s') # Use a temporary file to store output temp_output_file=$(mktemp) -# Execute command and capture output while displaying it +# Execute command and capture output while displaying it in realtime +# Using stdbuf to force line buffering for non-interactive sessions set -o pipefail -eval "$command" 2>&1 | tee "$temp_output_file" +stdbuf -oL -eL eval "$command" 2>&1 | tee "$temp_output_file" exit_code=${PIPESTATUS[0]} # Read the output from temporary file From a9a90052c81ef2d6f185603a252a138f851b80cf Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:48:28 -0400 Subject: [PATCH 41/69] =?UTF-8?q?>=20stdbuf:=20failed=20to=20run=20command?= =?UTF-8?q?=20=E2=80=98eval=E2=80=99:=20No=20such=20file=20or=20directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/run-with-summary | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index 1c99502..060cea9 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -77,7 +77,7 @@ format_output() { } # Get the command from arguments -command="$@" +command="$*" # Secondary help guard: if exactly one argument and it is -h/--help, show usage and exit 0 if [ "$command" = "-h" ] || [ "$command" = "--help" ]; then @@ -98,9 +98,8 @@ start_time=$(date '+%s') temp_output_file=$(mktemp) # Execute command and capture output while displaying it in realtime -# Using stdbuf to force line buffering for non-interactive sessions set -o pipefail -stdbuf -oL -eL eval "$command" 2>&1 | tee "$temp_output_file" +eval "$command" 2>&1 | tee "$temp_output_file" exit_code=${PIPESTATUS[0]} # Read the output from temporary file From d4ba38f2003c6ac95431b0c6ce9d98f3ac703113 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:49:32 -0400 Subject: [PATCH 42/69] Using stdbuf to force line buffering for non-interactive sessions --- src/run-with-summary | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index 060cea9..1c99502 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -77,7 +77,7 @@ format_output() { } # Get the command from arguments -command="$*" +command="$@" # Secondary help guard: if exactly one argument and it is -h/--help, show usage and exit 0 if [ "$command" = "-h" ] || [ "$command" = "--help" ]; then @@ -98,8 +98,9 @@ start_time=$(date '+%s') temp_output_file=$(mktemp) # Execute command and capture output while displaying it in realtime +# Using stdbuf to force line buffering for non-interactive sessions set -o pipefail -eval "$command" 2>&1 | tee "$temp_output_file" +stdbuf -oL -eL eval "$command" 2>&1 | tee "$temp_output_file" exit_code=${PIPESTATUS[0]} # Read the output from temporary file From 64b9e29e54b56eeb0bd92d0d87f84443aa52982b Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:50:18 -0400 Subject: [PATCH 43/69] Try this? --- src/run-with-summary | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run-with-summary b/src/run-with-summary index 1c99502..f03f5cf 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -100,7 +100,7 @@ temp_output_file=$(mktemp) # Execute command and capture output while displaying it in realtime # Using stdbuf to force line buffering for non-interactive sessions set -o pipefail -stdbuf -oL -eL eval "$command" 2>&1 | tee "$temp_output_file" +stdbuf -oL -eL $command 2>&1 | tee "$temp_output_file" exit_code=${PIPESTATUS[0]} # Read the output from temporary file From c5cf15028d99dd9e7d8089e850e57d8d68a02842 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:52:57 -0400 Subject: [PATCH 44/69] try something else. --- src/run-with-summary | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index f03f5cf..62a4c9e 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -98,9 +98,8 @@ start_time=$(date '+%s') temp_output_file=$(mktemp) # Execute command and capture output while displaying it in realtime -# Using stdbuf to force line buffering for non-interactive sessions set -o pipefail -stdbuf -oL -eL $command 2>&1 | tee "$temp_output_file" +$command 2>&1 | tee "$temp_output_file" exit_code=${PIPESTATUS[0]} # Read the output from temporary file From 46616793601917f302e75a7460cc494016cb6050 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:58:48 -0400 Subject: [PATCH 45/69] back to using stdbuf --- src/run-with-summary | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/run-with-summary b/src/run-with-summary index 62a4c9e..f03f5cf 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -98,8 +98,9 @@ start_time=$(date '+%s') temp_output_file=$(mktemp) # Execute command and capture output while displaying it in realtime +# Using stdbuf to force line buffering for non-interactive sessions set -o pipefail -$command 2>&1 | tee "$temp_output_file" +stdbuf -oL -eL $command 2>&1 | tee "$temp_output_file" exit_code=${PIPESTATUS[0]} # Read the output from temporary file From 2655b80621a98ef07eac9c964e1416f5b7b73dd1 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 08:59:53 -0400 Subject: [PATCH 46/69] Try using stdbuf if it exists. --- src/run-with-summary | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index f03f5cf..0482d88 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -98,9 +98,12 @@ start_time=$(date '+%s') temp_output_file=$(mktemp) # Execute command and capture output while displaying it in realtime -# Using stdbuf to force line buffering for non-interactive sessions set -o pipefail -stdbuf -oL -eL $command 2>&1 | tee "$temp_output_file" +if command -v stdbuf >/dev/null 2>&1; then + stdbuf -oL -eL $command 2>&1 | tee "$temp_output_file" +else + $command 2>&1 | tee "$temp_output_file" +fi exit_code=${PIPESTATUS[0]} # Read the output from temporary file From f199db0e4ea8dd9fa7a3d7ba19a4e28270956eed Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 09:02:16 -0400 Subject: [PATCH 47/69] Try again. --- src/run-with-summary | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run-with-summary b/src/run-with-summary index 0482d88..e88b660 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -100,7 +100,7 @@ temp_output_file=$(mktemp) # Execute command and capture output while displaying it in realtime set -o pipefail if command -v stdbuf >/dev/null 2>&1; then - stdbuf -oL -eL $command 2>&1 | tee "$temp_output_file" + stdbuf -oL $command 2>&1 | tee "$temp_output_file" else $command 2>&1 | tee "$temp_output_file" fi From 6b80c62ab96af09dc0745f8f969a554495210e44 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 09:09:28 -0400 Subject: [PATCH 48/69] Try different. --- src/run-with-summary | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index e88b660..5e58aa4 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -100,10 +100,10 @@ temp_output_file=$(mktemp) # Execute command and capture output while displaying it in realtime set -o pipefail if command -v stdbuf >/dev/null 2>&1; then - stdbuf -oL $command 2>&1 | tee "$temp_output_file" -else - $command 2>&1 | tee "$temp_output_file" + command="stdbuf -oL $command" fi + +$command 2>&1 | tee "$temp_output_file" exit_code=${PIPESTATUS[0]} # Read the output from temporary file From 9fa130fdf02401bad533fe44ec927dab57e165a1 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 18:37:01 -0400 Subject: [PATCH 49/69] Move usage to the top. --- src/run-with-summary | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index 5e58aa4..96c8b20 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -1,15 +1,4 @@ -#!/bin/bash - -# Customize the success and error messages. -success_message=${SUCCESS:-"Command executed"} -error_message=${ERROR:-"Command failed"} - -# Print extra stuff like user and hostname in the summary. -debug=${DEBUG:-""} - -# Print the markdown summary after the command output. -echo_summary=${SUMMARY:-""} -temp_report_file=${FILE:-"/tmp/summary.md"} +#!/usr/bin/env bash usage() { cat <<'USAGE' @@ -36,6 +25,19 @@ Examples: USAGE } +set -e + +# Customize the success and error messages. +success_message=${SUCCESS:-"Command executed"} +error_message=${ERROR:-"Command failed"} + +# Print extra stuff like user and hostname in the summary. +debug=${DEBUG:-""} + +# Print the markdown summary after the command output. +echo_summary=${SUMMARY:-""} +temp_report_file=${FILE:-"/tmp/summary.md"} + # Format output into markdown report format_output() { local command="$1" From 0716552bc05b9830f762ab4eb1bd7bb08e864a0f Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 18:37:51 -0400 Subject: [PATCH 50/69] Comment out test. --- .../workflows/scripts.run-with-summary.yml | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index cd2d94c..a50072a 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -56,27 +56,28 @@ jobs: echo "Exit code is not 0, as expected." fi - run-with-summary-fail-long: - name: run-with-summary long failure - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: run-with-summary failure - env: - SUCCESS: "Ping Succeeded :white_check_mark:" - ERROR: "Ping Failed, as expected :x:" - run: | - set -o pipefail - set +e - run-with-summary ping w3.org -c4 - exit_code=$? - cat $FILE >> $GITHUB_STEP_SUMMARY - echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV - - name: exit - run: | - if [ "$EXIT_CODE" == "0" ]; then - echo "Script was expected to fail. Something is wrong." - exit 1 - else - echo "Exit code is not 0, as expected." - fi +# @TODO: Real-time output on github actions does not work. You can use this workflow to work on it. +# run-with-summary-fail-long: +# name: run-with-summary long failure +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# - name: run-with-summary failure +# env: +# SUCCESS: "Ping Succeeded :white_check_mark:" +# ERROR: "Ping Failed, as expected :x:" +# run: | +# set -o pipefail +# set +e +# run-with-summary ping w3.org -c4 +# exit_code=$? +# cat $FILE >> $GITHUB_STEP_SUMMARY +# echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV +# - name: exit +# run: | +# if [ "$EXIT_CODE" == "0" ]; then +# echo "Script was expected to fail. Something is wrong." +# exit 1 +# else +# echo "Exit code is not 0, as expected." +# fi From 9d94f51a17975bae20f337dc2a5bce79d9adf0ad Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 18:45:12 -0400 Subject: [PATCH 51/69] Put example in details. --- README.md | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 57151c0..c2c75dc 100644 --- a/README.md +++ b/README.md @@ -5,21 +5,42 @@ Bash to basics. `run-with-summary ` -## Example +Executes a command and prints a markdown summary. + +Useful for CI systems like GitHub Actions. + +## Examples + +```shell + run-with-summary ping w3.org -c5 +``` + +To customize the report header text, show extra info in the table, or print the summary in the command run, use these env vars. ```shell SUCCESS="Deploy complete" \ ERROR="Deploy failed" \ DEBUG=1 \ SUMMARY=1 \ - run-with-summary ping w3.org -c3 + run-with-summary deploy.sh ``` -## Output +To output the results of a command to GitHub Actions summary, add this step to your workflow: -This script renders the output of the command and a summary using markdown syntax. +```yaml +- name: Deploy script + env: + SUCCESS: "Deploy complete" + ERROR: "Deploy failed" + DEBUG: 1 + SUMMARY: 1 + run: | + run-with-summary deploy.sh +``` -# Deploy complete +
+Example Output +# Command complete ``` ping w3.org -c5 ``` @@ -48,3 +69,4 @@ round-trip min/avg/max/stddev = 9.480/12.844/15.017/1.825 ms | Directory | /Users/jonpugh/Work/Operations/goatscripts Markdown report saved to /tmp/summary.md +
From dac4e2201cf462f38938af26f1675d9a3308fdd9 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 19:44:38 -0400 Subject: [PATCH 52/69] Rewrite. JUST render markdown. Users decide what to do with it. --- src/run-with-summary | 98 ++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 58 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index 96c8b20..f62a80e 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -7,20 +7,23 @@ Usage: run-with-summary Executes the given command, streams its output, and writes a Markdown summary to $FILE. Environment variables: - SUCCESS Custom success heading (default: "Command executed"). - ERROR Custom error heading (default: "Command failed"). + HEADING Custom text for the h1 tag. (default: "Running Command...") + SUMMARY Short text to display below the header. + SUCCESS Custom success message (default: "Command succeeded"). + ERROR Custom error message (default: "Command failed"). DEBUG If set (non-empty), include User/Host/Directory in the summary. - SUMMARY If set (non-empty), echo the Markdown summary to stdout after execution. FILE Markdown report file (default: /tmp/summary.md Examples: - run-with-summary ls -la + run-with-summary scripts/deploy.sh - SUCCESS="w3.org is online" \ - ERROR="w3.org unavailable!" \ + HEADING="Deployment" \ + SUMMARY="Deploy script running as an example." \ + SUCCESS="Deploy successful! :rocket:" \ + ERROR="DEPLOY FAILED! :x:" \ DEBUG=1 \ - SUMMARY=1 \ - run-with-summary ping w3.org -c3 + FILE=reports/$(date).md \ + run-with-summary scripts/deploy.sh USAGE } @@ -28,42 +31,39 @@ USAGE set -e # Customize the success and error messages. -success_message=${SUCCESS:-"Command executed"} +command="$@" +heading_message=${HEADING:-"Command executed"} +summary=${SUMMARY:-"Started $(date)"} +success_message=${SUCCESS:-"Command executed successfully."} error_message=${ERROR:-"Command failed"} # Print extra stuff like user and hostname in the summary. debug=${DEBUG:-""} # Print the markdown summary after the command output. -echo_summary=${SUMMARY:-""} temp_report_file=${FILE:-"/tmp/summary.md"} +if [ -z "$command" ]; then + usage + exit 1 +fi + # Format output into markdown report format_output() { local command="$1" - local output="$2" - local exit_code="$3" - local start_time="$4" - local end_time="$5" + local exit_code="$2" + local start_time="$3" + local end_time="$4" local duration=$((end_time - start_time)) local start_date=$(date -d "@$start_time" '+%Y-%m-%d %H:%M:%S %Z' 2>/dev/null || date -r $start_time '+%Y-%m-%d %H:%M:%S %Z') local end_date=$(date -d "@$end_time" '+%Y-%m-%d %H:%M:%S %Z' 2>/dev/null || date -r $end_time '+%Y-%m-%d %H:%M:%S %Z') - local heading_message="$error_message" + local message="$error_message" if [ "$exit_code" -eq 0 ]; then - heading_message="$success_message" + message="$success_message" fi - echo "# ${heading_message}" - echo "\`\`\`" - echo "$command" - echo "\`\`\`" - echo - echo "\`\`\`" - echo "$output" - echo "\`\`\`" - echo echo "| Command | \`$command\`" echo "|------------|-----------------------" echo "| Exit Code | \`$exit_code\`" @@ -76,21 +76,11 @@ format_output() { echo "| Host | $(hostname -f)" echo "| Directory | $(pwd)" fi + echo + echo $message } -# Get the command from arguments -command="$@" - -# Secondary help guard: if exactly one argument and it is -h/--help, show usage and exit 0 -if [ "$command" = "-h" ] || [ "$command" = "--help" ]; then - usage - exit 0 -fi -if [ -z "$command" ]; then - usage - exit 1 -fi # Record start time start_time=$(date '+%s') @@ -99,31 +89,23 @@ start_time=$(date '+%s') # Use a temporary file to store output temp_output_file=$(mktemp) -# Execute command and capture output while displaying it in realtime -set -o pipefail -if command -v stdbuf >/dev/null 2>&1; then - command="stdbuf -oL $command" -fi +echo "# ${heading_message}" +echo "${summary}" +echo "\`\`\`" +echo "$command" +echo "\`\`\`" +echo +echo "\`\`\`" -$command 2>&1 | tee "$temp_output_file" +set -o pipefail +$command exit_code=${PIPESTATUS[0]} +echo "\`\`\`" -# Read the output from temporary file -output=$(<"$temp_output_file") -rm "$temp_output_file" - - -# Record end time end_time=$(date '+%s') # Generate markdown report -formatted_output=$(format_output "$command" "$output" "$exit_code" "$start_time" "$end_time") -echo "$formatted_output" > $temp_report_file - -if [[ -n $echo_summary ]]; then - echo "$formatted_output" -fi -echo -echo "Markdown report saved to $temp_report_file" +format_output "$command" "$exit_code" "$start_time" "$end_time" -exit "$exit_code" \ No newline at end of file +# Exit same as command. +exit "$exit_code" From 22a770cd104993f737db08084a649fb30725a6bf Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 19:47:38 -0400 Subject: [PATCH 53/69] Cleanup tests --- .../workflows/scripts.run-with-summary.yml | 50 ++----------------- 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index a50072a..894b9cd 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -21,15 +21,11 @@ jobs: - uses: actions/checkout@v4 - name: run-with-summary env: + HEADING: "Running Tests" SUCCESS: "Test Command Succeeded :white_check_mark:" ERROR: "Test Command Failed! :x:" run: | - set -o pipefail - set +e - run-with-summary ls -la - exit_code=$? - cat $FILE >> $GITHUB_STEP_SUMMARY - exit $exit_code + run-with-summary ls -la >> $GITHUB_STEP_SUMMARY run-with-summary-fail: name: run-with-summary failure @@ -38,46 +34,8 @@ jobs: - uses: actions/checkout@v4 - name: run-with-summary failure env: + HEADING: "Confirming command failure" SUCCESS: "Command Succeeded :white_check_mark:" ERROR: "Command Failed, as expected :x:" run: | - set -o pipefail - set +e - run-with-summary not-a-command - exit_code=$? - cat $FILE >> $GITHUB_STEP_SUMMARY - echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV - - name: exit - run: | - if [ "$EXIT_CODE" == "0" ]; then - echo "Script was expected to fail. Something is wrong." - exit 1 - else - echo "Exit code is not 0, as expected." - fi - -# @TODO: Real-time output on github actions does not work. You can use this workflow to work on it. -# run-with-summary-fail-long: -# name: run-with-summary long failure -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v4 -# - name: run-with-summary failure -# env: -# SUCCESS: "Ping Succeeded :white_check_mark:" -# ERROR: "Ping Failed, as expected :x:" -# run: | -# set -o pipefail -# set +e -# run-with-summary ping w3.org -c4 -# exit_code=$? -# cat $FILE >> $GITHUB_STEP_SUMMARY -# echo "EXIT_CODE=$exit_code" >> $GITHUB_ENV -# - name: exit -# run: | -# if [ "$EXIT_CODE" == "0" ]; then -# echo "Script was expected to fail. Something is wrong." -# exit 1 -# else -# echo "Exit code is not 0, as expected." -# fi + run-with-summary not-a-command >> $GITHUB_STEP_SUMMARY From aabe12395a03b74fc38f88163a04d150d8645373 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 19:55:12 -0400 Subject: [PATCH 54/69] try tee --- .github/workflows/scripts.run-with-summary.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index 894b9cd..9f14be5 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -38,4 +38,4 @@ jobs: SUCCESS: "Command Succeeded :white_check_mark:" ERROR: "Command Failed, as expected :x:" run: | - run-with-summary not-a-command >> $GITHUB_STEP_SUMMARY + run-with-summary ping w3.org -n5 | tee -a $GITHUB_STEP_SUMMARY From 0948a48b174ad06fa1b13d8ede04c87838c01e9d Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 19:55:45 -0400 Subject: [PATCH 55/69] try tee --- .github/workflows/scripts.run-with-summary.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index 9f14be5..0c51f98 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -38,4 +38,4 @@ jobs: SUCCESS: "Command Succeeded :white_check_mark:" ERROR: "Command Failed, as expected :x:" run: | - run-with-summary ping w3.org -n5 | tee -a $GITHUB_STEP_SUMMARY + run-with-summary ping w3.org -c5 | tee -a $GITHUB_STEP_SUMMARY From f0372d2651e5ac86fb6bee474385ad5675e7de6a Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 19:57:59 -0400 Subject: [PATCH 56/69] Put the github PR description in the summary. --- .github/workflows/scripts.run-with-summary.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index 0c51f98..9b2a1a7 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -8,7 +8,7 @@ on: # Settings for run-with-summary script. env: FILE: report-${{ github.run_id }}.md - SUMMARY: yes + SUMMARY: ${{ github.event.pull_request.description }} DEBUG: yes PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin From 4268c1c5a67a423284371a460ae971a95b173aa9 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:00:33 -0400 Subject: [PATCH 57/69] Add a long summary. --- .github/workflows/scripts.run-with-summary.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index 9b2a1a7..c2e09a9 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -8,7 +8,9 @@ on: # Settings for run-with-summary script. env: FILE: report-${{ github.run_id }}.md - SUMMARY: ${{ github.event.pull_request.description }} + SUMMARY: | + Pull Request: #${{ github.event.number }} ${{ github.event.pull_request.title }} + ${{ github.event.pull_request.description }} DEBUG: yes PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin From 73555cba30076c6950041ec879dc15456abc5f31 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:02:40 -0400 Subject: [PATCH 58/69] More --- .github/workflows/scripts.run-with-summary.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index c2e09a9..c65c7fb 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -9,8 +9,8 @@ on: env: FILE: report-${{ github.run_id }}.md SUMMARY: | - Pull Request: #${{ github.event.number }} ${{ github.event.pull_request.title }} - ${{ github.event.pull_request.description }} + > Pull Request: [#${{ github.event.number }}](${{github.event.pull_request.html_url }}) ${{ github.event.pull_request.title }} + > ${{ github.event.pull_request.body }} DEBUG: yes PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin From 58bad72de09ccac140210a22d70582d609f36770 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:04:19 -0400 Subject: [PATCH 59/69] More --- .github/workflows/scripts.run-with-summary.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index c65c7fb..6134210 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -9,7 +9,7 @@ on: env: FILE: report-${{ github.run_id }}.md SUMMARY: | - > Pull Request: [#${{ github.event.number }}](${{github.event.pull_request.html_url }}) ${{ github.event.pull_request.title }} + Pull Request [#${{ github.event.number }} ${{ github.event.pull_request.title }}](${{github.event.pull_request.html_url }}) > ${{ github.event.pull_request.body }} DEBUG: yes PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin From d4901ddad7f1b4841603e5158c3b549b18ae70b4 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:07:29 -0400 Subject: [PATCH 60/69] More --- .github/workflows/scripts.run-with-summary.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index 6134210..c182563 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -9,7 +9,7 @@ on: env: FILE: report-${{ github.run_id }}.md SUMMARY: | - Pull Request [#${{ github.event.number }} ${{ github.event.pull_request.title }}](${{github.event.pull_request.html_url }}) + Pull Request #${{ github.event.number }}: [${{ github.event.pull_request.title }}](${{github.event.pull_request.html_url }}) > ${{ github.event.pull_request.body }} DEBUG: yes PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin From 7fbf190f0860948fa1700a658d4bbfb139220482 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:08:58 -0400 Subject: [PATCH 61/69] Only show heading if present. --- src/run-with-summary | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/run-with-summary b/src/run-with-summary index f62a80e..6690640 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -89,8 +89,14 @@ start_time=$(date '+%s') # Use a temporary file to store output temp_output_file=$(mktemp) -echo "# ${heading_message}" -echo "${summary}" +if [[ -n ${heading_message} ]]; then + echo "# ${heading_message}" +fi + +if [[ -n ${summary} ]]; then + echo "# ${summary}" +fi + echo "\`\`\`" echo "$command" echo "\`\`\`" From d7bdc47cb9b18dd9af4a54517904262661ace732 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:16:01 -0400 Subject: [PATCH 62/69] Print link to demo site. --- .github/workflows/scripts.run-with-summary.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index c182563..7638d3b 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -9,6 +9,7 @@ on: env: FILE: report-${{ github.run_id }}.md SUMMARY: | + Environment: https://pr${{ github.event.number }}.demo.site Pull Request #${{ github.event.number }}: [${{ github.event.pull_request.title }}](${{github.event.pull_request.html_url }}) > ${{ github.event.pull_request.body }} DEBUG: yes From 4c93b8f1caaf34d7a89a833f98cc576e2bbab5ae Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:17:58 -0400 Subject: [PATCH 63/69] Add more summary. --- .github/workflows/scripts.run-with-summary.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index 7638d3b..ac2df30 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -9,8 +9,8 @@ on: env: FILE: report-${{ github.run_id }}.md SUMMARY: | - Environment: https://pr${{ github.event.number }}.demo.site - Pull Request #${{ github.event.number }}: [${{ github.event.pull_request.title }}](${{github.event.pull_request.html_url }}) + - Environment: https://pr${{ github.event.number }}.demo.site + - Pull Request #${{ github.event.number }}: [${{ github.event.pull_request.title }}](${{github.event.pull_request.html_url }}) > ${{ github.event.pull_request.body }} DEBUG: yes PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin From a9ae7605ea92b60d43c877464c7ec3c7ec2a96e6 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:18:28 -0400 Subject: [PATCH 64/69] Wrong --- src/run-with-summary | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run-with-summary b/src/run-with-summary index 6690640..2058cb5 100755 --- a/src/run-with-summary +++ b/src/run-with-summary @@ -94,7 +94,7 @@ if [[ -n ${heading_message} ]]; then fi if [[ -n ${summary} ]]; then - echo "# ${summary}" + echo "${summary}" fi echo "\`\`\`" From f2ebaa493aef8b3e34aa274d8cf1a73b30e29f4c Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:19:41 -0400 Subject: [PATCH 65/69] Markdown. --- .github/workflows/scripts.run-with-summary.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index ac2df30..ab54897 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -10,7 +10,8 @@ env: FILE: report-${{ github.run_id }}.md SUMMARY: | - Environment: https://pr${{ github.event.number }}.demo.site - - Pull Request #${{ github.event.number }}: [${{ github.event.pull_request.title }}](${{github.event.pull_request.html_url }}) + - [Pull Request #${{ github.event.number }}](${{github.event.pull_request.html_url }}) + > **${{ github.event.pull_request.title }}** > ${{ github.event.pull_request.body }} DEBUG: yes PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin From 4de34c646586becd80f4b93926eecdde04b7cae0 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:21:17 -0400 Subject: [PATCH 66/69] Markdown. --- .github/workflows/scripts.run-with-summary.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index ab54897..86ee2db 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -10,9 +10,9 @@ env: FILE: report-${{ github.run_id }}.md SUMMARY: | - Environment: https://pr${{ github.event.number }}.demo.site - - [Pull Request #${{ github.event.number }}](${{github.event.pull_request.html_url }}) - > **${{ github.event.pull_request.title }}** +
[Pull Request #${{ github.event.number }}](${{github.event.pull_request.html_url }}) > ${{ github.event.pull_request.body }} +
DEBUG: yes PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin From c9be0af4f9a53c2faa6552007a3f4e9f243b6748 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:23:55 -0400 Subject: [PATCH 67/69] Markdown. --- .github/workflows/scripts.run-with-summary.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.run-with-summary.yml b/.github/workflows/scripts.run-with-summary.yml index 86ee2db..b2d0245 100644 --- a/.github/workflows/scripts.run-with-summary.yml +++ b/.github/workflows/scripts.run-with-summary.yml @@ -10,8 +10,10 @@ env: FILE: report-${{ github.run_id }}.md SUMMARY: | - Environment: https://pr${{ github.event.number }}.demo.site -
[Pull Request #${{ github.event.number }}](${{github.event.pull_request.html_url }}) - > ${{ github.event.pull_request.body }} + - Pull Request: ${{github.event.pull_request.html_url }} + +
${{ github.event.pull_request.title }} + ${{ github.event.pull_request.body }}
DEBUG: yes PATH: ./src:./bin:./vendor/bin:/usr/local/bin:/usr/bin:/bin From 5211a44f4f2a59765cf0a2b8b560fbe3fef198c9 Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:29:36 -0400 Subject: [PATCH 68/69] Fix readme. --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c2c75dc..eca7159 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,24 @@ To output the results of a command to GitHub Actions summary, add this step to y env: SUCCESS: "Deploy complete" ERROR: "Deploy failed" - DEBUG: 1 - SUMMARY: 1 + SUMMARY: | + - Environment: https://pr${{ github.event.number }}.demo.site + - Pull Request: ${{github.event.pull_request.html_url }} + +
${{ github.event.pull_request.title }} + ${{ github.event.pull_request.body }} +
run: | run-with-summary deploy.sh ```
Example Output + # Command complete + +Any markdown at all can be put into the SUMMARY env var. + ``` ping w3.org -c5 ``` From c7d62b20a470b46e7f36f37c83477054b1b5033b Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Fri, 3 Oct 2025 20:30:42 -0400 Subject: [PATCH 69/69] Fix readme. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eca7159..8e96223 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ # goatscripts Bash to basics. -# Run With Summary +These scripts are things I've been using in different places over the years. + +Help yourself. + +## Run With Summary `run-with-summary `