forked from mendersoftware/deployments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
202 lines (162 loc) · 7.1 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
language: go
# Forces travis to use VM insted container, required to be able to build containers.
sudo: required
cache:
pip: true
directories:
- node_modules
services:
- docker
- mongodb
addons:
apt:
sources:
- mongodb-3.4-precise
packages:
- mongodb-org-server
# Golang version matrix
go:
- 1.8
env:
matrix:
- JOB_TYPE=compile_and_basic_tests
- JOB_TYPE=compile_and_acceptance_tests
global:
# Should be encrypted or set as private travis variables (in travis settings):
# AWS_ACCESS_KEY_ID
# AWS_SECRET_ACCESS_KEY
# GITHUB_RELEASE_TOKEN
# DOCKER_HUB_EMAIL
# DOCKER_HUB_USERNAME
# DOCKER_HUB_PASSWORD
# AWS S3 bucket name, to store updated docs
- AWS_BUCKET_DOCS=mender-docs
# AWS region.
# Can be overridden by travis private variable set in travis settings: AWS_REGION_OVERRIDE
- AWS_REGION=eu-west-1
# Docker repository name
- DOCKER_REPOSITORY="mendersoftware/deployments"
# Use correct branch for testing
- TEST_BRANCH=$TRAVIS_BRANCH
before_install:
# Install code coverage / tooling
- go get -u github.com/axw/gocov/gocov
- go get -u golang.org/x/tools/cmd/cover
# Install cyclomatic dependency analysis tool
- go get -u github.com/fzipp/gocyclo
- sudo apt-get -qq install -y e2tools
- npm install -g swagger-cli
- pip2.7 install -U --user paramiko fabric PyYAML pytest requests pytest-xdist filelock
# Get our own Swagger verifier
- wget https://raw.githubusercontent.com/mendersoftware/autodocs/master/verify_docs.py
install: true
before_script:
# Print build info that binary is compiled with.
- echo $TRAVIS_COMMIT
- echo $TRAVIS_TAG
- echo $TRAVIS_BRANCH
- echo $TRAVIS_BUILD_NUMBER
- echo $TRAVIS_REPO_SLUG
# Rename the branch we're on, so that it's not in the way for the
# subsequent fetch. It's ok if this fails, it just means we're not on any
# branch.
- git branch -m temp-branch || true
# Git trick: Fetch directly into our local branches instead of remote
# branches.
- git fetch origin 'refs/heads/*:refs/heads/*'
# Get last remaining tags, if any.
- git fetch --tags origin
# Test if code was formatted with 'go fmt'
# Command will format code and return modified files
# fail if any have been modified.
- if [ -n "$(go fmt)" ]; then echo 'Code is not formatted with "go fmt"'; false; fi
# Perform static code analysys
- go vet `go list ./... | grep -v vendor`
# Fail builds when the cyclomatic complexity reaches 15 or more
- gocyclo -over 15 `find . -iname '*.go' | grep -v 'vendor' | grep -v '_test.go'`
# Verify that the Swagger docs are valid
- swagger-cli validate docs/*.yml
# Verify that the Swagger docs follow the autodeployment requirements
- python2.7 verify_docs.py `find docs -name "*.yml"`
script:
# go list supply import paths for all sub directories.
# Exclude vendor directory, we don't want to run tests and coverage for all dependencies every time,
# also including their coverage may introduce to much noice. Concentrate on the coverage of local packages.
# Execute go test on every local subpackage (resolved as dependencies) and generate covreage report for each.
# Test packages pararell (xargs -P)
- if [[ "$JOB_TYPE" = compile_and_basic_tests ]]; then
go list ./... | grep -v vendor | xargs -n1 -I {} -P 4 go test -v -covermode=atomic -coverprofile=../../../{}/coverage.txt {} || exit $? ;
fi
# Insert build information into compiled binary using ldflags
- CGO_ENABLED=0 go build -ldflags "-X main.Commit=`echo $TRAVIS_COMMIT` -X main.Tag=`echo $TRAVIS_TAG` -X main.Branch=`echo $TRAVIS_BRANCH` -X main.BuildNumber=`echo $TRAVIS_BUILD_NUMBER`"
# Clone integration repo. for api testing (purposely after license checking..)
# Exexutes acceptance/integration tasts with branch: master
- git clone -b master https://github.com/mendersoftware/integration.git integration_new
# Move script to testing directory
- if [[ "$JOB_TYPE" = compile_and_acceptance_tests ]]; then
mv integration_new/extra/travis-testing/* tests;
fi
# acceptance tests
# NOTE: the tests require mender-artifact binary to be available
- if [[ "$JOB_TYPE" = compile_and_acceptance_tests ]]; then
CGO_ENABLED=0 go test -c -o deployments-test -coverpkg $(go list ./... | grep -v vendor | grep -v mock | grep -v test | tr '\n' ,) &&
sudo docker build -f Dockerfile.acceptance-testing -t $DOCKER_REPOSITORY:prtest . &&
CGO_ENABLED=0 go build &&
CGO_ENABLED=0 go get -u -v github.com/mendersoftware/mender-artifact && go install github.com/mendersoftware/mender-artifact/cli/mender-artifact &&
( ./tests/build-acceptance ./tests ./docs/management_api.yml ./docs/devices_api.yml ./docs/internal_api.yml `which mender-artifact` deployments &&
TESTS_DIR=$PWD/tests ./tests/run-test-environment "acceptance" $PWD/integration_new ./tests/docker-compose-acceptance.yml &&
TESTS_DIR=$PWD/tests ./tests/run-test-environment "acceptance" $PWD/integration_new ./tests/docker-compose-acceptance.mt.yml);
fi
- if [ "$JOB_TYPE" = compile_and_basic_tests ]; then
sudo docker build -t $DOCKER_REPOSITORY:pr . ;
fi
after_success:
# Integrate with https://codecov.io
- if [[ "$JOB_TYPE" = compile_and_basic_tests ]]; then
bash <(curl -s https://codecov.io/bash) -F unittests ;
fi
- if [[ "$JOB_TYPE" = compile_and_acceptance_tests ]]; then
bash <(curl -s https://codecov.io/bash) -F acceptance ;
fi
before_deploy:
# Master is always lastest
- if [ ! -z "$TRAVIS_TAG" ]; then export IMAGE_TAG=$TRAVIS_TAG; else export IMAGE_TAG=$TRAVIS_BRANCH; fi
# Upload image to docker registry only on PUSH
- if [ "$JOB_TYPE" = compile_and_basic_tests ]; then
docker tag $DOCKER_REPOSITORY:pr $DOCKER_REPOSITORY:$IMAGE_TAG;
docker login --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD;
docker push $DOCKER_REPOSITORY:$IMAGE_TAG;
if [ "$TRAVIS_BRANCH" = master ]; then
export COMMIT_TAG="$TRAVIS_BRANCH"_"$TRAVIS_COMMIT";
docker tag $DOCKER_REPOSITORY:pr $DOCKER_REPOSITORY:$COMMIT_TAG;
docker push $DOCKER_REPOSITORY:$COMMIT_TAG;
fi;
fi
deploy:
# Store docs for auto-deployment script
-
provider: s3
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
bucket: $AWS_BUCKET_DOCS
region: $AWS_REGION
upload-dir: $TRAVIS_REPO_SLUG/latest/$TRAVIS_BRANCH
local_dir: docs
skip_cleanup: true
acl: public_read
on:
repo: $TRAVIS_REPO_SLUG
all_branches: true
# Force before_deploy for branches
-
provider: script
script: /bin/true
on:
all_branches: true
# Force before_deploy for tags
-
provider: script
script: /bin/true
on:
tags: true
all_branches: true