parse-options: const parse_options_concat() parameters
[git/raj.git] / ci / lib.sh
bloba90d0dc0fd2ae30ba59aa7f2262f884f43dc5ee5
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
13 # build of a tag.
15 if TAG=$(git describe --exact-match "$CI_BRANCH" 2>/dev/null) &&
16 test "$TAG" != "$CI_BRANCH"
17 then
18 echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)"
19 exit 0
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 () {
27 echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
28 # limit the file size
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).
36 skip_good_tree () {
37 if test "$TRAVIS_DEBUG_MODE" = true
38 then
39 return
42 if ! good_tree_info="$(grep "^$(git rev-parse $CI_COMMIT^{tree}) " "$good_trees_file")"
43 then
44 # Haven't seen this tree yet, or no cached good trees file yet.
45 # Continue the build job.
46 return
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"
53 then
54 cat <<-EOF
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'.
58 EOF
59 else
60 cat <<-EOF
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 $(url_for_job_id $prev_good_job_id)
64 To force a re-build delete the branch's cache and then hit 'Restart job'.
65 EOF
69 exit 0
72 check_unignored_build_artifacts ()
74 ! git ls-files --other --exclude-standard --error-unmatch \
75 -- ':/*' 2>/dev/null ||
77 echo "$(tput setaf 1)error: found unignored build artifacts$(tput sgr0)"
78 false
82 # Clear MAKEFLAGS that may come from the outside world.
83 export MAKEFLAGS=
85 # Set 'exit on error' for all CI scripts to let the caller know that
86 # something went wrong.
87 # Set tracing executed commands, primarily setting environment variables
88 # and installing dependencies.
89 set -ex
91 if test true = "$TRAVIS"
92 then
93 CI_TYPE=travis
94 # When building a PR, TRAVIS_BRANCH refers to the *target* branch. Not
95 # what we want here. We want the source branch instead.
96 CI_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"
97 CI_COMMIT="$TRAVIS_COMMIT"
98 CI_JOB_ID="$TRAVIS_JOB_ID"
99 CI_JOB_NUMBER="$TRAVIS_JOB_NUMBER"
100 CI_OS_NAME="$TRAVIS_OS_NAME"
101 CI_REPO_SLUG="$TRAVIS_REPO_SLUG"
103 cache_dir="$HOME/travis-cache"
105 url_for_job_id () {
106 echo "https://travis-ci.org/$CI_REPO_SLUG/jobs/$1"
109 BREW_INSTALL_PACKAGES="git-lfs gettext"
110 export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
111 export GIT_TEST_OPTS="--verbose-log -x --immediate"
112 MAKEFLAGS="$MAKEFLAGS --jobs=2"
113 elif test -n "$SYSTEM_COLLECTIONURI" || test -n "$SYSTEM_TASKDEFINITIONSURI"
114 then
115 CI_TYPE=azure-pipelines
116 # We are running in Azure Pipelines
117 CI_BRANCH="$BUILD_SOURCEBRANCH"
118 CI_COMMIT="$BUILD_SOURCEVERSION"
119 CI_JOB_ID="$BUILD_BUILDID"
120 CI_JOB_NUMBER="$BUILD_BUILDNUMBER"
121 CI_OS_NAME="$(echo "$AGENT_OS" | tr A-Z a-z)"
122 test darwin != "$CI_OS_NAME" || CI_OS_NAME=osx
123 CI_REPO_SLUG="$(expr "$BUILD_REPOSITORY_URI" : '.*/\([^/]*/[^/]*\)$')"
124 CC="${CC:-gcc}"
126 # use a subdirectory of the cache dir (because the file share is shared
127 # among *all* phases)
128 cache_dir="$HOME/test-cache/$SYSTEM_PHASENAME"
130 url_for_job_id () {
131 echo "$SYSTEM_TASKDEFINITIONSURI$SYSTEM_TEAMPROJECT/_build/results?buildId=$1"
134 export GIT_PROVE_OPTS="--timer --jobs 10 --state=failed,slow,save"
135 export GIT_TEST_OPTS="--verbose-log -x --write-junit-xml"
136 MAKEFLAGS="$MAKEFLAGS --jobs=10"
137 test windows_nt != "$CI_OS_NAME" ||
138 GIT_TEST_OPTS="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS"
139 else
140 echo "Could not identify CI type" >&2
141 exit 1
144 good_trees_file="$cache_dir/good-trees"
146 mkdir -p "$cache_dir"
148 skip_branch_tip_with_tag
149 skip_good_tree
151 if test -z "$jobname"
152 then
153 jobname="$CI_OS_NAME-$CC"
156 export DEVELOPER=1
157 export DEFAULT_TEST_TARGET=prove
158 export GIT_TEST_CLONE_2GB=true
160 case "$jobname" in
161 linux-clang|linux-gcc)
162 if [ "$jobname" = linux-gcc ]
163 then
164 export CC=gcc-8
167 export GIT_TEST_HTTPD=true
169 # The Linux build installs the defined dependency versions below.
170 # The OS X build installs much more recent versions, whichever
171 # were recorded in the Homebrew database upon creating the OS X
172 # image.
173 # Keep that in mind when you encounter a broken OS X build!
174 export LINUX_P4_VERSION="16.2"
175 export LINUX_GIT_LFS_VERSION="1.5.2"
177 P4_PATH="$HOME/custom/p4"
178 GIT_LFS_PATH="$HOME/custom/git-lfs"
179 export PATH="$GIT_LFS_PATH:$P4_PATH:$PATH"
181 osx-clang|osx-gcc)
182 if [ "$jobname" = osx-gcc ]
183 then
184 export CC=gcc-9
187 # t9810 occasionally fails on Travis CI OS X
188 # t9816 occasionally fails with "TAP out of sequence errors" on
189 # Travis CI OS X
190 export GIT_SKIP_TESTS="t9810 t9816"
192 GIT_TEST_GETTEXT_POISON)
193 export GIT_TEST_GETTEXT_POISON=true
195 esac
197 MAKEFLAGS="$MAKEFLAGS CC=${CC:-cc}"