1 # Library of functions shared by all CI scripts
3 if test true
!= "$GITHUB_ACTIONS"
16 echo "::group::$1" >&2
21 test -n "$need_to_end_group" ||
return 0
24 echo '::endgroup::' >&2
32 # work around `dash` not supporting `set -o pipefail`
37 sed 's/^\(\([^ ]*\):\([0-9]*\):\([0-9]*:\) \)\(error\|warning\): /::\5 file=\2,line=\3::\1/'
38 res
=$
(cat exit.status
)
44 begin_group
"CI setup"
47 # Set 'exit on error' for all CI scripts to let the caller know that
48 # something went wrong.
50 # We already enabled tracing executed commands earlier. This helps by showing
51 # how # environment variables are set and and dependencies are installed.
54 skip_branch_tip_with_tag
() {
55 # Sometimes, a branch is pushed at the same time the tag that points
56 # at the same commit as the tip of the branch is pushed, and building
57 # both at the same time is a waste.
59 # When the build is triggered by a push to a tag, $CI_BRANCH will
60 # have that tagname, e.g. v2.14.0. Let's see if $CI_BRANCH is
61 # exactly at a tag, and if so, if it is different from $CI_BRANCH.
62 # That way, we can tell if we are building the tip of a branch that
63 # is tagged and we can skip the build because we won't be skipping a
66 if TAG
=$
(git describe
--exact-match "$CI_BRANCH" 2>/dev
/null
) &&
67 test "$TAG" != "$CI_BRANCH"
69 echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)"
74 # Save some info about the current commit's tree, so we can skip the build
75 # job if we encounter the same tree again and can provide a useful info
78 echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
80 tail -1000 "$good_trees_file" >"$good_trees_file".tmp
81 mv "$good_trees_file".tmp
"$good_trees_file"
84 # Skip the build job if the same tree has already been built and tested
85 # successfully before (e.g. because the branch got rebased, changing only
86 # the commit messages).
88 if test true
= "$GITHUB_ACTIONS"
93 if ! good_tree_info
="$(grep "^$
(git rev-parse
$CI_COMMIT^
{tree
}) " "$good_trees_file")"
95 # Haven't seen this tree yet, or no cached good trees file yet.
96 # Continue the build job.
100 echo "$good_tree_info" |
{
101 read tree prev_good_commit prev_good_job_number prev_good_job_id
103 if test "$CI_JOB_ID" = "$prev_good_job_id"
106 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
107 This commit has already been built and tested successfully by this build job.
108 To force a re-build delete the branch's cache and then hit 'Restart job'.
112 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
113 This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit.
114 The log of that build job is available at $SYSTEM_TASKDEFINITIONSURI$SYSTEM_TEAMPROJECT/_build/results?buildId=$prev_good_job_id
115 To force a re-build delete the branch's cache and then hit 'Restart job'.
123 check_unignored_build_artifacts
() {
124 ! git ls-files
--other --exclude-standard --error-unmatch \
125 -- ':/*' 2>/dev
/null ||
127 echo "$(tput setaf 1)error: found unignored build artifacts$(tput sgr0)"
132 handle_failed_tests
() {
136 # GitHub Action doesn't set TERM, which is required by tput
137 export TERM
=${TERM:-dumb}
139 # Clear MAKEFLAGS that may come from the outside world.
142 if test -n "$SYSTEM_COLLECTIONURI" ||
test -n "$SYSTEM_TASKDEFINITIONSURI"
144 CI_TYPE
=azure-pipelines
145 # We are running in Azure Pipelines
146 CI_BRANCH
="$BUILD_SOURCEBRANCH"
147 CI_COMMIT
="$BUILD_SOURCEVERSION"
148 CI_JOB_ID
="$BUILD_BUILDID"
149 CI_JOB_NUMBER
="$BUILD_BUILDNUMBER"
150 CI_OS_NAME
="$(echo "$AGENT_OS" | tr A-Z a-z)"
151 test darwin
!= "$CI_OS_NAME" || CI_OS_NAME
=osx
152 CI_REPO_SLUG
="$(expr "$BUILD_REPOSITORY_URI" : '.*/\([^/]*/[^/]*\)$')"
155 # use a subdirectory of the cache dir (because the file share is shared
156 # among *all* phases)
157 cache_dir
="$HOME/test-cache/$SYSTEM_PHASENAME"
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"
164 elif test true
= "$GITHUB_ACTIONS"
166 CI_TYPE
=github-actions
167 CI_BRANCH
="$GITHUB_REF"
168 CI_COMMIT
="$GITHUB_SHA"
169 CI_OS_NAME
="$(echo "$RUNNER_OS" | tr A-Z a-z)"
170 test macos
!= "$CI_OS_NAME" || CI_OS_NAME
=osx
171 CI_REPO_SLUG
="$GITHUB_REPOSITORY"
172 CI_JOB_ID
="$GITHUB_RUN_ID"
173 CC
="${CC_PACKAGE:-${CC:-gcc}}"
175 handle_failed_tests
() {
176 mkdir
-p t
/failed-test-artifacts
177 echo "FAILED_TEST_ARTIFACTS=t/failed-test-artifacts" >>$GITHUB_ENV
179 for test_exit
in t
/test-results
/*.
exit
181 test 0 != "$(cat "$test_exit")" ||
continue
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"
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"
197 cache_dir
="$HOME/none"
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"
205 echo "Could not identify CI type" >&2
210 good_trees_file
="$cache_dir/good-trees"
212 mkdir
-p "$cache_dir"
214 test -n "${DONT_SKIP_TAGS-}" ||
215 skip_branch_tip_with_tag
218 if test -z "$jobname"
220 jobname
="$CI_OS_NAME-$CC"
224 export DEFAULT_TEST_TARGET
=prove
225 export GIT_TEST_CLONE_2GB
=true
226 export SKIP_DASHED_BUILT_INS
=YesPlease
228 case "$runs_on_pool" in
230 if test "$jobname" = "linux-gcc-default"
235 PYTHON_PACKAGE
=python2
236 if test "$jobname" = linux-gcc
238 PYTHON_PACKAGE
=python3
240 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/$PYTHON_PACKAGE"
242 export GIT_TEST_HTTPD
=true
244 # The Linux build installs the defined dependency versions below.
245 # The OS X build installs much more recent versions, whichever
246 # were recorded in the Homebrew database upon creating the OS X
248 # Keep that in mind when you encounter a broken OS X build!
249 export LINUX_GIT_LFS_VERSION
="1.5.2"
251 P4_PATH
="$HOME/custom/p4"
252 GIT_LFS_PATH
="$HOME/custom/git-lfs"
253 export PATH
="$GIT_LFS_PATH:$P4_PATH:$PATH"
256 if [ "$jobname" = osx-gcc
]
258 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=$(which python3)"
260 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=$(which python2)"
261 MAKEFLAGS
="$MAKEFLAGS APPLE_COMMON_CRYPTO_SHA1=Yes"
272 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3 USE_LIBPCRE2=Yes"
273 MAKEFLAGS
="$MAKEFLAGS NO_REGEX=Yes ICONV_OMITS_BOM=Yes"
274 MAKEFLAGS
="$MAKEFLAGS GIT_TEST_UTF8_LOCALE=C.UTF-8"
278 export GIT_TEST_PASSING_SANITIZE_LEAK
=true
279 export GIT_TEST_SANITIZE_LEAK_LOG
=true
282 export SANITIZE
=address
,undefined
283 export NO_SVN_TESTS
=LetsSaveSomeTime
284 MAKEFLAGS
="$MAKEFLAGS NO_PYTHON=YepBecauseP4FlakesTooOften"
288 MAKEFLAGS
="$MAKEFLAGS CC=${CC:-cc}"