1 # Library of functions shared by all CI scripts
3 if test true
= "$GITHUB_ACTIONS"
12 test -n "$need_to_end_group" ||
return 0
15 echo '::endgroup::' >&2
17 elif test true
= "$GITLAB_CI"
21 printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
22 trap "end_group '$1'" EXIT
27 test -n "$need_to_end_group" ||
return 0
30 printf "\e[0Ksection_end:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K\n"
45 # work around `dash` not supporting `set -o pipefail`
50 sed 's/^\(\([^ ]*\):\([0-9]*\):\([0-9]*:\) \)\(error\|warning\): /::\5 file=\2,line=\3::\1/'
51 res
=$
(cat exit.status
)
58 begin_group
"CI setup"
59 trap "end_group 'CI setup'" EXIT
61 # Set 'exit on error' for all CI scripts to let the caller know that
62 # something went wrong.
64 # We already enabled tracing executed commands earlier. This helps by showing
65 # how # environment variables are set and dependencies are installed.
68 skip_branch_tip_with_tag
() {
69 # Sometimes, a branch is pushed at the same time the tag that points
70 # at the same commit as the tip of the branch is pushed, and building
71 # both at the same time is a waste.
73 # When the build is triggered by a push to a tag, $CI_BRANCH will
74 # have that tagname, e.g. v2.14.0. Let's see if $CI_BRANCH is
75 # exactly at a tag, and if so, if it is different from $CI_BRANCH.
76 # That way, we can tell if we are building the tip of a branch that
77 # is tagged and we can skip the build because we won't be skipping a
80 if TAG
=$
(git describe
--exact-match "$CI_BRANCH" 2>/dev
/null
) &&
81 test "$TAG" != "$CI_BRANCH"
83 echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)"
88 # Check whether we can use the path passed via the first argument as Git
90 is_usable_git_repository
() {
91 # We require Git in our PATH, otherwise we cannot access repositories
93 if ! command -v git
>/dev
/null
98 # And the target directory needs to be a proper Git repository.
99 if ! git
-C "$1" rev-parse
2>/dev
/null
105 # Save some info about the current commit's tree, so we can skip the build
106 # job if we encounter the same tree again and can provide a useful info
109 if ! is_usable_git_repository .
114 echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
115 # limit the file size
116 tail -1000 "$good_trees_file" >"$good_trees_file".tmp
117 mv "$good_trees_file".tmp
"$good_trees_file"
120 # Skip the build job if the same tree has already been built and tested
121 # successfully before (e.g. because the branch got rebased, changing only
122 # the commit messages).
124 if test true
= "$GITHUB_ACTIONS"
129 if ! is_usable_git_repository .
134 if ! good_tree_info
="$(grep "^$
(git rev-parse
$CI_COMMIT^
{tree
}) " "$good_trees_file")"
136 # Haven't seen this tree yet, or no cached good trees file yet.
137 # Continue the build job.
141 echo "$good_tree_info" |
{
142 read tree prev_good_commit prev_good_job_number prev_good_job_id
144 if test "$CI_JOB_ID" = "$prev_good_job_id"
147 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
148 This commit has already been built and tested successfully by this build job.
149 To force a re-build delete the branch's cache and then hit 'Restart job'.
153 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
154 This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit.
155 The log of that build job is available at $SYSTEM_TASKDEFINITIONSURI$SYSTEM_TEAMPROJECT/_build/results?buildId=$prev_good_job_id
156 To force a re-build delete the branch's cache and then hit 'Restart job'.
164 check_unignored_build_artifacts
() {
165 if ! is_usable_git_repository .
170 ! git ls-files
--other --exclude-standard --error-unmatch \
171 -- ':/*' 2>/dev
/null ||
173 echo "$(tput setaf 1)error: found unignored build artifacts$(tput sgr0)"
178 handle_failed_tests
() {
182 create_failed_test_artifacts
() {
183 mkdir
-p t
/failed-test-artifacts
185 for test_exit
in t
/test-results
/*.
exit
187 test 0 != "$(cat "$test_exit")" ||
continue
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"
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"
202 # GitHub Action doesn't set TERM, which is required by tput
203 export TERM
=${TERM:-dumb}
205 # Clear MAKEFLAGS that may come from the outside world.
208 if test -n "$SYSTEM_COLLECTIONURI" ||
test -n "$SYSTEM_TASKDEFINITIONSURI"
210 CI_TYPE
=azure-pipelines
211 # We are running in Azure Pipelines
212 CI_BRANCH
="$BUILD_SOURCEBRANCH"
213 CI_COMMIT
="$BUILD_SOURCEVERSION"
214 CI_JOB_ID
="$BUILD_BUILDID"
215 CI_JOB_NUMBER
="$BUILD_BUILDNUMBER"
216 CI_OS_NAME
="$(echo "$AGENT_OS" | tr A-Z a-z)"
217 test darwin
!= "$CI_OS_NAME" || CI_OS_NAME
=osx
218 CI_REPO_SLUG
="$(expr "$BUILD_REPOSITORY_URI" : '.*/\([^/]*/[^/]*\)$')"
221 # use a subdirectory of the cache dir (because the file share is shared
222 # among *all* phases)
223 cache_dir
="$HOME/test-cache/$SYSTEM_PHASENAME"
225 GIT_TEST_OPTS
="--write-junit-xml"
227 elif test true
= "$GITHUB_ACTIONS"
229 CI_TYPE
=github-actions
230 CI_BRANCH
="$GITHUB_REF"
231 CI_COMMIT
="$GITHUB_SHA"
232 CI_OS_NAME
="$(echo "$RUNNER_OS" | tr A-Z a-z)"
233 test macos
!= "$CI_OS_NAME" || CI_OS_NAME
=osx
234 CI_REPO_SLUG
="$GITHUB_REPOSITORY"
235 CI_JOB_ID
="$GITHUB_RUN_ID"
236 CC
="${CC_PACKAGE:-${CC:-gcc}}"
238 handle_failed_tests
() {
239 echo "FAILED_TEST_ARTIFACTS=t/failed-test-artifacts" >>$GITHUB_ENV
240 create_failed_test_artifacts
244 cache_dir
="$HOME/none"
246 GIT_TEST_OPTS
="--github-workflow-markup"
248 elif test true
= "$GITLAB_CI"
251 CI_BRANCH
="$CI_COMMIT_REF_NAME"
252 CI_COMMIT
="$CI_COMMIT_SHA"
254 case "$OS,$CI_JOB_IMAGE" in
257 JOBS
=$NUMBER_OF_PROCESSORS
260 # GitLab CI has Python installed via multiple package managers,
261 # most notably via asdf and Homebrew. Ensure that our builds
262 # pick up the Homebrew one by prepending it to our PATH as the
263 # asdf one breaks tests.
264 export PATH
="$(brew --prefix)/bin:$PATH"
269 *,alpine
:*|
*,fedora
:*|
*,ubuntu
:*)
274 echo "Could not identify OS image" >&2
279 CI_REPO_SLUG
="$CI_PROJECT_PATH"
280 CI_JOB_ID
="$CI_JOB_ID"
281 CC
="${CC_PACKAGE:-${CC:-gcc}}"
284 handle_failed_tests
() {
285 create_failed_test_artifacts
289 cache_dir
="$HOME/none"
291 distro
=$
(echo "$CI_JOB_IMAGE" |
tr : -)
293 echo "Could not identify CI type" >&2
298 MAKEFLAGS
="$MAKEFLAGS --jobs=$JOBS"
299 GIT_PROVE_OPTS
="--timer --jobs $JOBS"
301 GIT_TEST_OPTS
="$GIT_TEST_OPTS --verbose-log -x"
302 case "$CI_OS_NAME" in
304 GIT_TEST_OPTS
="$GIT_TEST_OPTS --no-chain-lint --no-bin-wrappers"
309 export GIT_PROVE_OPTS
311 good_trees_file
="$cache_dir/good-trees"
313 mkdir
-p "$cache_dir"
315 test -n "${DONT_SKIP_TAGS-}" ||
316 skip_branch_tip_with_tag
319 if test -z "$jobname"
321 jobname
="$CI_OS_NAME-$CC"
325 export DEFAULT_TEST_TARGET
=prove
326 export GIT_TEST_CLONE_2GB
=true
327 export SKIP_DASHED_BUILT_INS
=YesPlease
331 if test "$jobname" = "linux-gcc-default"
336 # Python 2 is end of life, and Ubuntu 23.04 and newer don't actually
337 # have it anymore. We thus only test with Python 2 on older LTS
339 if test "$distro" = "ubuntu-20.04"
341 PYTHON_PACKAGE
=python2
343 PYTHON_PACKAGE
=python3
345 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/$PYTHON_PACKAGE"
349 # Apache is too old for HTTP/2.
352 export GIT_TEST_HTTPD
=true
356 # The Linux build installs the defined dependency versions below.
357 # The OS X build installs much more recent versions, whichever
358 # were recorded in the Homebrew database upon creating the OS X
360 # Keep that in mind when you encounter a broken OS X build!
361 export LINUX_GIT_LFS_VERSION
="1.5.2"
364 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=$(which python3)"
365 if [ "$jobname" != osx-gcc
]
367 MAKEFLAGS
="$MAKEFLAGS APPLE_COMMON_CRYPTO_SHA1=Yes"
372 CUSTOM_PATH
="${CUSTOM_PATH:-$HOME/path}"
373 export PATH
="$CUSTOM_PATH:$PATH"
381 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3 USE_LIBPCRE2=Yes"
382 MAKEFLAGS
="$MAKEFLAGS NO_REGEX=Yes ICONV_OMITS_BOM=Yes"
383 MAKEFLAGS
="$MAKEFLAGS GIT_TEST_UTF8_LOCALE=C.UTF-8"
385 linux-leaks|linux-reftable-leaks
)
387 export GIT_TEST_PASSING_SANITIZE_LEAK
=true
390 export SANITIZE
=address
,undefined
391 export NO_SVN_TESTS
=LetsSaveSomeTime
392 MAKEFLAGS
="$MAKEFLAGS NO_PYTHON=YepBecauseP4FlakesTooOften"
396 MAKEFLAGS
="$MAKEFLAGS CC=${CC:-cc}"