forked from mendersoftware/inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
202 lines (187 loc) · 6.24 KB
/
.gitlab-ci.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
image: docker
cache:
paths:
- /apt-cache
- /go/src/github.com
- /go/src/golang.org
- /go/src/google.golang.org
- /go/src/gopkg.in
- node_modules
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_REPOSITORY: mendersoftware/inventory
services:
- docker:dind
- mongo
stages:
- test_prep_build
- test_prep
- test
- build
- publish
before_script:
- mkdir -p /go/src/github.com/mendersoftware /go/src/_/builds
- cp -r $CI_PROJECT_DIR /go/src/github.com/mendersoftware/inventory
- ln -s /go/src/github.com/mendersoftware /go/src/_/builds/mendersoftware
- cd /go/src/github.com/mendersoftware/inventory
# 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
test:build_acceptance:
image: golang:1.11
stage: test_prep_build
script:
- CGO_ENABLED=0 go test -c -o /go/src/github.com/mendersoftware/inventory/inventory-test -coverpkg $(go list ./... | grep -v vendor | grep -v mock | grep -v test | tr '\n' ,);
- cp /go/src/github.com/mendersoftware/inventory/inventory-test $CI_PROJECT_DIR
artifacts:
untracked: true
paths:
- inventory-test
test:prepare_acceptance:
before_script: []
stage: test_prep
dependencies:
- test:build_acceptance
script:
- docker build -f Dockerfile.acceptance-testing -t $DOCKER_REPOSITORY:prtest .;
- docker save $DOCKER_REPOSITORY:prtest > tests_image.tar
- docker build -t $DOCKER_REPOSITORY:pr .
- docker run --rm --entrypoint "/bin/sh" -v $(pwd):/binary $DOCKER_REPOSITORY:pr -c "cp /usr/bin/inventory /binary"
- docker build -t testing -f tests/Dockerfile tests
- docker save testing > acceptance_testing_image.tar
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- /go/src/github.com/mendersoftware/inventory/inventory-test
policy: pull
artifacts:
expire_in: 30min
paths:
- tests_image.tar
- acceptance_testing_image.tar
- inventory
test:acceptance_tests:
image: tiangolo/docker-with-compose
before_script: []
services:
- docker:dind
stage: test
dependencies:
- test:build_acceptance
- test:prepare_acceptance
script:
- apk add git bash
- git clone https://github.com/mendersoftware/integration.git
- mv integration/extra/travis-testing/* tests/
- mv docs/* tests/
- mv inventory tests/
- docker load -i tests_image.tar
- docker load -i acceptance_testing_image.tar
- TESTS_DIR=$(pwd)/tests $(pwd)/tests/run-test-environment acceptance $(pwd)/integration $(pwd)/tests/docker-compose.yml ;
artifacts:
expire_in: 30min
paths:
- tests/coverage-acceptance.txt
tags:
- docker
test:static:
image: golang:1.11
stage: test
dependencies: []
script:
- curl -sL https://deb.nodesource.com/setup_11.x | bash -
- apt-get -qq update
- apt-get install -qy --allow-unauthenticated python3-pip nodejs
- pip3 install pyyaml
- npm install -g swagger-cli
# Get our own Swagger verifier
- wget https://raw.githubusercontent.com/mendersoftware/autodocs/master/verify_docs.py
# 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
- if test "$(ls -A docs)"; then python3 verify_docs.py `find docs -name "*.yml"`; fi
test:unit:
image: golang:1.11.4
stage: test
dependencies: []
script:
- apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
- echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/3.6 main" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list
- apt-get -qq update
- apt-get install -qy --allow-unauthenticated mongodb-org-server=3.6.11
- go list ./... | grep -v vendor | xargs -n1 -I {} -P 4 go test -v -covermode=atomic -coverprofile=../../../{}/coverage.txt {} || exit $? ;
- mkdir -p tests/unit-coverage && find . -name 'coverage.txt' -exec cp --parents {} ./tests/unit-coverage \;
- tar -cvf $CI_PROJECT_DIR/unit-coverage.tar tests/unit-coverage
artifacts:
expire_in: 30min
paths:
- unit-coverage.tar
build:
before_script: []
stage: build
script:
- docker build -t $DOCKER_REPOSITORY:pr .
- docker save $DOCKER_REPOSITORY:pr > image.tar
artifacts:
expire_in: 1h
paths:
- image.tar
tags:
- docker
publish:docs:
before_script: []
stage: publish
script:
- echo "publishing docs"
publish:tests:
stage: publish
before_script: []
dependencies:
- test:acceptance_tests
- test:unit
script:
- tar -xvf unit-coverage.tar
# - bash <(curl -s https://codecov.io/bash) -F unittests -s ./tests/unit-coverage;
# - bash <(curl -s https://codecov.io/bash) -F acceptance -f ./tests/coverage-acceptance.txt;
publish:build:
before_script: []
stage: publish
dependencies:
- build
script:
- echo "publishing image to docker hub"
# - docker load -i image.tar
# - if [ ! -z "$CI_COMMIT_TAG" ]; then export IMAGE_TAG=$CI_COMMIT_TAG; else export IMAGE_TAG=$CI_COMMIT_REF_NAME; fi ;
# - 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 ;
except:
- master
tags:
- docker
publish:build:master:
before_script: []
stage: publish
dependencies:
- build
script:
- echo "publishing image to docker hub"
# - docker load -i image.tar
# - export COMMIT_TAG="$CI_COMMIT_REF_NAME"_"$CI_COMMIT_SHA";
# - docker tag $DOCKER_REPOSITORY:pr $DOCKER_REPOSITORY:$COMMIT_TAG;
# - docker push $DOCKER_REPOSITORY:$COMMIT_TAG;
only:
- master
tags:
- docker