Skip to content

Commit 6729095

Browse files
authored
Support multi-line Strings in logging.functions.sh (#1079)
Support was added for multi-line error messages in #970, but not for the rest of the functions - without this change, only the first line is logged.
1 parent cde78e6 commit 6729095

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

.github/scripts/logging.functions.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,44 @@
33
# Prints the given message to stderr
44
function echoerr() {
55
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-error-message
6-
# Support multi-line strings by replacing line separator with GitHub Actions compatible one
7-
echo "::error::ERROR - ${*//$'\n'/%0A}" 1>&2;
6+
__log "error" "ERROR - " "${*}"
87
}
98

109
# Prints the given message as a warning
1110
function echowarning() {
1211
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-warning-message
13-
echo "::warning::$*" 1>&2;
12+
__log "warning" "${*}"
1413
}
1514

1615
# Prints the given message as a notice
1716
function echonotice() {
1817
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-notice-message
19-
echo "::notice::$*" 1>&2;
18+
__log "notice" "${*}"
2019
}
2120

2221
# Prints the given message to debug logs, _if enabled_
2322
function echodebug() {
2423
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-debug-message
25-
echo "::debug::$*" 1>&2;
24+
__log "debug" "${*}"
2625
}
2726

2827
# Create group
2928
function echo_group() {
3029
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#grouping-log-lines
31-
local TITLE=$1
32-
echo "::group::${TITLE}"
30+
__log "group" "${*}"
3331
}
3432

3533
# Ends group after calling echo_group()
3634
function echo_group_end() {
3735
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#grouping-log-lines
38-
echo "::endgroup::"
36+
__log "endgroup"
37+
}
38+
39+
function __log() {
40+
local level=${1}
41+
shift
42+
local message=${*}
43+
44+
# Support multi-line strings by replacing line separator with GitHub Actions compatible one
45+
echo "::${level}::${message//$'\n'/%0A}" 1>&2
3946
}

0 commit comments

Comments
 (0)