blob: 9d28ab50fb4462a1b064e8c89cd5f13518fd86cd [file] [log] [blame]
Lars Schneider657343a2017-09-10 16:44:28 +02001# Library of functions shared by all CI scripts
2
Lars Schneider09f5e972017-09-10 16:44:29 +02003skip_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.
7 #
Johannes Schindelin4096a982019-01-27 15:26:49 -08008 # 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
13 # build of a tag.
Lars Schneider09f5e972017-09-10 16:44:29 +020014
Johannes Schindelin4096a982019-01-27 15:26:49 -080015 if TAG=$(git describe --exact-match "$CI_BRANCH" 2>/dev/null) &&
16 test "$TAG" != "$CI_BRANCH"
Lars Schneider09f5e972017-09-10 16:44:29 +020017 then
Johannes Schindelin4096a982019-01-27 15:26:49 -080018 echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)"
Lars Schneider09f5e972017-09-10 16:44:29 +020019 exit 0
20 fi
21}
22
SZEDER Gábor9cc2c762017-12-31 11:12:05 +010023# 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
25# message.
26save_good_tree () {
Johannes Schindelinb011fab2019-01-27 15:26:51 -080027 echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
SZEDER Gábor9cc2c762017-12-31 11:12:05 +010028 # limit the file size
29 tail -1000 "$good_trees_file" >"$good_trees_file".tmp
30 mv "$good_trees_file".tmp "$good_trees_file"
31}
32
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).
36skip_good_tree () {
Ævar Arnfjörð Bjarmason4a6e4b92021-11-23 17:29:08 +010037 if test true = "$GITHUB_ACTIONS"
SZEDER Gáborc46ebc22019-09-21 09:40:54 +020038 then
39 return
40 fi
41
Johannes Schindelinb011fab2019-01-27 15:26:51 -080042 if ! good_tree_info="$(grep "^$(git rev-parse $CI_COMMIT^{tree}) " "$good_trees_file")"
SZEDER Gábor9cc2c762017-12-31 11:12:05 +010043 then
44 # Haven't seen this tree yet, or no cached good trees file yet.
45 # Continue the build job.
46 return
47 fi
48
49 echo "$good_tree_info" | {
50 read tree prev_good_commit prev_good_job_number prev_good_job_id
51
Johannes Schindelinb011fab2019-01-27 15:26:51 -080052 if test "$CI_JOB_ID" = "$prev_good_job_id"
SZEDER Gábor9cc2c762017-12-31 11:12:05 +010053 then
54 cat <<-EOF
Johannes Schindelinb011fab2019-01-27 15:26:51 -080055 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
SZEDER Gábor9cc2c762017-12-31 11:12:05 +010056 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'.
58 EOF
59 else
60 cat <<-EOF
Johannes Schindelinb011fab2019-01-27 15:26:51 -080061 $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
SZEDER Gábor9cc2c762017-12-31 11:12:05 +010062 This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit.
Ævar Arnfjörð Bjarmason4a6e4b92021-11-23 17:29:08 +010063 The log of that build job is available at $SYSTEM_TASKDEFINITIONSURI$SYSTEM_TEAMPROJECT/_build/results?buildId=$prev_good_job_id
SZEDER Gábor9cc2c762017-12-31 11:12:05 +010064 To force a re-build delete the branch's cache and then hit 'Restart job'.
65 EOF
66 fi
67 }
68
69 exit 0
70}
71
SZEDER Gáborb92cb862017-12-31 17:02:06 +010072check_unignored_build_artifacts ()
73{
74 ! git ls-files --other --exclude-standard --error-unmatch \
75 -- ':/*' 2>/dev/null ||
76 {
77 echo "$(tput setaf 1)error: found unignored build artifacts$(tput sgr0)"
78 false
79 }
80}
81
Đoàn Trần Công Danh855c1582020-04-08 11:05:34 +070082# GitHub Action doesn't set TERM, which is required by tput
83export TERM=${TERM:-dumb}
84
Junio C Hamanoa8c51f72019-02-07 11:36:28 -080085# Clear MAKEFLAGS that may come from the outside world.
86export MAKEFLAGS=
87
Lars Schneider657343a2017-09-10 16:44:28 +020088# Set 'exit on error' for all CI scripts to let the caller know that
SZEDER Gábora8b8b6b2017-12-27 17:36:00 +010089# something went wrong.
90# Set tracing executed commands, primarily setting environment variables
91# and installing dependencies.
SZEDER Gábor4f263662017-12-12 00:34:43 +010092set -ex
Lars Schneider09f5e972017-09-10 16:44:29 +020093
Ævar Arnfjörð Bjarmason4a6e4b92021-11-23 17:29:08 +010094if test -n "$SYSTEM_COLLECTIONURI" || test -n "$SYSTEM_TASKDEFINITIONSURI"
Johannes Schindelin6141a2e2019-01-29 06:19:28 -080095then
96 CI_TYPE=azure-pipelines
97 # We are running in Azure Pipelines
98 CI_BRANCH="$BUILD_SOURCEBRANCH"
99 CI_COMMIT="$BUILD_SOURCEVERSION"
100 CI_JOB_ID="$BUILD_BUILDID"
101 CI_JOB_NUMBER="$BUILD_BUILDNUMBER"
102 CI_OS_NAME="$(echo "$AGENT_OS" | tr A-Z a-z)"
103 test darwin != "$CI_OS_NAME" || CI_OS_NAME=osx
104 CI_REPO_SLUG="$(expr "$BUILD_REPOSITORY_URI" : '.*/\([^/]*/[^/]*\)$')"
105 CC="${CC:-gcc}"
106
107 # use a subdirectory of the cache dir (because the file share is shared
108 # among *all* phases)
109 cache_dir="$HOME/test-cache/$SYSTEM_PHASENAME"
110
Johannes Schindelin6141a2e2019-01-29 06:19:28 -0800111 export GIT_PROVE_OPTS="--timer --jobs 10 --state=failed,slow,save"
112 export GIT_TEST_OPTS="--verbose-log -x --write-junit-xml"
Junio C Hamanoa8c51f72019-02-07 11:36:28 -0800113 MAKEFLAGS="$MAKEFLAGS --jobs=10"
Johannes Schindelina87e4272019-01-29 06:19:38 -0800114 test windows_nt != "$CI_OS_NAME" ||
115 GIT_TEST_OPTS="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
Johannes Schindelina3f2eec2020-04-08 11:05:33 +0700116elif test true = "$GITHUB_ACTIONS"
117then
118 CI_TYPE=github-actions
119 CI_BRANCH="$GITHUB_REF"
120 CI_COMMIT="$GITHUB_SHA"
121 CI_OS_NAME="$(echo "$RUNNER_OS" | tr A-Z a-z)"
122 test macos != "$CI_OS_NAME" || CI_OS_NAME=osx
123 CI_REPO_SLUG="$GITHUB_REPOSITORY"
124 CI_JOB_ID="$GITHUB_RUN_ID"
125 CC="${CC:-gcc}"
Johannes Schindelin4463ce72020-10-08 15:29:35 +0000126 DONT_SKIP_TAGS=t
Johannes Schindelina3f2eec2020-04-08 11:05:33 +0700127
128 cache_dir="$HOME/none"
129
130 export GIT_PROVE_OPTS="--timer --jobs 10"
131 export GIT_TEST_OPTS="--verbose-log -x"
132 MAKEFLAGS="$MAKEFLAGS --jobs=10"
133 test windows != "$CI_OS_NAME" ||
134 GIT_TEST_OPTS="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
Johannes Schindelinb011fab2019-01-27 15:26:51 -0800135else
136 echo "Could not identify CI type" >&2
Johannes Schindelin5127e8c2020-04-08 11:05:32 +0700137 env >&2
Johannes Schindelinb011fab2019-01-27 15:26:51 -0800138 exit 1
139fi
140
SZEDER Gáborb2cbaa02018-01-29 18:17:11 +0100141good_trees_file="$cache_dir/good-trees"
142
143mkdir -p "$cache_dir"
SZEDER Gáborb4a2fdc2017-12-31 11:12:04 +0100144
Johannes Schindelin4463ce72020-10-08 15:29:35 +0000145test -n "${DONT_SKIP_TAGS-}" ||
Lars Schneider09f5e972017-09-10 16:44:29 +0200146skip_branch_tip_with_tag
SZEDER Gábor9cc2c762017-12-31 11:12:05 +0100147skip_good_tree
SZEDER Gábor83d1efe2017-11-01 12:55:35 +0100148
SZEDER Gáborbf427a92017-12-12 00:34:44 +0100149if test -z "$jobname"
150then
Johannes Schindelinb011fab2019-01-27 15:26:51 -0800151 jobname="$CI_OS_NAME-$CC"
SZEDER Gáborbf427a92017-12-12 00:34:44 +0100152fi
153
SZEDER Gábore3371e92017-12-12 00:34:45 +0100154export DEVELOPER=1
155export DEFAULT_TEST_TARGET=prove
SZEDER Gábora85efb52019-11-22 14:14:37 +0100156export GIT_TEST_CLONE_2GB=true
Johannes Schindelinef60e9f2020-09-21 22:28:17 +0000157export SKIP_DASHED_BUILT_INS=YesPlease
SZEDER Gábore3371e92017-12-12 00:34:45 +0100158
Ævar Arnfjörð Bjarmason707d2f22021-11-23 17:29:11 +0100159case "$runs_on_pool" in
160ubuntu-latest)
161 if test "$jobname" = "linux-gcc-default"
162 then
163 break
164 fi
165
Junio C Hamano57cbc532019-02-06 22:05:26 -0800166 if [ "$jobname" = linux-gcc ]
167 then
SZEDER Gábor60e47f62020-07-23 23:38:48 +0200168 MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3"
SZEDER Gábor6bb40ed2020-01-23 18:56:45 +0100169 else
SZEDER Gábor60e47f62020-07-23 23:38:48 +0200170 MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python2"
Junio C Hamano57cbc532019-02-06 22:05:26 -0800171 fi
172
SZEDER Gábor39602902019-09-06 14:13:26 +0200173 export GIT_TEST_HTTPD=true
SZEDER Gábora1157b72017-12-12 00:34:46 +0100174
SZEDER Gábore3371e92017-12-12 00:34:45 +0100175 # The Linux build installs the defined dependency versions below.
SZEDER Gábor37a2e352019-07-06 18:21:14 +0200176 # The OS X build installs much more recent versions, whichever
177 # were recorded in the Homebrew database upon creating the OS X
178 # image.
179 # Keep that in mind when you encounter a broken OS X build!
SZEDER Gábore3371e92017-12-12 00:34:45 +0100180 export LINUX_P4_VERSION="16.2"
181 export LINUX_GIT_LFS_VERSION="1.5.2"
182
SZEDER Gábor88e00b72017-12-31 17:02:05 +0100183 P4_PATH="$HOME/custom/p4"
184 GIT_LFS_PATH="$HOME/custom/git-lfs"
SZEDER Gábor83d1efe2017-11-01 12:55:35 +0100185 export PATH="$GIT_LFS_PATH:$P4_PATH:$PATH"
186 ;;
Ævar Arnfjörð Bjarmason707d2f22021-11-23 17:29:11 +0100187macos-latest)
Junio C Hamano57cbc532019-02-06 22:05:26 -0800188 if [ "$jobname" = osx-gcc ]
189 then
SZEDER Gábor6bb40ed2020-01-23 18:56:45 +0100190 MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=$(which python3)"
191 else
192 MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=$(which python2)"
Junio C Hamano57cbc532019-02-06 22:05:26 -0800193 fi
SZEDER Gábore3371e92017-12-12 00:34:45 +0100194 ;;
Ævar Arnfjörð Bjarmason707d2f22021-11-23 17:29:11 +0100195esac
SZEDER Gábore3371e92017-12-12 00:34:45 +0100196
Ævar Arnfjörð Bjarmason707d2f22021-11-23 17:29:11 +0100197case "$jobname" in
Ævar Arnfjörð Bjarmasonc08bb262021-11-23 17:29:10 +0100198linux32)
SZEDER Gábord2fae192020-04-02 20:04:00 +0700199 CC=gcc
Han-Wen Nienhuysa3229202021-10-07 20:25:03 +0000200 MAKEFLAGS="$MAKEFLAGS NO_UNCOMPRESS2=1"
SZEDER Gábord2fae192020-04-02 20:04:00 +0700201 ;;
Đoàn Trần Công Danhe0f86902020-04-04 08:08:50 +0700202linux-musl)
203 CC=gcc
204 MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3 USE_LIBPCRE2=Yes"
205 MAKEFLAGS="$MAKEFLAGS NO_REGEX=Yes ICONV_OMITS_BOM=Yes"
Đoàn Trần Công Danh482c9622021-06-08 13:56:28 +0700206 MAKEFLAGS="$MAKEFLAGS GIT_TEST_UTF8_LOCALE=C.UTF-8"
Đoàn Trần Công Danhe0f86902020-04-04 08:08:50 +0700207 ;;
Ævar Arnfjörð Bjarmason956d2e42021-09-23 11:20:46 +0200208linux-leaks)
209 export SANITIZE=leak
210 export GIT_TEST_PASSING_SANITIZE_LEAK=true
211 ;;
212esac
213
Junio C Hamanoa8c51f72019-02-07 11:36:28 -0800214MAKEFLAGS="$MAKEFLAGS CC=${CC:-cc}"