Skip to content

Commit 064b935

Browse files
dschogitster
authored andcommitted
ci: make it easier to find failed tests' logs in the GitHub workflow
When investigating a test failure, the time that matters most is the time it takes from getting aware of the failure to displaying the output of the failing test case. You currently have to know a lot of implementation details when investigating test failures in the CI runs. The first step is easy: the failed job is marked quite clearly, but when opening it, the failed step is expanded, which in our case is the one running `ci/run-build-and-tests.sh`. This step, most notably, only offers a high-level view of what went wrong: it prints the output of `prove` which merely tells the reader which test script failed. The actually interesting part is in the detailed log of said failed test script. But that log is shown in the CI run's step that runs `ci/print-test-failures.sh`. And that step is _not_ expanded in the web UI by default. It is even marked as "successful", which makes it very easy to miss that there is useful information hidden in there. Let's help the reader by showing the failed tests' detailed logs in the step that is expanded automatically, i.e. directly after the test suite failed. This also helps the situation where the _build_ failed and the `print-test-failures` step was executed under the assumption that the _test suite_ failed, and consequently failed to find any failed tests. An alternative way to implement this patch would be to source `ci/print-test-failures.sh` in the `handle_test_failures` function to show these logs. However, over the course of the next few commits, we want to introduce some grouping which would be harder to achieve that way (for example, we do want a leaner, and colored, preamble for each failed test script, and it would be trickier to accommodate the lack of nested groupings in GitHub workflows' output). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8487311 commit 064b935

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ jobs:
129129
shell: bash
130130
- name: test
131131
shell: bash
132-
run: . /etc/profile && make -C t -e
133-
- name: ci/print-test-failures.sh
134-
if: failure()
135-
shell: bash
136-
run: ci/print-test-failures.sh
132+
run: . /etc/profile && make -C t -e || ci/print-test-failures-github.sh
137133
- name: Upload failed tests' directories
138134
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
139135
uses: actions/upload-artifact@v2
@@ -218,11 +214,7 @@ jobs:
218214
shell: bash
219215
- name: test
220216
shell: bash
221-
run: . /etc/profile && make -C t -e
222-
- name: ci/print-test-failures.sh
223-
if: failure()
224-
shell: bash
225-
run: ci/print-test-failures.sh
217+
run: . /etc/profile && make -C t -e || ci/print-test-failures-github.sh
226218
- name: Upload failed tests' directories
227219
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
228220
uses: actions/upload-artifact@v2
@@ -265,10 +257,8 @@ jobs:
265257
- run: ci/lib.sh --build
266258
- run: make
267259
- run: ci/lib.sh --test
268-
- run: make test
260+
- run: make test || ci/print-test-failures-github.sh
269261
if: success()
270-
- run: ci/print-test-failures.sh
271-
if: failure()
272262
- name: Upload failed tests' directories
273263
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
274264
uses: actions/upload-artifact@v2
@@ -301,10 +291,8 @@ jobs:
301291
- run: ci/lib.sh --build
302292
- run: make
303293
- run: ci/lib.sh --test
304-
- run: make test
294+
- run: make test || ci/print-test-failures-github.sh
305295
if: success() && matrix.vector.skip-tests != 'no'
306-
- run: ci/print-test-failures.sh
307-
if: failure() && matrix.vector.skip-tests != 'no'
308296
- name: Upload failed tests' directories
309297
if: failure() && env.FAILED_TEST_ARTIFACTS != ''
310298
uses: actions/upload-artifact@v1

ci/print-test-failures-github.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
. ${0%/*}/lib-ci-type.sh
4+
5+
set -e
6+
7+
case "$CI_TYPE" in
8+
github-actions)
9+
handle_failed_tests () {
10+
mkdir -p t/failed-test-artifacts
11+
echo "FAILED_TEST_ARTIFACTS=t/failed-test-artifacts" >>$GITHUB_ENV
12+
13+
for test_exit in t/test-results/*.exit
14+
do
15+
test 0 != "$(cat "$test_exit")" || continue
16+
17+
test_name="${test_exit%.exit}"
18+
test_name="${test_name##*/}"
19+
printf "\\e[33m\\e[1m=== Failed test: ${test_name} ===\\e[m\\n"
20+
cat "t/test-results/$test_name.out"
21+
22+
trash_dir="t/trash directory.$test_name"
23+
cp "t/test-results/$test_name.out" t/failed-test-artifacts/
24+
tar czf t/failed-test-artifacts/"$test_name".trash.tar.gz "$trash_dir"
25+
done
26+
return 1
27+
}
28+
;;
29+
*)
30+
echo "Unhandled CI type: $CI_TYPE" >&2
31+
exit 1
32+
;;
33+
esac
34+
35+
handle_failed_tests

0 commit comments

Comments
 (0)