1
1
# Library of functions shared by all CI scripts
2
2
3
- if test true ! = " $GITHUB_ACTIONS "
3
+ if test true = " $GITHUB_ACTIONS "
4
4
then
5
- begin_group () { : ; }
6
- end_group () { : ; }
7
-
8
- group () {
9
- shift
10
- " $@ "
11
- }
12
- set -x
13
- else
14
5
begin_group () {
15
6
need_to_end_group=t
16
7
echo " ::group::$1 " >&2
23
14
need_to_end_group=
24
15
echo ' ::endgroup::' >&2
25
16
}
26
- trap end_group EXIT
17
+ elif test true = " $GITLAB_CI "
18
+ then
19
+ begin_group () {
20
+ need_to_end_group=t
21
+ printf " \e[0Ksection_start:$( date +%s) :$( echo " $1 " | tr ' ' _) \r\e[0K$1 \n"
22
+ trap " end_group '$1 '" EXIT
23
+ set -x
24
+ }
27
25
28
- group () {
26
+ end_group () {
27
+ test -n " $need_to_end_group " || return 0
29
28
set +x
30
- begin_group " $1 "
31
- shift
32
- # work around `dash` not supporting `set -o pipefail`
33
- (
34
- " $@ " 2>&1
35
- echo $? > exit.status
36
- ) |
37
- sed ' s/^\(\([^ ]*\):\([0-9]*\):\([0-9]*:\) \)\(error\|warning\): /::\5 file=\2,line=\3::\1/'
38
- res=$( cat exit.status)
39
- rm exit.status
40
- end_group
41
- return $res
29
+ need_to_end_group=
30
+ printf " \e[0Ksection_end:$( date +%s) :$( echo " $1 " | tr ' ' _) \r\e[0K\n"
31
+ trap - EXIT
42
32
}
33
+ else
34
+ begin_group () { : ; }
35
+ end_group () { : ; }
43
36
44
- begin_group " CI setup "
37
+ set -x
45
38
fi
46
39
40
+ group () {
41
+ group=" $1 "
42
+ shift
43
+ begin_group " $group "
44
+
45
+ # work around `dash` not supporting `set -o pipefail`
46
+ (
47
+ " $@ " 2>&1
48
+ echo $? > exit.status
49
+ ) |
50
+ sed ' s/^\(\([^ ]*\):\([0-9]*\):\([0-9]*:\) \)\(error\|warning\): /::\5 file=\2,line=\3::\1/'
51
+ res=$( cat exit.status)
52
+ rm exit.status
53
+
54
+ end_group " $group "
55
+ return $res
56
+ }
57
+
58
+ begin_group " CI setup"
59
+ trap " end_group 'CI setup'" EXIT
60
+
47
61
# Set 'exit on error' for all CI scripts to let the caller know that
48
62
# something went wrong.
49
63
#
@@ -71,10 +85,32 @@ skip_branch_tip_with_tag () {
71
85
fi
72
86
}
73
87
88
+ # Check whether we can use the path passed via the first argument as Git
89
+ # repository.
90
+ is_usable_git_repository () {
91
+ # We require Git in our PATH, otherwise we cannot access repositories
92
+ # at all.
93
+ if ! command -v git > /dev/null
94
+ then
95
+ return 1
96
+ fi
97
+
98
+ # And the target directory needs to be a proper Git repository.
99
+ if ! git -C " $1 " rev-parse 2> /dev/null
100
+ then
101
+ return 1
102
+ fi
103
+ }
104
+
74
105
# Save some info about the current commit's tree, so we can skip the build
75
106
# job if we encounter the same tree again and can provide a useful info
76
107
# message.
77
108
save_good_tree () {
109
+ if ! is_usable_git_repository .
110
+ then
111
+ return
112
+ fi
113
+
78
114
echo " $( git rev-parse $CI_COMMIT ^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID " >> " $good_trees_file "
79
115
# limit the file size
80
116
tail -1000 " $good_trees_file " > " $good_trees_file " .tmp
@@ -90,6 +126,11 @@ skip_good_tree () {
90
126
return
91
127
fi
92
128
129
+ if ! is_usable_git_repository .
130
+ then
131
+ return
132
+ fi
133
+
93
134
if ! good_tree_info=" $( grep " ^$( git rev-parse $CI_COMMIT ^{tree}) " " $good_trees_file " ) "
94
135
then
95
136
# Haven't seen this tree yet, or no cached good trees file yet.
@@ -121,6 +162,11 @@ skip_good_tree () {
121
162
}
122
163
123
164
check_unignored_build_artifacts () {
165
+ if ! is_usable_git_repository .
166
+ then
167
+ return
168
+ fi
169
+
124
170
! git ls-files --other --exclude-standard --error-unmatch \
125
171
-- ' :/*' 2> /dev/null ||
126
172
{
@@ -133,6 +179,26 @@ handle_failed_tests () {
133
179
return 1
134
180
}
135
181
182
+ create_failed_test_artifacts () {
183
+ mkdir -p t/failed-test-artifacts
184
+
185
+ for test_exit in t/test-results/* .exit
186
+ do
187
+ test 0 ! = " $( cat " $test_exit " ) " || continue
188
+
189
+ test_name=" ${test_exit% .exit} "
190
+ test_name=" ${test_name##*/ } "
191
+ printf " \\ e[33m\\ e[1m=== Failed test: ${test_name} ===\\ e[m\\ n"
192
+ echo " The full logs are in the 'print test failures' step below."
193
+ echo " See also the 'failed-tests-*' artifacts attached to this run."
194
+ cat " t/test-results/$test_name .markup"
195
+
196
+ trash_dir=" t/trash directory.$test_name "
197
+ cp " t/test-results/$test_name .out" t/failed-test-artifacts/
198
+ tar czf t/failed-test-artifacts/" $test_name " .trash.tar.gz " $trash_dir "
199
+ done
200
+ }
201
+
136
202
# GitHub Action doesn't set TERM, which is required by tput
137
203
export TERM=${TERM:- dumb}
138
204
@@ -156,11 +222,8 @@ then
156
222
# among *all* phases)
157
223
cache_dir=" $HOME /test-cache/$SYSTEM_PHASENAME "
158
224
159
- export GIT_PROVE_OPTS=" --timer --jobs 10 --state=failed,slow,save"
160
- export GIT_TEST_OPTS=" --verbose-log -x --write-junit-xml"
161
- MAKEFLAGS=" $MAKEFLAGS --jobs=10"
162
- test windows_nt ! = " $CI_OS_NAME " ||
163
- GIT_TEST_OPTS=" --no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS "
225
+ GIT_TEST_OPTS=" --write-junit-xml"
226
+ JOBS=10
164
227
elif test true = " $GITHUB_ACTIONS "
165
228
then
166
229
CI_TYPE=github-actions
@@ -173,40 +236,63 @@ then
173
236
CC=" ${CC_PACKAGE:- ${CC:- gcc} } "
174
237
DONT_SKIP_TAGS=t
175
238
handle_failed_tests () {
176
- mkdir -p t/failed-test-artifacts
177
239
echo " FAILED_TEST_ARTIFACTS=t/failed-test-artifacts" >> $GITHUB_ENV
240
+ create_failed_test_artifacts
241
+ return 1
242
+ }
178
243
179
- for test_exit in t/test-results/* .exit
180
- do
181
- test 0 ! = " $( cat " $test_exit " ) " || continue
182
-
183
- test_name=" ${test_exit% .exit} "
184
- test_name=" ${test_name##*/ } "
185
- printf " \\ e[33m\\ e[1m=== Failed test: ${test_name} ===\\ e[m\\ n"
186
- echo " The full logs are in the 'print test failures' step below."
187
- echo " See also the 'failed-tests-*' artifacts attached to this run."
188
- cat " t/test-results/$test_name .markup"
189
-
190
- trash_dir=" t/trash directory.$test_name "
191
- cp " t/test-results/$test_name .out" t/failed-test-artifacts/
192
- tar czf t/failed-test-artifacts/" $test_name " .trash.tar.gz " $trash_dir "
193
- done
244
+ cache_dir=" $HOME /none"
245
+
246
+ GIT_TEST_OPTS=" --github-workflow-markup"
247
+ JOBS=10
248
+ elif test true = " $GITLAB_CI "
249
+ then
250
+ CI_TYPE=gitlab-ci
251
+ CI_BRANCH=" $CI_COMMIT_REF_NAME "
252
+ CI_COMMIT=" $CI_COMMIT_SHA "
253
+ case " $CI_JOB_IMAGE " in
254
+ macos-* )
255
+ CI_OS_NAME=osx;;
256
+ alpine:* |fedora:* |ubuntu:* )
257
+ CI_OS_NAME=linux;;
258
+ * )
259
+ echo " Could not identify OS image" >&2
260
+ env >&2
261
+ exit 1
262
+ ;;
263
+ esac
264
+ CI_REPO_SLUG=" $CI_PROJECT_PATH "
265
+ CI_JOB_ID=" $CI_JOB_ID "
266
+ CC=" ${CC_PACKAGE:- ${CC:- gcc} } "
267
+ DONT_SKIP_TAGS=t
268
+ handle_failed_tests () {
269
+ create_failed_test_artifacts
194
270
return 1
195
271
}
196
272
197
273
cache_dir=" $HOME /none"
198
274
199
- export GIT_PROVE_OPTS=" --timer --jobs 10"
200
- export GIT_TEST_OPTS=" --verbose-log -x --github-workflow-markup"
201
- MAKEFLAGS=" $MAKEFLAGS --jobs=10"
202
- test windows ! = " $CI_OS_NAME " ||
203
- GIT_TEST_OPTS=" --no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS "
275
+ runs_on_pool=$( echo " $CI_JOB_IMAGE " | tr : -)
276
+ JOBS=$( nproc)
204
277
else
205
278
echo " Could not identify CI type" >&2
206
279
env >&2
207
280
exit 1
208
281
fi
209
282
283
+ MAKEFLAGS=" $MAKEFLAGS --jobs=$JOBS "
284
+ GIT_PROVE_OPTS=" --timer --jobs $JOBS --state=failed,slow,save"
285
+
286
+ GIT_TEST_OPTS=" $GIT_TEST_OPTS --verbose-log -x"
287
+ case " $CI_OS_NAME " in
288
+ windows|windows_nt)
289
+ GIT_TEST_OPTS=" $GIT_TEST_OPTS --no-chain-lint --no-bin-wrappers"
290
+ ;;
291
+ esac
292
+
293
+ export GIT_TEST_OPTS
294
+ export GIT_PROVE_OPTS
295
+
210
296
good_trees_file=" $cache_dir /good-trees"
211
297
212
298
mkdir -p " $cache_dir "
285
371
286
372
MAKEFLAGS=" $MAKEFLAGS CC=${CC:- cc} "
287
373
288
- end_group
374
+ end_group " CI setup "
289
375
set -x
0 commit comments