Lars Schneider | 657343a | 2017-09-10 16:44:28 +0200 | [diff] [blame] | 1 | # Library of functions shared by all CI scripts |
| 2 | |
Lars Schneider | 09f5e97 | 2017-09-10 16:44:29 +0200 | [diff] [blame] | 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 | # |
Johannes Schindelin | 4096a98 | 2019-01-27 15:26:49 -0800 | [diff] [blame] | 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. |
Lars Schneider | 09f5e97 | 2017-09-10 16:44:29 +0200 | [diff] [blame] | 14 | |
Johannes Schindelin | 4096a98 | 2019-01-27 15:26:49 -0800 | [diff] [blame] | 15 | if TAG=$(git describe --exact-match "$CI_BRANCH" 2>/dev/null) && |
| 16 | test "$TAG" != "$CI_BRANCH" |
Lars Schneider | 09f5e97 | 2017-09-10 16:44:29 +0200 | [diff] [blame] | 17 | then |
Johannes Schindelin | 4096a98 | 2019-01-27 15:26:49 -0800 | [diff] [blame] | 18 | echo "$(tput setaf 2)Tip of $CI_BRANCH is exactly at $TAG$(tput sgr0)" |
Lars Schneider | 09f5e97 | 2017-09-10 16:44:29 +0200 | [diff] [blame] | 19 | exit 0 |
| 20 | fi |
| 21 | } |
| 22 | |
SZEDER Gábor | 9cc2c76 | 2017-12-31 11:12:05 +0100 | [diff] [blame] | 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 () { |
Johannes Schindelin | b011fab | 2019-01-27 15:26:51 -0800 | [diff] [blame] | 27 | echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file" |
SZEDER Gábor | 9cc2c76 | 2017-12-31 11:12:05 +0100 | [diff] [blame] | 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 () { |
Ævar Arnfjörð Bjarmason | 4a6e4b9 | 2021-11-23 17:29:08 +0100 | [diff] [blame] | 37 | if test true = "$GITHUB_ACTIONS" |
SZEDER Gábor | c46ebc2 | 2019-09-21 09:40:54 +0200 | [diff] [blame] | 38 | then |
| 39 | return |
| 40 | fi |
| 41 | |
Johannes Schindelin | b011fab | 2019-01-27 15:26:51 -0800 | [diff] [blame] | 42 | if ! good_tree_info="$(grep "^$(git rev-parse $CI_COMMIT^{tree}) " "$good_trees_file")" |
SZEDER Gábor | 9cc2c76 | 2017-12-31 11:12:05 +0100 | [diff] [blame] | 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 | |
Johannes Schindelin | b011fab | 2019-01-27 15:26:51 -0800 | [diff] [blame] | 52 | if test "$CI_JOB_ID" = "$prev_good_job_id" |
SZEDER Gábor | 9cc2c76 | 2017-12-31 11:12:05 +0100 | [diff] [blame] | 53 | then |
| 54 | cat <<-EOF |
Johannes Schindelin | b011fab | 2019-01-27 15:26:51 -0800 | [diff] [blame] | 55 | $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0) |
SZEDER Gábor | 9cc2c76 | 2017-12-31 11:12:05 +0100 | [diff] [blame] | 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 |
Johannes Schindelin | b011fab | 2019-01-27 15:26:51 -0800 | [diff] [blame] | 61 | $(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0) |
SZEDER Gábor | 9cc2c76 | 2017-12-31 11:12:05 +0100 | [diff] [blame] | 62 | 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ð Bjarmason | 4a6e4b9 | 2021-11-23 17:29:08 +0100 | [diff] [blame] | 63 | The log of that build job is available at $SYSTEM_TASKDEFINITIONSURI$SYSTEM_TEAMPROJECT/_build/results?buildId=$prev_good_job_id |
SZEDER Gábor | 9cc2c76 | 2017-12-31 11:12:05 +0100 | [diff] [blame] | 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 | |
SZEDER Gábor | b92cb86 | 2017-12-31 17:02:06 +0100 | [diff] [blame] | 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 | |
Đoàn Trần Công Danh | 855c158 | 2020-04-08 11:05:34 +0700 | [diff] [blame] | 82 | # GitHub Action doesn't set TERM, which is required by tput |
| 83 | export TERM=${TERM:-dumb} |
| 84 | |
Junio C Hamano | a8c51f7 | 2019-02-07 11:36:28 -0800 | [diff] [blame] | 85 | # Clear MAKEFLAGS that may come from the outside world. |
| 86 | export MAKEFLAGS= |
| 87 | |
Lars Schneider | 657343a | 2017-09-10 16:44:28 +0200 | [diff] [blame] | 88 | # Set 'exit on error' for all CI scripts to let the caller know that |
SZEDER Gábor | a8b8b6b | 2017-12-27 17:36:00 +0100 | [diff] [blame] | 89 | # something went wrong. |
| 90 | # Set tracing executed commands, primarily setting environment variables |
| 91 | # and installing dependencies. |
SZEDER Gábor | 4f26366 | 2017-12-12 00:34:43 +0100 | [diff] [blame] | 92 | set -ex |
Lars Schneider | 09f5e97 | 2017-09-10 16:44:29 +0200 | [diff] [blame] | 93 | |
Ævar Arnfjörð Bjarmason | 4a6e4b9 | 2021-11-23 17:29:08 +0100 | [diff] [blame] | 94 | if test -n "$SYSTEM_COLLECTIONURI" || test -n "$SYSTEM_TASKDEFINITIONSURI" |
Johannes Schindelin | 6141a2e | 2019-01-29 06:19:28 -0800 | [diff] [blame] | 95 | then |
| 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 Schindelin | 6141a2e | 2019-01-29 06:19:28 -0800 | [diff] [blame] | 111 | export GIT_PROVE_OPTS="--timer --jobs 10 --state=failed,slow,save" |
| 112 | export GIT_TEST_OPTS="--verbose-log -x --write-junit-xml" |
Junio C Hamano | a8c51f7 | 2019-02-07 11:36:28 -0800 | [diff] [blame] | 113 | MAKEFLAGS="$MAKEFLAGS --jobs=10" |
Johannes Schindelin | a87e427 | 2019-01-29 06:19:38 -0800 | [diff] [blame] | 114 | test windows_nt != "$CI_OS_NAME" || |
| 115 | GIT_TEST_OPTS="--no-chain-lint --no-bin-wrappers $GIT_TEST_OPTS" |
Johannes Schindelin | a3f2eec | 2020-04-08 11:05:33 +0700 | [diff] [blame] | 116 | elif test true = "$GITHUB_ACTIONS" |
| 117 | then |
| 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 Schindelin | 4463ce7 | 2020-10-08 15:29:35 +0000 | [diff] [blame] | 126 | DONT_SKIP_TAGS=t |
Johannes Schindelin | a3f2eec | 2020-04-08 11:05:33 +0700 | [diff] [blame] | 127 | |
| 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 Schindelin | b011fab | 2019-01-27 15:26:51 -0800 | [diff] [blame] | 135 | else |
| 136 | echo "Could not identify CI type" >&2 |
Johannes Schindelin | 5127e8c | 2020-04-08 11:05:32 +0700 | [diff] [blame] | 137 | env >&2 |
Johannes Schindelin | b011fab | 2019-01-27 15:26:51 -0800 | [diff] [blame] | 138 | exit 1 |
| 139 | fi |
| 140 | |
SZEDER Gábor | b2cbaa0 | 2018-01-29 18:17:11 +0100 | [diff] [blame] | 141 | good_trees_file="$cache_dir/good-trees" |
| 142 | |
| 143 | mkdir -p "$cache_dir" |
SZEDER Gábor | b4a2fdc | 2017-12-31 11:12:04 +0100 | [diff] [blame] | 144 | |
Johannes Schindelin | 4463ce7 | 2020-10-08 15:29:35 +0000 | [diff] [blame] | 145 | test -n "${DONT_SKIP_TAGS-}" || |
Lars Schneider | 09f5e97 | 2017-09-10 16:44:29 +0200 | [diff] [blame] | 146 | skip_branch_tip_with_tag |
SZEDER Gábor | 9cc2c76 | 2017-12-31 11:12:05 +0100 | [diff] [blame] | 147 | skip_good_tree |
SZEDER Gábor | 83d1efe | 2017-11-01 12:55:35 +0100 | [diff] [blame] | 148 | |
SZEDER Gábor | bf427a9 | 2017-12-12 00:34:44 +0100 | [diff] [blame] | 149 | if test -z "$jobname" |
| 150 | then |
Johannes Schindelin | b011fab | 2019-01-27 15:26:51 -0800 | [diff] [blame] | 151 | jobname="$CI_OS_NAME-$CC" |
SZEDER Gábor | bf427a9 | 2017-12-12 00:34:44 +0100 | [diff] [blame] | 152 | fi |
| 153 | |
SZEDER Gábor | e3371e9 | 2017-12-12 00:34:45 +0100 | [diff] [blame] | 154 | export DEVELOPER=1 |
| 155 | export DEFAULT_TEST_TARGET=prove |
SZEDER Gábor | a85efb5 | 2019-11-22 14:14:37 +0100 | [diff] [blame] | 156 | export GIT_TEST_CLONE_2GB=true |
Johannes Schindelin | ef60e9f | 2020-09-21 22:28:17 +0000 | [diff] [blame] | 157 | export SKIP_DASHED_BUILT_INS=YesPlease |
SZEDER Gábor | e3371e9 | 2017-12-12 00:34:45 +0100 | [diff] [blame] | 158 | |
Ævar Arnfjörð Bjarmason | 707d2f2 | 2021-11-23 17:29:11 +0100 | [diff] [blame] | 159 | case "$runs_on_pool" in |
| 160 | ubuntu-latest) |
| 161 | if test "$jobname" = "linux-gcc-default" |
| 162 | then |
| 163 | break |
| 164 | fi |
| 165 | |
Junio C Hamano | 57cbc53 | 2019-02-06 22:05:26 -0800 | [diff] [blame] | 166 | if [ "$jobname" = linux-gcc ] |
| 167 | then |
SZEDER Gábor | 60e47f6 | 2020-07-23 23:38:48 +0200 | [diff] [blame] | 168 | MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3" |
SZEDER Gábor | 6bb40ed | 2020-01-23 18:56:45 +0100 | [diff] [blame] | 169 | else |
SZEDER Gábor | 60e47f6 | 2020-07-23 23:38:48 +0200 | [diff] [blame] | 170 | MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python2" |
Junio C Hamano | 57cbc53 | 2019-02-06 22:05:26 -0800 | [diff] [blame] | 171 | fi |
| 172 | |
SZEDER Gábor | 3960290 | 2019-09-06 14:13:26 +0200 | [diff] [blame] | 173 | export GIT_TEST_HTTPD=true |
SZEDER Gábor | a1157b7 | 2017-12-12 00:34:46 +0100 | [diff] [blame] | 174 | |
SZEDER Gábor | e3371e9 | 2017-12-12 00:34:45 +0100 | [diff] [blame] | 175 | # The Linux build installs the defined dependency versions below. |
SZEDER Gábor | 37a2e35 | 2019-07-06 18:21:14 +0200 | [diff] [blame] | 176 | # 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ábor | e3371e9 | 2017-12-12 00:34:45 +0100 | [diff] [blame] | 180 | export LINUX_P4_VERSION="16.2" |
| 181 | export LINUX_GIT_LFS_VERSION="1.5.2" |
| 182 | |
SZEDER Gábor | 88e00b7 | 2017-12-31 17:02:05 +0100 | [diff] [blame] | 183 | P4_PATH="$HOME/custom/p4" |
| 184 | GIT_LFS_PATH="$HOME/custom/git-lfs" |
SZEDER Gábor | 83d1efe | 2017-11-01 12:55:35 +0100 | [diff] [blame] | 185 | export PATH="$GIT_LFS_PATH:$P4_PATH:$PATH" |
| 186 | ;; |
Ævar Arnfjörð Bjarmason | 707d2f2 | 2021-11-23 17:29:11 +0100 | [diff] [blame] | 187 | macos-latest) |
Junio C Hamano | 57cbc53 | 2019-02-06 22:05:26 -0800 | [diff] [blame] | 188 | if [ "$jobname" = osx-gcc ] |
| 189 | then |
SZEDER Gábor | 6bb40ed | 2020-01-23 18:56:45 +0100 | [diff] [blame] | 190 | MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=$(which python3)" |
| 191 | else |
| 192 | MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=$(which python2)" |
Junio C Hamano | 57cbc53 | 2019-02-06 22:05:26 -0800 | [diff] [blame] | 193 | fi |
SZEDER Gábor | e3371e9 | 2017-12-12 00:34:45 +0100 | [diff] [blame] | 194 | ;; |
Ævar Arnfjörð Bjarmason | 707d2f2 | 2021-11-23 17:29:11 +0100 | [diff] [blame] | 195 | esac |
SZEDER Gábor | e3371e9 | 2017-12-12 00:34:45 +0100 | [diff] [blame] | 196 | |
Ævar Arnfjörð Bjarmason | 707d2f2 | 2021-11-23 17:29:11 +0100 | [diff] [blame] | 197 | case "$jobname" in |
Ævar Arnfjörð Bjarmason | c08bb26 | 2021-11-23 17:29:10 +0100 | [diff] [blame] | 198 | linux32) |
SZEDER Gábor | d2fae19 | 2020-04-02 20:04:00 +0700 | [diff] [blame] | 199 | CC=gcc |
Han-Wen Nienhuys | a322920 | 2021-10-07 20:25:03 +0000 | [diff] [blame] | 200 | MAKEFLAGS="$MAKEFLAGS NO_UNCOMPRESS2=1" |
SZEDER Gábor | d2fae19 | 2020-04-02 20:04:00 +0700 | [diff] [blame] | 201 | ;; |
Đoàn Trần Công Danh | e0f8690 | 2020-04-04 08:08:50 +0700 | [diff] [blame] | 202 | linux-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 Danh | 482c962 | 2021-06-08 13:56:28 +0700 | [diff] [blame] | 206 | MAKEFLAGS="$MAKEFLAGS GIT_TEST_UTF8_LOCALE=C.UTF-8" |
Đoàn Trần Công Danh | e0f8690 | 2020-04-04 08:08:50 +0700 | [diff] [blame] | 207 | ;; |
Ævar Arnfjörð Bjarmason | 956d2e4 | 2021-09-23 11:20:46 +0200 | [diff] [blame] | 208 | linux-leaks) |
| 209 | export SANITIZE=leak |
| 210 | export GIT_TEST_PASSING_SANITIZE_LEAK=true |
| 211 | ;; |
| 212 | esac |
| 213 | |
Junio C Hamano | a8c51f7 | 2019-02-07 11:36:28 -0800 | [diff] [blame] | 214 | MAKEFLAGS="$MAKEFLAGS CC=${CC:-cc}" |