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
38 begin_group
"CI setup"
41 # Set 'exit on error' for all CI scripts to let the caller know that
42 # something went wrong.
44 # We already enabled tracing executed commands earlier. This helps by showing
45 # how # environment variables are set and and dependencies are installed.
48 skip_branch_tip_with_tag
() {
49 # Sometimes, a branch is pushed at the same time the tag that points
50 # at the same commit as the tip of the branch is pushed, and building
51 # both at the same time is a waste.
53 # When the build is triggered by a push to a tag, $CI_BRANCH will
54 # have that tagname, e.g. v2.14.0. Let's see if $CI_BRANCH is
55 # exactly at a tag, and if so, if it is different from $CI_BRANCH.
56 # That way, we can tell if we are building the tip of a branch that
57 # is tagged and we can skip the build because we won't be skipping a
60 if TAG
=$
(git describe
--exact-match "$CI_BRANCH" 2>/dev
/null
) &&
61 test "$TAG" != "$CI_BRANCH"
63 echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)"
68 # Save some info about the current commit's tree, so we can skip the build
69 # job if we encounter the same tree again and can provide a useful info
72 echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
74 tail -1000 "$good_trees_file" >"$good_trees_file".tmp
75 mv "$good_trees_file".tmp
"$good_trees_file"
78 # Skip the build job if the same tree has already been built and tested
79 # successfully before (e.g. because the branch got rebased, changing only
80 # the commit messages).
82 if test true
= "$GITHUB_ACTIONS"
87 if ! good_tree_info
="$(grep "^$
(git rev-parse
$CI_COMMIT^
{tree
}) " "$good_trees_file")"
89 # Haven't seen this tree yet, or no cached good trees file yet.
90 # Continue the build job.
94 echo "$good_tree_info" |
{
95 read tree prev_good_commit prev_good_job_number prev_good_job_id
97 if test "$CI_JOB_ID" = "$prev_good_job_id"
100 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
101 This commit has already been built and tested successfully by this build job.
102 To force a re-build delete the branch's cache and then hit 'Restart job'.
106 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
107 This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit.
108 The log of that build job is available at $SYSTEM_TASKDEFINITIONSURI$SYSTEM_TEAMPROJECT/_build/results?buildId=$prev_good_job_id
109 To force a re-build delete the branch's cache and then hit 'Restart job'.
117 check_unignored_build_artifacts
() {
118 ! git ls-files
--other --exclude-standard --error-unmatch \
119 -- ':/*' 2>/dev
/null ||
121 echo "$(tput setaf 1)error: found unignored build artifacts$(tput sgr0)"
126 handle_failed_tests
() {
130 # GitHub Action doesn't set TERM, which is required by tput
131 export TERM
=${TERM:-dumb}
133 # Clear MAKEFLAGS that may come from the outside world.
136 if test -n "$SYSTEM_COLLECTIONURI" ||
test -n "$SYSTEM_TASKDEFINITIONSURI"
138 CI_TYPE
=azure-pipelines
139 # We are running in Azure Pipelines
140 CI_BRANCH
="$BUILD_SOURCEBRANCH"
141 CI_COMMIT
="$BUILD_SOURCEVERSION"
142 CI_JOB_ID
="$BUILD_BUILDID"
143 CI_JOB_NUMBER
="$BUILD_BUILDNUMBER"
144 CI_OS_NAME
="$(echo "$AGENT_OS" | tr A-Z a-z)"
145 test darwin
!= "$CI_OS_NAME" || CI_OS_NAME
=osx
146 CI_REPO_SLUG
="$(expr "$BUILD_REPOSITORY_URI" : '.*/\([^/]*/[^/]*\)$')"
149 # use a subdirectory of the cache dir (because the file share is shared
150 # among *all* phases)
151 cache_dir
="$HOME/test-cache/$SYSTEM_PHASENAME"
153 export GIT_PROVE_OPTS
="--timer --jobs 10 --state=failed,slow,save"
154 export GIT_TEST_OPTS
="--verbose-log -x --write-junit-xml"
155 MAKEFLAGS
="$MAKEFLAGS --jobs=10"
156 test windows_nt
!= "$CI_OS_NAME" ||
157 GIT_TEST_OPTS
="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
158 elif test true
= "$GITHUB_ACTIONS"
160 CI_TYPE
=github-actions
161 CI_BRANCH
="$GITHUB_REF"
162 CI_COMMIT
="$GITHUB_SHA"
163 CI_OS_NAME
="$(echo "$RUNNER_OS" | tr A-Z a-z)"
164 test macos
!= "$CI_OS_NAME" || CI_OS_NAME
=osx
165 CI_REPO_SLUG
="$GITHUB_REPOSITORY"
166 CI_JOB_ID
="$GITHUB_RUN_ID"
167 CC
="${CC_PACKAGE:-${CC:-gcc}}"
169 handle_failed_tests
() {
170 mkdir
-p t
/failed-test-artifacts
171 echo "FAILED_TEST_ARTIFACTS=t/failed-test-artifacts" >>$GITHUB_ENV
173 for test_exit
in t
/test-results
/*.
exit
175 test 0 != "$(cat "$test_exit")" ||
continue
177 test_name
="${test_exit%.exit}"
178 test_name
="${test_name##*/}"
179 printf "\\e[33m\\e[1m=== Failed test: ${test_name} ===\\e[m\\n"
180 echo "The full logs are in the artifacts attached to this run."
181 cat "t/test-results/$test_name.markup"
183 trash_dir
="t/trash directory.$test_name"
184 cp "t/test-results/$test_name.out" t
/failed-test-artifacts
/
185 tar czf t
/failed-test-artifacts
/"$test_name".trash.
tar.gz
"$trash_dir"
190 cache_dir
="$HOME/none"
192 export GIT_PROVE_OPTS
="--timer --jobs 10"
193 export GIT_TEST_OPTS
="--verbose-log -x --github-workflow-markup"
194 MAKEFLAGS
="$MAKEFLAGS --jobs=10"
195 test windows
!= "$CI_OS_NAME" ||
196 GIT_TEST_OPTS
="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
198 echo "Could not identify CI type" >&2
203 good_trees_file
="$cache_dir/good-trees"
205 mkdir
-p "$cache_dir"
207 test -n "${DONT_SKIP_TAGS-}" ||
208 skip_branch_tip_with_tag
211 if test -z "$jobname"
213 jobname
="$CI_OS_NAME-$CC"
217 export DEFAULT_TEST_TARGET
=prove
218 export GIT_TEST_CLONE_2GB
=true
219 export SKIP_DASHED_BUILT_INS
=YesPlease
221 case "$runs_on_pool" in
223 if test "$jobname" = "linux-gcc-default"
228 if [ "$jobname" = linux-gcc
]
230 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3"
232 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/python2"
235 export GIT_TEST_HTTPD
=true
237 # The Linux build installs the defined dependency versions below.
238 # The OS X build installs much more recent versions, whichever
239 # were recorded in the Homebrew database upon creating the OS X
241 # Keep that in mind when you encounter a broken OS X build!
242 export LINUX_P4_VERSION
="16.2"
243 export LINUX_GIT_LFS_VERSION
="1.5.2"
245 P4_PATH
="$HOME/custom/p4"
246 GIT_LFS_PATH
="$HOME/custom/git-lfs"
247 export PATH
="$GIT_LFS_PATH:$P4_PATH:$PATH"
250 if [ "$jobname" = osx-gcc
]
252 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=$(which python3)"
254 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=$(which python2)"
265 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3 USE_LIBPCRE2=Yes"
266 MAKEFLAGS
="$MAKEFLAGS NO_REGEX=Yes ICONV_OMITS_BOM=Yes"
267 MAKEFLAGS
="$MAKEFLAGS GIT_TEST_UTF8_LOCALE=C.UTF-8"
271 export GIT_TEST_PASSING_SANITIZE_LEAK
=true
275 MAKEFLAGS
="$MAKEFLAGS CC=${CC:-cc}"