Skip to content

Commit e624f20

Browse files
pks-tgitster
authored andcommitted
ci: split out logic to set up failed test artifacts
We have some logic in place to create a directory with the output from failed tests, which will then subsequently be uploaded as CI artifacts. We're about to add support for GitLab CI, which will want to reuse the logic. Split the logic into a separate function so that it is reusable. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 412847c commit e624f20

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

ci/lib.sh

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ handle_failed_tests () {
131131
return 1
132132
}
133133

134+
create_failed_test_artifacts () {
135+
mkdir -p t/failed-test-artifacts
136+
137+
for test_exit in t/test-results/*.exit
138+
do
139+
test 0 != "$(cat "$test_exit")" || continue
140+
141+
test_name="${test_exit%.exit}"
142+
test_name="${test_name##*/}"
143+
printf "\\e[33m\\e[1m=== Failed test: ${test_name} ===\\e[m\\n"
144+
echo "The full logs are in the 'print test failures' step below."
145+
echo "See also the 'failed-tests-*' artifacts attached to this run."
146+
cat "t/test-results/$test_name.markup"
147+
148+
trash_dir="t/trash directory.$test_name"
149+
cp "t/test-results/$test_name.out" t/failed-test-artifacts/
150+
tar czf t/failed-test-artifacts/"$test_name".trash.tar.gz "$trash_dir"
151+
done
152+
}
153+
134154
# GitHub Action doesn't set TERM, which is required by tput
135155
export TERM=${TERM:-dumb}
136156

@@ -171,24 +191,8 @@ then
171191
CC="${CC_PACKAGE:-${CC:-gcc}}"
172192
DONT_SKIP_TAGS=t
173193
handle_failed_tests () {
174-
mkdir -p t/failed-test-artifacts
175194
echo "FAILED_TEST_ARTIFACTS=t/failed-test-artifacts" >>$GITHUB_ENV
176-
177-
for test_exit in t/test-results/*.exit
178-
do
179-
test 0 != "$(cat "$test_exit")" || continue
180-
181-
test_name="${test_exit%.exit}"
182-
test_name="${test_name##*/}"
183-
printf "\\e[33m\\e[1m=== Failed test: ${test_name} ===\\e[m\\n"
184-
echo "The full logs are in the 'print test failures' step below."
185-
echo "See also the 'failed-tests-*' artifacts attached to this run."
186-
cat "t/test-results/$test_name.markup"
187-
188-
trash_dir="t/trash directory.$test_name"
189-
cp "t/test-results/$test_name.out" t/failed-test-artifacts/
190-
tar czf t/failed-test-artifacts/"$test_name".trash.tar.gz "$trash_dir"
191-
done
195+
create_failed_test_artifacts
192196
return 1
193197
}
194198

0 commit comments

Comments
 (0)