Skip to content

Commit afd178f

Browse files
authored
Travis tweaks (#831)
* Speed up Travis build * Git clone options: limited depth to 10, disabled submodules * Cut down number of test combinations * Tweaks: consistent quoting, clone depth, removed -u from go get * Run go tests in parallel * Include osx explicitly on the test matrix * Run coverage for a single set of tests * Review comments * Env controlled parallelism * Removed git settings * Named profile files * Review
1 parent 8a243b0 commit afd178f

File tree

2 files changed

+73
-48
lines changed

2 files changed

+73
-48
lines changed

.travis.yml

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,55 @@ language: go
33

44
os:
55
- linux
6-
- osx
76

87
go:
98
- 1.8
109

1110
env:
12-
- GOFLAGS=''
11+
- WITH_COVERAGE=true
1312
- GOFLAGS='-race'
14-
- GOFLAGS='--tags batched_queue'
1513
- GOFLAGS='-race --tags batched_queue'
16-
- GOFLAGS='' WITH_ETCD=true
17-
- GOFLAGS='-race' WITH_ETCD=true
18-
- GOFLAGS='--tags pkcs11' WITH_PKCS11=true
19-
- GOFLAGS='-race --tags pkcs11' WITH_PKCS11=true
14+
- GOFLAGS='-race' WITH_ETCD=true
15+
- GOFLAGS='-race --tags pkcs11' WITH_PKCS11=true
2016

2117
matrix:
2218
fast_finish: true
2319
allow_failures:
2420
- os: osx
25-
exclude:
26-
- os: osx
27-
env: GOFLAGS= WITH_PKCS11=true
28-
- os: osx
29-
env: GOFLAGS=-race WITH_PKCS11=true
21+
include:
22+
- os: osx # Run only "vanilla" tests on osx
23+
env:
24+
25+
services: mysql
3026

3127
install:
32-
- if [[ "${WITH_PKCS11}" == "true" ]]; then sudo apt-get install softhsm ; fi
28+
- if [[ "${WITH_PKCS11}" == "true" ]]; then sudo apt-get install -y softhsm ; fi
3329
- |
34-
if [ ! -d $HOME/gopath/src/github.com/google ]; then
35-
mkdir -p $HOME/gopath/src/github.com/google
36-
ln -s $TRAVIS_BUILD_DIR $HOME/gopath/src/github.com/google/trillian
30+
if [ ! -d "$HOME/gopath/src/github.com/google" ]; then
31+
mkdir -p "$HOME/gopath/src/github.com/google"
32+
ln -s "$TRAVIS_BUILD_DIR" "$HOME/gopath/src/github.com/google/trillian"
3733
fi
3834
- mkdir ../protoc
3935
- |
4036
(
4137
cd ../protoc
42-
wget https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-${TRAVIS_OS_NAME}-x86_64.zip
43-
unzip protoc-3.2.0-${TRAVIS_OS_NAME}-x86_64.zip
38+
wget "https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-${TRAVIS_OS_NAME}-x86_64.zip"
39+
unzip "protoc-3.2.0-${TRAVIS_OS_NAME}-x86_64.zip"
4440
)
45-
- export PATH=$(pwd)/../protoc/bin:$PATH
41+
- export PATH="$(pwd)/../protoc/bin:$PATH"
4642
# googleapis is not Go code, but it's required for .pb.go regeneration because of API dependencies.
47-
- git clone https://github.com/googleapis/googleapis.git $GOPATH/src/github.com/googleapis/googleapis
43+
- git clone --depth=1 https://github.com/googleapis/googleapis.git "$GOPATH/src/github.com/googleapis/googleapis"
4844
- go get ${GOFLAGS} -d -t ./...
49-
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then brew update > /dev/null && brew install mariadb && mysql.server start; fi
50-
- go get -u github.com/client9/misspell/cmd/misspell
51-
- go get -u github.com/fzipp/gocyclo
52-
- go get -u github.com/gordonklaus/ineffassign
53-
- go get -u github.com/golang/lint/golint
54-
- go get -u github.com/golang/protobuf/proto
55-
- go get -u github.com/golang/protobuf/protoc-gen-go
56-
- go get -u github.com/kisielk/errcheck
57-
- go get -u golang.org/x/tools/cmd/stringer
58-
- go get -u github.com/google/certificate-transparency-go
45+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update > /dev/null && brew install mariadb && mysql.server start; fi
46+
- go get github.com/client9/misspell/cmd/misspell
47+
- go get github.com/fzipp/gocyclo
48+
- go get github.com/gordonklaus/ineffassign
49+
- go get github.com/golang/lint/golint
50+
- go get github.com/golang/protobuf/proto
51+
- go get github.com/golang/protobuf/protoc-gen-go
52+
- go get github.com/kisielk/errcheck
53+
- go get golang.org/x/tools/cmd/stringer
54+
- go get github.com/google/certificate-transparency-go
5955
- go get -d -t github.com/google/certificate-transparency-go/...
6056
- go install github.com/golang/{mock/mockgen,protobuf/protoc-gen-go}
6157
# install vendored protoc-gen-grpc-gateway binary
@@ -64,10 +60,13 @@ install:
6460
- go install ./vendor/github.com/coreos/etcd/cmd/etcd
6561
- go install ./vendor/github.com/coreos/etcd/cmd/etcdctl
6662

63+
before_script:
64+
- yes | ./scripts/resetdb.sh
65+
6766
script:
6867
- set -e
69-
- cd $HOME/gopath/src/github.com/google/trillian
70-
- ./scripts/presubmit.sh
68+
- cd "$HOME/gopath/src/github.com/google/trillian"
69+
- ./scripts/presubmit.sh ${WITH_COVERAGE:+--coverage}
7170
- |
7271
# Check re-generation didn't change anything
7372
# Skip protoc-generated files (.pb.go) because protoc is not deterministic
@@ -84,17 +83,15 @@ script:
8483
export ETCD_DIR="${GOPATH}/bin"
8584
fi
8685
- ./integration/integration_test.sh
87-
- cd $HOME/gopath/src/github.com/google/certificate-transparency-go
86+
- cd "$HOME/gopath/src/github.com/google/certificate-transparency-go"
8887
- ./trillian/integration/integration_test.sh
8988
- cd $HOME/gopath/src/github.com/google/trillian
9089
- HAMMER_OPTS="--operations=50" ./integration/maphammer.sh 3
9190
- set +e
9291

93-
services: mysql
94-
95-
before_script:
96-
- yes | ./scripts/resetdb.sh
97-
9892
after_success:
99-
- cp /tmp/coverage.txt .
100-
- bash <(curl -s https://codecov.io/bash)
93+
- |
94+
if [[ -f /tmp/coverage.txt ]]; then
95+
cp /tmp/coverage.txt .
96+
bash <(curl -s https://codecov.io/bash)
97+
fi

scripts/presubmit.sh

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#!/bin/bash
22
#
33
# Presubmit checks for Trillian.
4+
#
45
# Checks for lint errors, spelling, licensing, correct builds / tests and so on.
56
# Flags may be specified to allow suppressing of checks or automatic fixes, try
67
# `scripts/presubmit.sh --help` for details.
8+
#
9+
# Globals:
10+
# GO_TEST_PARALLELISM: max processes to use for Go tests. Optional (defaults
11+
# to 10).
712
set -eu
813

914
check_deps() {
@@ -25,18 +30,22 @@ check_cmd() {
2530
}
2631

2732
usage() {
28-
echo "$0 [--fix] [--no-build] [--no-linters] [--no-generate]"
33+
echo "$0 [--coverage] [--fix] [--no-build] [--no-linters] [--no-generate]"
2934
}
3035

3136
main() {
3237
check_deps
3338

39+
local coverage=0
3440
local fix=0
3541
local run_build=1
3642
local run_linters=1
3743
local run_generate=1
3844
while [[ $# -gt 0 ]]; do
3945
case "$1" in
46+
--coverage)
47+
coverage=1
48+
;;
4049
--fix)
4150
fix=1
4251
;;
@@ -93,16 +102,35 @@ main() {
93102
go build ${goflags} ${go_dirs}
94103

95104
echo 'running go test'
96-
echo "" > coverage.txt
105+
106+
# Individual package profiles are written to "$profile.out" files under
107+
# /tmp/trillian_profile.
108+
# An aggregate profile is created at /tmp/coverage.txt.
109+
mkdir -p /tmp/trillian_profile
110+
rm -f /tmp/trillian_profile/*
97111

98112
for d in ${go_dirs}; do
99-
go test -timeout=5m -short -coverprofile=profile.out -covermode=atomic ${goflags} $d
100-
if [ -f profile.out ]; then
101-
cat profile.out >> coverage.txt
102-
rm profile.out
113+
# Create a different -coverprofile for each test (if enabled)
114+
local coverflags=
115+
if [[ ${coverage} -eq 1 ]]; then
116+
# Transform $d to a smaller, valid file name.
117+
# For example:
118+
# * github.com/google/trillian becomes trillian.out
119+
# * github.com/google/trillian/cmd/createtree/keys becomes
120+
# trillian-cmd-createtree-keys.out
121+
local profile="${d}.out"
122+
profile="${profile#github.com/*/}"
123+
profile="${profile//\//-}"
124+
coverflags="-covermode=atomic -coverprofile='/tmp/trillian_profile/${profile}'"
103125
fi
104-
done
105-
cp coverage.txt /tmp
126+
127+
# Do not run go test in the loop, instead echo it so we can use xargs to
128+
# add some parallelism.
129+
echo go test -short -timeout=5m ${coverflags} ${goflags} "$d"
130+
done | xargs -I '{}' -P ${GO_TEST_PARALLELISM:=10} bash -c '{}'
131+
132+
[[ ${coverage} -eq 1 ]] && \
133+
cat /tmp/trillian_profile/*.out > /tmp/coverage.txt
106134
fi
107135

108136
if [[ "${run_linters}" -eq 1 ]]; then

0 commit comments

Comments
 (0)