Skip to content

Commit bd8bf87

Browse files
dschogitster
authored andcommitted
ci: optionally mark up output in the GitHub workflow
A couple of commands exist to spruce up the output in GitHub workflows: https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions In addition to the `::group::<label>`/`::endgroup::` commands (which we already use to structure the output of the build step better), we also use `::error::`/`::notice::` to draw the attention to test failures and to test cases that were expected to fail but didn't. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af87aeb commit bd8bf87

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

t/test-lib-functions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ test_verify_prereq () {
719719
}
720720

721721
test_expect_failure () {
722-
test_start_
722+
test_start_ "$@"
723723
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
724724
test "$#" = 2 ||
725725
BUG "not 2 or 3 parameters to test-expect-failure"
@@ -739,7 +739,7 @@ test_expect_failure () {
739739
}
740740

741741
test_expect_success () {
742-
test_start_
742+
test_start_ "$@"
743743
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
744744
test "$#" = 2 ||
745745
BUG "not 2 or 3 parameters to test-expect-success"

t/test-lib-github-workflow-markup.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Library of functions to mark up test scripts' output suitable for
2+
# pretty-printing it in GitHub workflows.
3+
#
4+
# Copyright (c) 2022 Johannes Schindelin
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 2 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see http://www.gnu.org/licenses/ .
18+
#
19+
# The idea is for `test-lib.sh` to source this file when run in GitHub
20+
# workflows; these functions will then override (empty) functions
21+
# that are are called at the appropriate times during the test runs.
22+
23+
start_test_output () {
24+
test -n "$GIT_TEST_TEE_OUTPUT_FILE" ||
25+
die "--github-workflow-markup requires --verbose-log"
26+
github_markup_output="${GIT_TEST_TEE_OUTPUT_FILE%.out}.markup"
27+
>$github_markup_output
28+
GIT_TEST_TEE_OFFSET=0
29+
}
30+
31+
# No need to override start_test_case_output
32+
33+
finalize_test_case_output () {
34+
test_case_result=$1
35+
shift
36+
case "$test_case_result" in
37+
failure)
38+
echo >>$github_markup_output "::error::failed: $this_test.$test_count $1"
39+
;;
40+
fixed)
41+
echo >>$github_markup_output "::notice::fixed: $this_test.$test_count $1"
42+
;;
43+
esac
44+
echo >>$github_markup_output "::group::$test_case_result: $this_test.$test_count $*"
45+
test-tool >>$github_markup_output path-utils skip-n-bytes \
46+
"$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET
47+
echo >>$github_markup_output "::endgroup::"
48+
}
49+
50+
# No need to override finalize_test_output

t/test-lib.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ parse_option () {
174174
--write-junit-xml)
175175
. "$TEST_DIRECTORY/test-lib-junit.sh"
176176
;;
177+
--github-workflow-markup)
178+
. "$TEST_DIRECTORY/test-lib-github-workflow-markup.sh"
179+
;;
177180
--stress)
178181
stress=t ;;
179182
--stress=*)
@@ -1029,7 +1032,7 @@ test_start_ () {
10291032
test_count=$(($test_count+1))
10301033
maybe_setup_verbose
10311034
maybe_setup_valgrind
1032-
start_test_case_output
1035+
start_test_case_output "$@"
10331036
}
10341037

10351038
test_finish_ () {

0 commit comments

Comments
 (0)