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 <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Schneider committed Sep 10, 2017 at 16:44 UTC 657343a602ec5eddae6074656bfd0e8a91aaa8e8
10 files changed +128 -81
.travis.yml
+8 -80
@@ -61,23 +61,8 @@ matrix:
61 services:
62 - docker
63 before_install:
64 - - docker pull daald/ubuntu32:xenial
64 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
66 - env: Static Analysis
67 os: linux
68 compiler:
@@ -86,9 +71,8 @@ matrix:
71 packages:
72 - coccinelle
73 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
76 after_failure:
77 - env: Documentation
78 os: linux
@@ -99,70 +83,14 @@ matrix:
83 - asciidoc
84 - xmlto
85 before_install:
102 - before_script: gem install asciidoctor
86 + before_script:
87 script: ci/test-documentation.sh
88 after_failure:
89
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
94
95 notifications:
96 email: false
ci/install-dependencies.sh new
+43
@@ -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 new
+5
@@ -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 new
+18
@@ -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 new
+8
@@ -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 new
+23
@@ -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 new
+8
@@ -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 new
+10
@@ -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
+2
@@ -6,6 +6,8 @@
6 # supported) and a commit hash.
7 #
8
9 +. ${0%/*}/lib-travisci.sh
10 +
11 test $# -ne 2 && echo "Unexpected number of parameters" && exit 1
12 test -z "$GFW_CI_TOKEN" && echo "GFW_CI_TOKEN not defined" && exit
13
ci/test-documentation.sh
+3 -1
@@ -3,7 +3,9 @@
3 # Perform sanity checks on documentation and build it.
4 #
5
6 -set -e
6 +. ${0%/*}/lib-travisci.sh
7 +
8 +gem install asciidoctor
9
10 make check-builtins
11 make check-docs