Skip to content

Commit 704667c

Browse files
committed
Merge branch 'js/ci-github-workflow-markup' into seen
Update the GitHub workflow support to make it quicker to get to the failing test. * js/ci-github-workflow-markup: ci: call `finalize_test_case_output` a little later ci: use `--github-workflow-markup` in the GitHub workflow ci: optionally mark up output in the GitHub workflow test(junit): avoid line feeds in XML attributes tests: refactor --write-junit-xml code ci/run-build-and-tests: add some structure to the GitHub workflow output ci: make it easier to find failed tests' logs in the GitHub workflow ci/run-build-and-tests: take a more high-level view ci: fix code style
2 parents 2664591 + eb53a5b commit 704667c

File tree

8 files changed

+288
-139
lines changed

8 files changed

+288
-139
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ jobs:
119119
- name: test
120120
shell: bash
121121
run: . /etc/profile && ci/run-test-slice.sh ${{matrix.nr}} 10
122-
- name: ci/print-test-failures.sh
123-
if: failure()
124-
shell: bash
125-
run: ci/print-test-failures.sh
126122
- name: Upload failed tests' directories
127123
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
128124
uses: actions/upload-artifact@v2
@@ -204,10 +200,6 @@ jobs:
204200
env:
205201
NO_SVN_TESTS: 1
206202
run: . /etc/profile && ci/run-test-slice.sh ${{matrix.nr}} 10
207-
- name: ci/print-test-failures.sh
208-
if: failure()
209-
shell: bash
210-
run: ci/print-test-failures.sh
211203
- name: Upload failed tests' directories
212204
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
213205
uses: actions/upload-artifact@v2
@@ -261,8 +253,6 @@ jobs:
261253
- uses: actions/checkout@v2
262254
- run: ci/install-dependencies.sh
263255
- run: ci/run-build-and-tests.sh
264-
- run: ci/print-test-failures.sh
265-
if: failure()
266256
- name: Upload failed tests' directories
267257
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
268258
uses: actions/upload-artifact@v2
@@ -292,8 +282,6 @@ jobs:
292282
- uses: actions/checkout@v1
293283
- run: ci/install-docker-dependencies.sh
294284
- run: ci/run-build-and-tests.sh
295-
- run: ci/print-test-failures.sh
296-
if: failure()
297285
- name: Upload failed tests' directories
298286
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
299287
uses: actions/upload-artifact@v1

ci/lib.sh

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
11
# Library of functions shared by all CI scripts
22

