Skip to content

Commit 67a419c

Browse files
committed
Ensure outputs are logged at end of scripts
1 parent 5a0bc54 commit 67a419c

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

.github/actions/build-tar-image/action.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,35 @@ runs:
159159
- name: Set outputs
160160
run: |
161161
set -euo pipefail
162-
162+
163163
debug_log() {
164164
if [ "${RUNNER_DEBUG:-0}" = "1" ]; then
165165
echo "$1" | while IFS= read -r line; do
166166
echo "##[debug]$line"
167167
done
168168
fi
169169
}
170-
170+
171+
log_content() {
172+
local content="$1"
173+
local label="${2:-}"
174+
175+
if [[ -n "$label" ]]; then
176+
# Replace the beginning of each line with two spaces
177+
local indented_content="${content//$'\n'/$'\n' }"
178+
printf "%s:\n %s\n" "$label" "$indented_content"
179+
else
180+
echo "$content"
181+
fi
182+
}
183+
184+
log_output() {
185+
echo ::group::Set outputs
186+
log_content "$(cat "$GITHUB_OUTPUT")" "GITHUB_OUTPUT"
187+
log_content "$(cat "$GITHUB_ENV")" "GITHUB_ENV"
188+
echo ::endgroup::
189+
}
190+
171191
set_output() {
172192
local value="$1"
173193
local output_key="$2"
@@ -189,5 +209,5 @@ runs:
189209
190210
image_value="${{ inputs.upload-name }}:${{ inputs.upload-tag }}"
191211
set_output "$image_value" "image-name"
192-
debug_log "GitHub Output: $(cat "$GITHUB_OUTPUT")\nGitHub Env: $(cat "$GITHUB_ENV")"
212+
log_output
193213
shell: bash

.github/actions/load-tar-image/action.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,27 @@ runs:
3131
done
3232
fi
3333
}
34-
34+
35+
log_content() {
36+
local content="$1"
37+
local label="${2:-}"
38+
39+
if [[ -n "$label" ]]; then
40+
# Replace the beginning of each line with two spaces
41+
local indented_content="${content//$'\n'/$'\n' }"
42+
printf "%s:\n %s\n" "$label" "$indented_content"
43+
else
44+
echo "$content"
45+
fi
46+
}
47+
48+
log_output() {
49+
echo ::group::Set outputs
50+
log_content "$(cat "$GITHUB_OUTPUT")" "GITHUB_OUTPUT"
51+
log_content "$(cat "$GITHUB_ENV")" "GITHUB_ENV"
52+
echo ::endgroup::
53+
}
54+
3555
set_output() {
3656
local value="$1"
3757
local output_key="$2"
@@ -53,5 +73,5 @@ runs:
5373
5474
image_value="${{ inputs.download-name }}:${{ inputs.download-tag }}"
5575
set_output "$image_value" "image-name"
56-
debug_log "GitHub Output: $(cat "$GITHUB_OUTPUT")\nGitHub Env: $(cat "$GITHUB_ENV")"
76+
log_output
5777
shell: bash

0 commit comments

Comments
 (0)