Skip to content

Commit 657343a

Browse files
larsxschneidergitster
authored andcommitted
travis-ci: move Travis CI code into dedicated scripts
Most of the Travis CI commands are in the '.travis.yml'. The yml format does not support functions and therefore code duplication is necessary to run commands across all builds. To fix this, add a library for common CI functions. Move all Travis CI code into dedicated scripts and make them call the library first. Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent edc74bc commit 657343a

10 files changed

+128
-81
lines changed

.travis.yml

Lines changed: 8 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,8 @@ matrix:
6161
services:
6262
- docker
6363
before_install:
64-
- docker pull daald/ubuntu32:xenial
6564
before_script:
66-
script:
67-
- >
68-
docker run
69-
--interactive
70-
--env DEVELOPER
71-
--env DEFAULT_TEST_TARGET
72-
--env GIT_PROVE_OPTS
73-
--env GIT_TEST_OPTS
74-
--env GIT_TEST_CLONE_2GB
75-
--volume "${PWD}:/usr/src/git"
76-
daald/ubuntu32:xenial
77-
/usr/src/git/ci/run-linux32-build.sh $(id -u $USER)
78-
# Use the following command to debug the docker build locally:
79-
# $ docker run -itv "${PWD}:/usr/src/git" --entrypoint /bin/bash daald/ubuntu32:xenial
80-
# root@container:/# /usr/src/git/ci/run-linux32-build.sh
65+
script: ci/run-linux32-docker.sh
8166
- env: Static Analysis
8267
os: linux
8368
compiler:
@@ -86,9 +71,8 @@ matrix:
8671
packages:
8772
- coccinelle
8873
before_install:
89-
script:
90-
# "before_script" that builds Git is inherited from base job
91-
- make coccicheck
74+
# "before_script" that builds Git is inherited from base job
75+
script: ci/run-static-analysis.sh
9276
after_failure:
9377
- env: Documentation
9478
os: linux
@@ -99,70 +83,14 @@ matrix:
9983
- asciidoc
10084
- xmlto
10185
before_install:
102-
before_script: gem install asciidoctor
86+
before_script:
10387
script: ci/test-documentation.sh
10488
after_failure:
10589

