]>
Commit | Line | Data |
---|---|---|
657343a6 LS |
1 | # Library of functions shared by all CI scripts |
2 | ||
09f5e974 LS |
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. | |
7 | # | |
4096a98d JS |
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 | |
13 | # build of a tag. | |
09f5e974 | 14 | |
4096a98d JS |
15 | if TAG=$(git describe --exact-match "$CI_BRANCH" 2>/dev/null) && |
16 | test "$TAG" != "$CI_BRANCH" | |
09f5e974 | 17 | then |
4096a98d | 18 | echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)" |
09f5e974 LS |
19 | exit 0 |
20 | fi | |
21 | } | |
22 | ||
9cc2c76f SG |
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 | |
25 | # message. | |
26 | save_good_tree () { | |
b011fabd | 27 | echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file" |
9cc2c76f SG |
28 | # 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). | |
36 | skip_good_tree () { | |
a3f2eec8 | 37 | if test "$TRAVIS_DEBUG_MODE" = true || test true = "$GITHUB_ACTIONS" |
c46ebc24 SG |
38 | then |
39 | return | |
40 | fi | |
41 | ||
b011fabd | 42 | if ! good_tree_info="$(grep "^$(git rev-parse $CI_COMMIT^{tree}) " "$good_trees_file")" |
9cc2c76f SG |
43 | 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 | ||
b011fabd | 52 | if test "$CI_JOB_ID" = "$prev_good_job_id" |
9cc2c76f SG |
53 | then |
54 | cat <<-EOF | |
b011fabd | 55 | $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0) |
9cc2c76f SG |
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'. | |
58 | EOF | |
59 | else | |
60 | cat <<-EOF | |
b011fabd | 61 | $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0) |
9cc2c76f | 62 | This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit. |
b011fabd | 63 | The log of that build job is available at $(url_for_job_id $prev_good_job_id) |
9cc2c76f SG |
64 | 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 | ||
b92cb86e SG |
72 | check_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 | ||
855c158e ĐTCD |
82 | # GitHub Action doesn't set TERM, which is required by tput |
83 | export TERM=${TERM:-dumb} | |
84 | ||
a8c51f77 JH |
85 | # Clear MAKEFLAGS that may come from the outside world. |
86 | export MAKEFLAGS= | |
87 | ||
657343a6 | 88 | # Set 'exit on error' for all CI scripts to let the caller know that |
a8b8b6b8 SG |
89 | # something went wrong. |
90 | # Set tracing executed commands, primarily setting environment variables | |
91 | # and installing dependencies. | |
4f263666 | 92 | set -ex |
09f5e974 | 93 | |
b011fabd JS |
94 | if test true = "$TRAVIS" |
95 | then | |
96 | CI_TYPE=travis | |
97 | # When building a PR, TRAVIS_BRANCH refers to the *target* branch. Not | |
98 | # what we want here. We want the source branch instead. | |
99 | CI_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}" | |
100 | CI_COMMIT="$TRAVIS_COMMIT" | |
101 | CI_JOB_ID="$TRAVIS_JOB_ID" | |
102 | CI_JOB_NUMBER="$TRAVIS_JOB_NUMBER" | |
103 | CI_OS_NAME="$TRAVIS_OS_NAME" | |
104 | CI_REPO_SLUG="$TRAVIS_REPO_SLUG" | |
105 | ||
106 | cache_dir="$HOME/travis-cache" | |
107 | ||
108 | url_for_job_id () { | |
109 | echo "https://travis-ci.org/$CI_REPO_SLUG/jobs/$1" | |
110 | } | |
111 | ||
112 | BREW_INSTALL_PACKAGES="git-lfs gettext" | |
113 | export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save" | |
114 | export GIT_TEST_OPTS="--verbose-log -x --immediate" | |
a8c51f77 | 115 | MAKEFLAGS="$MAKEFLAGS --jobs=2" |
6141a2ed JS |
116 | elif test -n "$SYSTEM_COLLECTIONURI" || test -n "$SYSTEM_TASKDEFINITIONSURI" |
117 | then | |
118 | CI_TYPE=azure-pipelines | |
119 | # We are running in Azure Pipelines | |
120 | CI_BRANCH="$BUILD_SOURCEBRANCH" | |
121 | CI_COMMIT="$BUILD_SOURCEVERSION" | |
122 | CI_JOB_ID="$BUILD_BUILDID" | |
123 | CI_JOB_NUMBER="$BUILD_BUILDNUMBER" | |
124 | CI_OS_NAME="$(echo "$AGENT_OS" | tr A-Z a-z)" | |
125 | test darwin != "$CI_OS_NAME" || CI_OS_NAME=osx | |
126 | CI_REPO_SLUG="$(expr "$BUILD_REPOSITORY_URI" : '.*/\([^/]*/[^/]*\)$')" | |
127 | CC="${CC:-gcc}" | |
128 | ||
129 | # use a subdirectory of the cache dir (because the file share is shared | |
130 | # among *all* phases) | |
131 | cache_dir="$HOME/test-cache/$SYSTEM_PHASENAME" | |
132 | ||
133 | url_for_job_id () { | |
134 | echo "$SYSTEM_TASKDEFINITIONSURI$SYSTEM_TEAMPROJECT/_build/results?buildId=$1" | |
135 | } | |
136 | ||
6141a2ed JS |
137 | export GIT_PROVE_OPTS="--timer --jobs 10 --state=failed,slow,save" |
138 | export GIT_TEST_OPTS="--verbose-log -x --write-junit-xml" | |
a8c51f77 | 139 | MAKEFLAGS="$MAKEFLAGS --jobs=10" |
a87e427e JS |
140 | test windows_nt != "$CI_OS_NAME" || |
141 | GIT_TEST_OPTS="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS" | |
a3f2eec8 JS |
142 | elif test true = "$GITHUB_ACTIONS" |
143 | then | |
144 | CI_TYPE=github-actions | |
145 | CI_BRANCH="$GITHUB_REF" | |
146 | CI_COMMIT="$GITHUB_SHA" | |
147 | CI_OS_NAME="$(echo "$RUNNER_OS" | tr A-Z a-z)" | |
148 | test macos != "$CI_OS_NAME" || CI_OS_NAME=osx | |
149 | CI_REPO_SLUG="$GITHUB_REPOSITORY" | |
150 | CI_JOB_ID="$GITHUB_RUN_ID" | |
151 | CC="${CC:-gcc}" | |
4463ce75 | 152 | DONT_SKIP_TAGS=t |
a3f2eec8 JS |
153 | |
154 | cache_dir="$HOME/none" | |
155 | ||
156 | export GIT_PROVE_OPTS="--timer --jobs 10" | |
157 | export GIT_TEST_OPTS="--verbose-log -x" | |
158 | MAKEFLAGS="$MAKEFLAGS --jobs=10" | |
159 | test windows != "$CI_OS_NAME" || | |
160 | GIT_TEST_OPTS="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS" | |
b011fabd JS |
161 | else |
162 | echo "Could not identify CI type" >&2 | |
5127e8cf | 163 | env >&2 |
b011fabd JS |
164 | exit 1 |
165 | fi | |
4096a98d | 166 | |
b2cbaa09 SG |
167 | good_trees_file="$cache_dir/good-trees" |
168 | ||
169 | mkdir -p "$cache_dir" | |
b4a2fdc9 | 170 | |
4463ce75 | 171 | test -n "${DONT_SKIP_TAGS-}" || |
09f5e974 | 172 | skip_branch_tip_with_tag |
9cc2c76f | 173 | skip_good_tree |
83d1efe5 | 174 | |
bf427a94 SG |
175 | if test -z "$jobname" |
176 | then | |
b011fabd | 177 | jobname="$CI_OS_NAME-$CC" |
bf427a94 SG |
178 | fi |
179 | ||
e3371e92 SG |
180 | export DEVELOPER=1 |
181 | export DEFAULT_TEST_TARGET=prove | |
a85efb59 | 182 | export GIT_TEST_CLONE_2GB=true |
ef60e9f7 | 183 | export SKIP_DASHED_BUILT_INS=YesPlease |
e3371e92 | 184 | |
bf427a94 SG |
185 | case "$jobname" in |
186 | linux-clang|linux-gcc) | |
2c8921db SG |
187 | if [ "$jobname" = linux-gcc ] |
188 | then | |
189 | export CC=gcc-8 | |
60e47f67 | 190 | MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3" |
6bb40ed2 | 191 | else |
60e47f67 | 192 | MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python2" |
2c8921db SG |
193 | fi |
194 | ||
39602906 | 195 | export GIT_TEST_HTTPD=true |
a1157b76 | 196 | |
e3371e92 | 197 | # The Linux build installs the defined dependency versions below. |
37a2e353 SG |
198 | # The OS X build installs much more recent versions, whichever |
199 | # were recorded in the Homebrew database upon creating the OS X | |
200 | # image. | |
201 | # Keep that in mind when you encounter a broken OS X build! | |
e3371e92 SG |
202 | export LINUX_P4_VERSION="16.2" |
203 | export LINUX_GIT_LFS_VERSION="1.5.2" | |
204 | ||
88e00b70 SG |
205 | P4_PATH="$HOME/custom/p4" |
206 | GIT_LFS_PATH="$HOME/custom/git-lfs" | |
83d1efe5 SG |
207 | export PATH="$GIT_LFS_PATH:$P4_PATH:$PATH" |
208 | ;; | |
e3371e92 | 209 | osx-clang|osx-gcc) |
2c8921db SG |
210 | if [ "$jobname" = osx-gcc ] |
211 | then | |
176441bf | 212 | export CC=gcc-9 |
6bb40ed2 SG |
213 | MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=$(which python3)" |
214 | else | |
215 | MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=$(which python2)" | |
2c8921db SG |
216 | fi |
217 | ||
e3371e92 SG |
218 | # t9810 occasionally fails on Travis CI OS X |
219 | # t9816 occasionally fails with "TAP out of sequence errors" on | |
220 | # Travis CI OS X | |
221 | export GIT_SKIP_TESTS="t9810 t9816" | |
222 | ;; | |
87b68db3 | 223 | GETTEXT_POISON) |
1ff750b1 | 224 | export GIT_TEST_GETTEXT_POISON=true |
e3371e92 | 225 | ;; |
d2fae19e SG |
226 | Linux32) |
227 | CC=gcc | |
228 | ;; | |
e0f8690d ĐTCD |
229 | linux-musl) |
230 | CC=gcc | |
231 | MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3 USE_LIBPCRE2=Yes" | |
232 | MAKEFLAGS="$MAKEFLAGS NO_REGEX=Yes ICONV_OMITS_BOM=Yes" | |
233 | ;; | |
83d1efe5 | 234 | esac |
2c8921db | 235 | |
a8c51f77 | 236 | MAKEFLAGS="$MAKEFLAGS CC=${CC:-cc}" |