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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Nov 9, 2023 at 09:05 UTC
e624f206bc07201562619e2a9788e2b3762409fc
1 file changed
+21
-17
ci/lib.sh
+21
-17
@@ -131,6 +131,26 @@ handle_failed_tests () {
131
return 1
132
}
133
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
+
154
# GitHub Action doesn't set TERM, which is required by tput
155
export TERM=${TERM:-dumb}
156
@@ -171,24 +191,8 @@ then
191
CC="${CC_PACKAGE:-${CC:-gcc}}"
192
DONT_SKIP_TAGS=t
193
handle_failed_tests () {
174
- mkdir -p t/failed-test-artifacts
194
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
196
return 1
197
}
198