1 # Library of functions shared by all CI scripts
3 skip_branch_tip_with_tag
() {
4 # Sometimes, a branch is pushed at the same time the tag that points
5 # at the same commit as the tip of the branch is pushed, and building
6 # both at the same time is a waste.
8 # When the build is triggered by a push to a tag, $CI_BRANCH will
9 # have that tagname, e.g. v2.14.0. Let's see if $CI_BRANCH is
10 # exactly at a tag, and if so, if it is different from $CI_BRANCH.
11 # That way, we can tell if we are building the tip of a branch that
12 # is tagged and we can skip the build because we won't be skipping a
15 if TAG
=$
(git describe
--exact-match "$CI_BRANCH" 2>/dev
/null
) &&
16 test "$TAG" != "$CI_BRANCH"
18 echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)"
23 # Save some info about the current commit's tree, so we can skip the build
24 # job if we encounter the same tree again and can provide a useful info
27 echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
29 tail -1000 "$good_trees_file" >"$good_trees_file".tmp
30 mv "$good_trees_file".tmp
"$good_trees_file"
33 # Skip the build job if the same tree has already been built and tested
34 # successfully before (e.g. because the branch got rebased, changing only
35 # the commit messages).
37 if test true
= "$GITHUB_ACTIONS"
42 if ! good_tree_info
="$(grep "^$
(git rev-parse
$CI_COMMIT^
{tree
}) " "$good_trees_file")"
44 # Haven't seen this tree yet, or no cached good trees file yet.
45 # Continue the build job.
49 echo "$good_tree_info" |
{
50 read tree prev_good_commit prev_good_job_number prev_good_job_id
52 if test "$CI_JOB_ID" = "$prev_good_job_id"
55 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
56 This commit has already been built and tested successfully by this build job.
57 To force a re-build delete the branch's cache and then hit 'Restart job'.
61 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
62 This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit.
63 The log of that build job is available at $SYSTEM_TASKDEFINITIONSURI$SYSTEM_TEAMPROJECT/_build/results?buildId=$prev_good_job_id
64 To force a re-build delete the branch's cache and then hit 'Restart job'.
72 check_unignored_build_artifacts
() {
73 ! git ls-files
--other --exclude-standard --error-unmatch \
74 -- ':/*' 2>/dev
/null ||
76 echo "$(tput setaf 1)error: found unignored build artifacts$(tput sgr0)"
81 # GitHub Action doesn't set TERM, which is required by tput
82 export TERM
=${TERM:-dumb}
84 # Clear MAKEFLAGS that may come from the outside world.
87 # Set 'exit on error' for all CI scripts to let the caller know that
88 # something went wrong.
89 # Set tracing executed commands, primarily setting environment variables
90 # and installing dependencies.
93 if test -n "$SYSTEM_COLLECTIONURI" ||
test -n "$SYSTEM_TASKDEFINITIONSURI"
95 CI_TYPE
=azure-pipelines
96 # We are running in Azure Pipelines
97 CI_BRANCH
="$BUILD_SOURCEBRANCH"
98 CI_COMMIT
="$BUILD_SOURCEVERSION"
99 CI_JOB_ID
="$BUILD_BUILDID"
100 CI_JOB_NUMBER
="$BUILD_BUILDNUMBER"
101 CI_OS_NAME
="$(echo "$AGENT_OS" | tr A-Z a-z)"
102 test darwin
!= "$CI_OS_NAME" || CI_OS_NAME
=osx
103 CI_REPO_SLUG
="$(expr "$BUILD_REPOSITORY_URI" : '.*/\([^/]*/[^/]*\)$')"
106 # use a subdirectory of the cache dir (because the file share is shared
107 # among *all* phases)
108 cache_dir
="$HOME/test-cache/$SYSTEM_PHASENAME"
110 export GIT_PROVE_OPTS
="--timer --jobs 10 --state=failed,slow,save"
111 export GIT_TEST_OPTS
="--verbose-log -x --write-junit-xml"
112 MAKEFLAGS
="$MAKEFLAGS --jobs=10"
113 test windows_nt
!= "$CI_OS_NAME" ||
114 GIT_TEST_OPTS
="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
115 elif test true
= "$GITHUB_ACTIONS"
117 CI_TYPE
=github-actions
118 CI_BRANCH
="$GITHUB_REF"
119 CI_COMMIT
="$GITHUB_SHA"
120 CI_OS_NAME
="$(echo "$RUNNER_OS" | tr A-Z a-z)"
121 test macos
!= "$CI_OS_NAME" || CI_OS_NAME
=osx
122 CI_REPO_SLUG
="$GITHUB_REPOSITORY"
123 CI_JOB_ID
="$GITHUB_RUN_ID"
124 CC
="${CC_PACKAGE:-${CC:-gcc}}"
127 cache_dir
="$HOME/none"
129 export GIT_PROVE_OPTS
="--timer --jobs 10"
130 export GIT_TEST_OPTS
="--verbose-log -x"
131 MAKEFLAGS
="$MAKEFLAGS --jobs=10"
132 test windows
!= "$CI_OS_NAME" ||
133 GIT_TEST_OPTS
="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
135 echo "Could not identify CI type" >&2
140 good_trees_file
="$cache_dir/good-trees"
142 mkdir
-p "$cache_dir"
144 test -n "${DONT_SKIP_TAGS-}" ||
145 skip_branch_tip_with_tag
148 if test -z "$jobname"
150 jobname
="$CI_OS_NAME-$CC"
154 export DEFAULT_TEST_TARGET
=prove
155 export GIT_TEST_CLONE_2GB
=true
156 export SKIP_DASHED_BUILT_INS
=YesPlease
158 case "$runs_on_pool" in
160 if test "$jobname" = "linux-gcc-default"
165 if [ "$jobname" = linux-gcc
]
167 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3"
169 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/python2"
172 export GIT_TEST_HTTPD
=true
174 # The Linux build installs the defined dependency versions below.
175 # The OS X build installs much more recent versions, whichever
176 # were recorded in the Homebrew database upon creating the OS X
178 # Keep that in mind when you encounter a broken OS X build!
179 export LINUX_P4_VERSION
="16.2"
180 export LINUX_GIT_LFS_VERSION
="1.5.2"
182 P4_PATH
="$HOME/custom/p4"
183 GIT_LFS_PATH
="$HOME/custom/git-lfs"
184 export PATH
="$GIT_LFS_PATH:$P4_PATH:$PATH"
187 if [ "$jobname" = osx-gcc
]
189 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=$(which python3)"
191 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=$(which python2)"
202 MAKEFLAGS
="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3 USE_LIBPCRE2=Yes"
203 MAKEFLAGS
="$MAKEFLAGS NO_REGEX=Yes ICONV_OMITS_BOM=Yes"
204 MAKEFLAGS
="$MAKEFLAGS GIT_TEST_UTF8_LOCALE=C.UTF-8"
208 export GIT_TEST_PASSING_SANITIZE_LEAK
=true
212 MAKEFLAGS
="$MAKEFLAGS CC=${CC:-cc}"