Skip to content

Commit b011fab

Browse files
dschogitster
authored andcommitted
ci/lib.sh: encapsulate Travis-specific things
The upcoming patches will allow building git.git via Azure Pipelines (i.e. Azure DevOps' Continuous Integration), where variable names and URLs look a bit different than in Travis CI. Also, the configurations of the available agents are different. For example, Travis' and Azure Pipelines' macOS agents are set up differently, so that on Travis, we have to install the git-lfs and gettext Homebrew packages, and on Azure Pipelines we do not need to. Likewise, Azure Pipelines' Ubuntu agents already have asciidoctor installed. Finally, on Azure Pipelines the natural way is not to base64-encode tar files of the trash directories of failed tests, but to publish build artifacts instead. Therefore, that code to log those base64-encoded tar files is guarded to be Travis-specific. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c2160f2 commit b011fab

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

ci/install-dependencies.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ osx-clang|osx-gcc)
3737
brew update --quiet
3838
# Uncomment this if you want to run perf tests:
3939
# brew install gnu-time
40-
brew install git-lfs gettext
40+
test -z "$BREW_INSTALL_PACKAGES" ||
41+
brew install $BREW_INSTALL_PACKAGES
4142
brew link --force gettext
4243
brew install caskroom/cask/perforce
4344
;;

ci/lib.sh

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ skip_branch_tip_with_tag () {
2424
# job if we encounter the same tree again and can provide a useful info
2525
# message.
2626
save_good_tree () {
27-
echo "$(git rev-parse $TRAVIS_COMMIT^{tree}) $TRAVIS_COMMIT $TRAVIS_JOB_NUMBER $TRAVIS_JOB_ID" >>"$good_trees_file"
27+
echo "$(git rev-parse $CI_COMMIT^{tree}) $CI_COMMIT $CI_JOB_NUMBER $CI_JOB_ID" >>"$good_trees_file"
2828
# limit the file size
2929
tail -1000 "$good_trees_file" >"$good_trees_file".tmp
3030
mv "$good_trees_file".tmp "$good_trees_file"
@@ -34,7 +34,7 @@ save_good_tree () {
3434
# successfully before (e.g. because the branch got rebased, changing only
3535
# the commit messages).
3636
skip_good_tree () {
37-
if ! good_tree_info="$(grep "^$(git rev-parse $TRAVIS_COMMIT^{tree}) " "$good_trees_file")"
37+
if ! good_tree_info="$(grep "^$(git rev-parse $CI_COMMIT^{tree}) " "$good_trees_file")"
3838
then
3939
# Haven't seen this tree yet, or no cached good trees file yet.
4040
# Continue the build job.
@@ -44,18 +44,18 @@ skip_good_tree () {
4444
echo "$good_tree_info" | {
4545
read tree prev_good_commit prev_good_job_number prev_good_job_id
4646

47-
if test "$TRAVIS_JOB_ID" = "$prev_good_job_id"
47+
if test "$CI_JOB_ID" = "$prev_good_job_id"
4848
then
4949
cat <<-EOF
50-
$(tput setaf 2)Skipping build job for commit $TRAVIS_COMMIT.$(tput sgr0)
50+
$(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
5151
This commit has already been built and tested successfully by this build job.
5252
To force a re-build delete the branch's cache and then hit 'Restart job'.
5353
EOF
5454
else
5555
cat <<-EOF
56-
$(tput setaf 2)Skipping build job for commit $TRAVIS_COMMIT.$(tput sgr0)
56+
$(tput setaf 2)Skipping build job for commit $CI_COMMIT.$(tput sgr0)
5757
This commit's tree has already been built and tested successfully in build job $prev_good_job_number for commit $prev_good_commit.
58-
The log of that build job is available at https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$prev_good_job_id
58+
The log of that build job is available at $(url_for_job_id $prev_good_job_id)
5959
To force a re-build delete the branch's cache and then hit 'Restart job'.
6060
EOF
6161
fi
@@ -80,11 +80,32 @@ check_unignored_build_artifacts ()
8080
# and installing dependencies.
8181
set -ex
8282

83-
# When building a PR, TRAVIS_BRANCH refers to the *target* branch. Not what we
84-
# want here. We want the source branch instead.
85-
CI_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"
83+
if test true = "$TRAVIS"
84+
then
85+
CI_TYPE=travis
86+
# When building a PR, TRAVIS_BRANCH refers to the *target* branch. Not
87+
# what we want here. We want the source branch instead.
88+
CI_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"
89+
CI_COMMIT="$TRAVIS_COMMIT"
90+
CI_JOB_ID="$TRAVIS_JOB_ID"
91+
CI_JOB_NUMBER="$TRAVIS_JOB_NUMBER"
92+
CI_OS_NAME="$TRAVIS_OS_NAME"
93+
CI_REPO_SLUG="$TRAVIS_REPO_SLUG"
94+
95+
cache_dir="$HOME/travis-cache"
96+
97+
url_for_job_id () {
98+
echo "https://travis-ci.org/$CI_REPO_SLUG/jobs/$1"
99+
}
100+
101+
BREW_INSTALL_PACKAGES="git-lfs gettext"
102+
export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
103+
export GIT_TEST_OPTS="--verbose-log -x --immediate"
104+
else
105+
echo "Could not identify CI type" >&2
106+
exit 1
107+
fi
86108

87-
cache_dir="$HOME/travis-cache"
88109
good_trees_file="$cache_dir/good-trees"
89110

90111
mkdir -p "$cache_dir"
@@ -94,13 +115,11 @@ skip_good_tree
94115

95116
if test -z "$jobname"
96117
then
97-
jobname="$TRAVIS_OS_NAME-$CC"
118+
jobname="$CI_OS_NAME-$CC"
98119
fi
99120

100121
export DEVELOPER=1
101122
export DEFAULT_TEST_TARGET=prove
102-
export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
103-
export GIT_TEST_OPTS="--verbose-log -x --immediate"
104123
export GIT_TEST_CLONE_2GB=YesPlease
105124
if [ "$jobname" = linux-gcc ]; then
106125
export CC=gcc-8

ci/print-test-failures.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ do
3838
test_name="${TEST_EXIT%.exit}"
3939
test_name="${test_name##*/}"
4040
trash_dir="trash directory.$test_name"
41+
case "$CI_TYPE" in
42+
travis)
43+
;;
44+
*)
45+
echo "Unhandled CI type: $CI_TYPE" >&2
46+
exit 1
47+
;;
48+
esac
4149
trash_tgz_b64="trash.$test_name.base64"
4250
if [ -d "$trash_dir" ]
4351
then

ci/test-documentation.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
. ${0%/*}/lib.sh
77

8+
test -n "$ALREADY_HAVE_ASCIIDOCTOR" ||
89
gem install asciidoctor
910

1011
make check-builtins

0 commit comments

Comments
 (0)