106-
before_install:
107-
- >
108-
case "${TRAVIS_OS_NAME:-linux}" in
109-
linux)
110-
export GIT_TEST_HTTPD=YesPlease
111-
112-
mkdir --parents custom/p4
113-
pushd custom/p4
114-
wget --quiet http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION/bin.linux26x86_64/p4d
115-
wget --quiet http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION/bin.linux26x86_64/p4
116-
chmod u+x p4d
117-
chmod u+x p4
118-
export PATH="$(pwd):$PATH"
119-
popd
120-
mkdir --parents custom/git-lfs
121-
pushd custom/git-lfs
122-
wget --quiet https://github.com/github/git-lfs/releases/download/v$LINUX_GIT_LFS_VERSION/git-lfs-linux-amd64-$LINUX_GIT_LFS_VERSION.tar.gz
123-
tar --extract --gunzip --file "git-lfs-linux-amd64-$LINUX_GIT_LFS_VERSION.tar.gz"
124-
cp git-lfs-$LINUX_GIT_LFS_VERSION/git-lfs .
125-
export PATH="$(pwd):$PATH"
126-
popd
127-
;;
128-
osx)
129-
brew update --quiet
130-
# Uncomment this if you want to run perf tests:
131-
# brew install gnu-time
132-
brew install git-lfs gettext
133-
brew link --force gettext
134-
brew install caskroom/cask/perforce
135-
;;
136-
esac;
137-
echo "$(tput setaf 6)Perforce Server Version$(tput sgr0)";
138-
p4d -V | grep Rev.;
139-
echo "$(tput setaf 6)Perforce Client Version$(tput sgr0)";
140-
p4 -V | grep Rev.;
141-
echo "$(tput setaf 6)Git-LFS Version$(tput sgr0)";
142-
git-lfs version;
143-
144-
before_script: make --jobs=2
145-
146-
script:
147-
- >
148-
mkdir -p $HOME/travis-cache;
149-
ln -s $HOME/travis-cache/.prove t/.prove;
150-
make --quiet test;
151-
152-
after_failure:
153-
- >
154-
: '<-- Click here to see detailed test output! ';
155-
for TEST_EXIT in t/test-results/*.exit;
156-
do
157-
if [ "$(cat "$TEST_EXIT")" != "0" ];
158-
then
159-
TEST_OUT="${TEST_EXIT%exit}out";
160-
echo "------------------------------------------------------------------------";
161-
echo "$(tput setaf 1)${TEST_OUT}...$(tput sgr0)";
162-
echo "------------------------------------------------------------------------";
163-
cat "${TEST_OUT}";
164-
fi;
165-
done;
90+
before_install: ci/install-dependencies.sh
91+
before_script: ci/run-build.sh
92+
script: ci/run-tests.sh
93+
after_failure: ci/print-test-failures.sh
16694

16795
notifications:
16896
email: false

ci/install-dependencies.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Install dependencies required to build and test Git on Linux and macOS
4+
#
5+
6+
. ${0%/*}/lib-travisci.sh
7+
8+
case "${TRAVIS_OS_NAME:-linux}" in
9+
linux)
10+
export GIT_TEST_HTTPD=YesPlease
11+
12+
mkdir --parents custom/p4
13+
pushd custom/p4
14+
wget --quiet http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION/bin.linux26x86_64/p4d
15+
wget --quiet http://filehost.perforce.com/perforce/r$LINUX_P4_VERSION/bin.linux26x86_64/p4
16+
chmod u+x p4d
17+
chmod u+x p4
18+
export PATH="$(pwd):$PATH"
19+
popd
20+
mkdir --parents custom/git-lfs
21+
pushd custom/git-lfs
22+
wget --quiet https://github.com/github/git-lfs/releases/download/v$LINUX_GIT_LFS_VERSION/git-lfs-linux-amd64-$LINUX_GIT_LFS_VERSION.tar.gz
23+
tar --extract --gunzip --file "git-lfs-linux-amd64-$LINUX_GIT_LFS_VERSION.tar.gz"
24+
cp git-lfs-$LINUX_GIT_LFS_VERSION/git-lfs .
25+
export PATH="$(pwd):$PATH"
26+
popd
27+
;;
28+
osx)
29+
brew update --quiet
30+
# Uncomment this if you want to run perf tests:
31+
# brew install gnu-time
32+
brew install git-lfs gettext
33+
brew link --force gettext
34+
brew install caskroom/cask/perforce
35+
;;
36+
esac
37+
38+
echo "$(tput setaf 6)Perforce Server Version$(tput sgr0)"
39+
p4d -V | grep Rev.
40+
echo "$(tput setaf 6)Perforce Client Version$(tput sgr0)"
41+
p4 -V | grep Rev.
42+
echo "$(tput setaf 6)Git-LFS Version$(tput sgr0)"
43+
git-lfs version

ci/lib-travisci.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Library of functions shared by all CI scripts
2+
3+
# Set 'exit on error' for all CI scripts to let the caller know that
4+
# something went wrong
5+
set -e

ci/print-test-failures.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
#
3+
# Print output of failing tests
4+
#
5+
6+
. ${0%/*}/lib-travisci.sh
7+
8+
for TEST_EXIT in t/test-results/*.exit
9+
do
10+
if [ "$(cat "$TEST_EXIT")" != "0" ]
11+
then
12+
TEST_OUT="${TEST_EXIT%exit}out"
13+
echo "------------------------------------------------------------------------"
14+
echo "$(tput setaf 1)${TEST_OUT}...$(tput sgr0)"
15+
echo "------------------------------------------------------------------------"
16+
cat "${TEST_OUT}"
17+
fi
18+
done

ci/run-build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
#
3+
# Build Git
4+
#
5+
6+
. ${0%/*}/lib-travisci.sh
7+
8+
make --jobs=2

ci/run-linux32-docker.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
#
3+
# Download and run Docker image to build and test 32-bit Git
4+
#
5+
6+
. ${0%/*}/lib-travisci.sh
7+
8+
docker pull daald/ubuntu32:xenial
9+
10+
# Use the following command to debug the docker build locally:
11+
# $ docker run -itv "${PWD}:/usr/src/git" --entrypoint /bin/bash daald/ubuntu32:xenial
12+
# root@container:/# /usr/src/git/ci/run-linux32-build.sh
13+
14+
docker run \
15+
--interactive \
16+
--env DEVELOPER \
17+
--env DEFAULT_TEST_TARGET \
18+
--env GIT_PROVE_OPTS \
19+
--env GIT_TEST_OPTS \
20+
--env GIT_TEST_CLONE_2GB \
21+
--volume "${PWD}:/usr/src/git" \
22+
daald/ubuntu32:xenial \
23+
/usr/src/git/ci/run-linux32-build.sh $(id -u $USER)

ci/run-static-analysis.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
#
3+
# Perform various static code analysis checks
4+
#
5+
6+
. ${0%/*}/lib-travisci.sh
7+
8+
make coccicheck

ci/run-tests.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
#
3+
# Test Git
4+
#
5+
6+
. ${0%/*}/lib-travisci.sh
7+
8+
mkdir -p $HOME/travis-cache
9+
ln -s $HOME/travis-cache/.prove t/.prove
10+
make --quiet test

ci/run-windows-build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# supported) and a commit hash.
77
#
88

9+
. ${0%/*}/lib-travisci.sh
10+
911
test $# -ne 2 && echo "Unexpected number of parameters" && exit 1
1012
test -z "$GFW_CI_TOKEN" && echo "GFW_CI_TOKEN not defined" && exit
1113

ci/test-documentation.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# Perform sanity checks on documentation and build it.
44
#
55

6-
set -e
6+
. ${0%/*}/lib-travisci.sh
7+
8+
gem install asciidoctor
79

810
make check-builtins
911
make check-docs

0 commit comments

Comments
 (0)