3+
if test true != "$GITHUB_ACTIONS"
4+
then
5+
begin_group () { :; }
6+
end_group () { :; }
7+
8+
group () {
9+
shift
10+
"$@"
11+
}
12+
set -x
13+
else
14+
begin_group () {
15+
need_to_end_group=t
16+
echo "::group::$1" >&2
17+
set -x
18+
}
19+
20+
end_group () {
21+
test -n "$need_to_end_group" || return 0
22+
set +x
23+
need_to_end_group=
24+
echo '::endgroup::' >&2
25+
}
26+
trap end_group EXIT
27+
28+
group () {
29+
set +x
30+
begin_group "$1"
31+
shift
32+
"$@"
33+
res=$?
34+
end_group
35+
return $res
36+
}
37+
38+
begin_group "CI setup"
39+
fi
40+
41+
# Set 'exit on error' for all CI scripts to let the caller know that
42+
# something went wrong.
43+
#
44+
# We already enabled tracing executed commands earlier. This helps by showing
45+
# how # environment variables are set and and dependencies are installed.
46+
set -e
47+
348
skip_branch_tip_with_tag () {
449
# Sometimes, a branch is pushed at the same time the tag that points
550
# at the same commit as the tip of the branch is pushed, and building
@@ -69,8 +114,7 @@ skip_good_tree () {
69114
exit 0
70115
}
71116

72-
check_unignored_build_artifacts ()
73-
{
117+
check_unignored_build_artifacts () {
74118
! git ls-files --other --exclude-standard --error-unmatch \
75119
-- ':/*' 2>/dev/null ||
76120
{
@@ -79,18 +123,16 @@ check_unignored_build_artifacts ()
79123
}
80124
}
81125

126+
handle_failed_tests () {
127+
return 1
128+
}
129+
82130
# GitHub Action doesn't set TERM, which is required by tput
83131
export TERM=${TERM:-dumb}
84132

85133
# Clear MAKEFLAGS that may come from the outside world.
86134
export MAKEFLAGS=
87135

88-
# Set 'exit on error' for all CI scripts to let the caller know that
89-
# something went wrong.
90-
# Set tracing executed commands, primarily setting environment variables
91-
# and installing dependencies.
92-
set -ex
93-
94136
if test -n "$SYSTEM_COLLECTIONURI" || test -n "$SYSTEM_TASKDEFINITIONSURI"
95137
then
96138
CI_TYPE=azure-pipelines
@@ -124,11 +166,30 @@ then
124166
CI_JOB_ID="$GITHUB_RUN_ID"
125167
CC="${CC_PACKAGE:-${CC:-gcc}}"
126168
DONT_SKIP_TAGS=t
169+
handle_failed_tests () {
170+
mkdir -p t/failed-test-artifacts
171+
echo "FAILED_TEST_ARTIFACTS=t/failed-test-artifacts" >>$GITHUB_ENV
172+
173+
for test_exit in t/test-results/*.exit
174+
do
175+
test 0 != "$(cat "$test_exit")" || continue
176+
177+
test_name="${test_exit%.exit}"
178+
test_name="${test_name##*/}"
179+
printf "\\e[33m\\e[1m=== Failed test: ${test_name} ===\\e[m\\n"
180+
cat "t/test-results/$test_name.markup"
181+
182+
trash_dir="t/trash directory.$test_name"
183+
cp "t/test-results/$test_name.out" t/failed-test-artifacts/
184+
tar czf t/failed-test-artifacts/"$test_name".trash.tar.gz "$trash_dir"
185+
done
186+
return 1
187+
}
127188

128189
cache_dir="$HOME/none"
129190

130191
export GIT_PROVE_OPTS="--timer --jobs 10"
131-
export GIT_TEST_OPTS="--verbose-log -x"
192+
export GIT_TEST_OPTS="--verbose-log -x --github-workflow-markup"
132193
MAKEFLAGS="$MAKEFLAGS --jobs=10"
133194
test windows != "$CI_OS_NAME" ||
134195
GIT_TEST_OPTS="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
@@ -211,3 +272,6 @@ linux-leaks)
211272
esac
212273

213274
MAKEFLAGS="$MAKEFLAGS CC=${CC:-cc}"
275+
276+
end_group
277+
set -x

ci/run-build-and-tests.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ windows*) cmd //c mklink //j t\\.prove "$(cygpath -aw "$cache_dir/.prove")";;
1010
*) ln -s "$cache_dir/.prove" t/.prove;;
1111
esac
1212

13-
export MAKE_TARGETS="all test"
13+
run_tests=t
1414

1515
case "$jobname" in
1616
linux-gcc)
@@ -41,14 +41,16 @@ pedantic)
4141
# Don't run the tests; we only care about whether Git can be
4242
# built.
4343
export DEVOPTS=pedantic
44-
export MAKE_TARGETS=all
44+
run_tests=
4545
;;
4646
esac
4747

48-
# Any new "test" targets should not go after this "make", but should
49-
# adjust $MAKE_TARGETS. Otherwise compilation-only targets above will
50-
# start running tests.
51-
make $MAKE_TARGETS
48+
group Build make
49+
if test -n "$run_tests"
50+
then
51+
group "Run tests" make test ||
52+
handle_failed_tests
53+
fi
5254
check_unignored_build_artifacts
5355

5456
save_good_tree

ci/run-test-slice.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ windows*) cmd //c mklink //j t\\.prove "$(cygpath -aw "$cache_dir/.prove")";;
1010
*) ln -s "$cache_dir/.prove" t/.prove;;
1111
esac
1212

13-
make --quiet -C t T="$(cd t &&
13+
group "Run tests" make --quiet -C t T="$(cd t &&
1414
./helper/test-tool path-utils slice-tests "$1" "$2" t[0-9]*.sh |
15-
tr '\n' ' ')"
15+
tr '\n' ' ')" ||
16+
handle_failed_tests
1617

1718
check_unignored_build_artifacts

t/test-lib-functions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ test_verify_prereq () {
795795
}
796796

797797
test_expect_failure () {
798-
test_start_
798+
test_start_ "$@"
799799
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
800800
test "$#" = 2 ||
801801
BUG "not 2 or 3 parameters to test-expect-failure"
@@ -815,7 +815,7 @@ test_expect_failure () {
815815
}
816816

817817
test_expect_success () {
818-
test_start_
818+
test_start_ "$@"
819819
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
820820
test "$#" = 2 ||
821821
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

0 commit comments

Comments
 (0)