Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 65fb5fd

Browse files
Merge pull request #498 from ijc/ci-improvements
some CI improvements
2 parents baf0b24 + 7219043 commit 65fb5fd

File tree

16 files changed

+168
-101
lines changed

16 files changed

+168
-101
lines changed

.golangci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
linters:
2+
enable-all: false
3+
disable-all: true
4+
enable:
5+
- deadcode
6+
- errcheck
7+
- gocyclo
8+
- gofmt
9+
- goimports
10+
- golint
11+
- gosimple
12+
- govet
13+
- ineffassign
14+
- interfacer
15+
- lll
16+
- misspell
17+
- nakedret
18+
- staticcheck
19+
- structcheck
20+
- typecheck
21+
- unconvert
22+
- unparam
23+
- unused
24+
- varcheck
25+
linters-settings:
26+
gocyclo:
27+
min-complexity: 16
28+
lll:
29+
line-length: 200

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ ENV PATH=${PATH}:/go/src/github.com/docker/app/bin/
2121
ARG DEP_VERSION=v0.5.0
2222
RUN curl -o /usr/bin/dep -L https://github.com/golang/dep/releases/download/${DEP_VERSION}/dep-linux-amd64 && \
2323
chmod +x /usr/bin/dep
24+
ARG GOTESTSUM_VERSION=v0.3.4
25+
RUN mkdir $GOPATH/src/gotest.tools && \
26+
git clone -q https://github.com/gotestyourself/gotestsum $GOPATH/src/gotest.tools/gotestsum && \
27+
cd $GOPATH/src/gotest.tools/gotestsum && \
28+
git -C $GOPATH/src/gotest.tools/gotestsum checkout -q $GOTESTSUM_VERSION && \
29+
GO111MODULE=on GOOS=linux go build -o /usr/local/bin/gotestsum-linux gotest.tools/gotestsum && \
30+
GO111MODULE=on GOOS=darwin go build -o /usr/local/bin/gotestsum-darwin gotest.tools/gotestsum && \
31+
GO111MODULE=on GOOS=windows go build -o /usr/local/bin/gotestsum-windows.exe gotest.tools/gotestsum && \
32+
ln -s gotestsum-linux /usr/local/bin/gotestsum
33+
# Source for cmd/test2json is part of the Go distribution and is
34+
# therefore available in the base image.
35+
RUN GOOS=linux go build -o /usr/local/bin/test2json-linux cmd/test2json && \
36+
GOOS=darwin go build -o /usr/local/bin/test2json-darwin cmd/test2json && \
37+
GOOS=windows go build -o /usr/local/bin/test2json-windows.exe cmd/test2json
2438
RUN go get -d gopkg.in/mjibson/esc.v0 && \
2539
cd /go/src/github.com/mjibson/esc && \
2640
go build -v -o /usr/bin/esc . && \

Dockerfile.lint

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,8 @@ RUN apk add --no-cache \
88
make \
99
coreutils
1010

11-
ENV GOMETALITER_VERSION=2.0.11
12-
ENV NAKEDRECT_SHA=c0e305a4f690fed163d47628bcc06a6d5655bf92
13-
14-
WORKDIR /go/src/github.com/alecthomas/gometalinter
15-
RUN curl -L https://github.com/alecthomas/gometalinter/archive/v${GOMETALITER_VERSION}.tar.gz | tar xz --strip-components=1 \
16-
&& go build -v -o /usr/local/bin/gometalinter . \
17-
&& gometalinter --install \
18-
&& rm -rf /go/src/* /go/pkg/*
19-
20-
WORKDIR /go/src/github.com/alexkohler/nakedret
21-
RUN git clone https://github.com/alexkohler/nakedret.git /go/src/github.com/alexkohler/nakedret \
22-
&& go build -v -o /usr/local/bin/nakedret . \
11+
RUN GO111MODULE=on go get \
12+
github.com/golangci/golangci-lint/cmd/[email protected] \
2313
&& rm -rf /go/src/* /go/pkg/*
2414

2515
WORKDIR /go/src/github.com/docker/app

Jenkinsfile

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ pipeline {
1919
steps {
2020
dir('src/github.com/docker/app') {
2121
checkout scm
22-
sh 'make -f docker.Makefile lint'
23-
sh 'make -f docker.Makefile check-vendor'
22+
ansiColor('xterm') {
23+
sh 'make -f docker.Makefile lint'
24+
sh 'make -f docker.Makefile check-vendor'
25+
}
2426
}
2527
}
2628
post {
@@ -38,7 +40,9 @@ pipeline {
3840
script {
3941
try {
4042
checkout scm
41-
sh 'make -f docker.Makefile cli-cross cross e2e-cross tars'
43+
ansiColor('xterm') {
44+
sh 'make -f docker.Makefile cli-cross cross e2e-cross tars'
45+
}
4246
dir('bin') {
4347
stash name: 'binaries'
4448
}
@@ -72,9 +76,11 @@ pipeline {
7276
steps {
7377
dir('src/github.com/docker/app') {
7478
checkout scm
75-
sh 'make -f docker.Makefile save-invocation-image'
76-
sh 'make -f docker.Makefile INVOCATION_IMAGE_TAG=$BUILD_TAG-coverage OUTPUT=coverage-invocation-image.tar save-invocation-image-tag'
77-
sh 'make -f docker.Makefile INVOCATION_IMAGE_TAG=$BUILD_TAG-coverage-experimental OUTPUT=coverage-experimental-invocation-image.tar save-invocation-image-tag'
79+
ansiColor('xterm') {
80+
sh 'make -f docker.Makefile save-invocation-image'
81+
sh 'make -f docker.Makefile INVOCATION_IMAGE_TAG=$BUILD_TAG-coverage OUTPUT=coverage-invocation-image.tar save-invocation-image-tag'
82+
sh 'make -f docker.Makefile INVOCATION_IMAGE_TAG=$BUILD_TAG-coverage-experimental OUTPUT=coverage-experimental-invocation-image.tar save-invocation-image-tag'
83+
}
7884
dir('_build') {
7985
stash name: 'invocation-image', includes: 'invocation-image.tar'
8086
stash name: 'coverage-invocation-image', includes: 'coverage-invocation-image.tar'
@@ -108,13 +114,22 @@ pipeline {
108114
unstash "coverage-invocation-image"
109115
sh 'docker load -i coverage-invocation-image.tar'
110116
}
111-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG-coverage coverage'
117+
ansiColor('xterm') {
118+
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG-coverage coverage-run || true'
119+
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG-coverage coverage-results'
120+
}
112121
archiveArtifacts '_build/ci-cov/all.out'
113122
archiveArtifacts '_build/ci-cov/coverage.html'
114123
}
115124
}
116125
post {
117126
always {
127+
dir('src/github.com/docker/app/_build/test-results') {
128+
sh '[ ! -e unit-coverage.xml ] || sed -i -E -e \'s,"github.com/docker/app","unit/basic",g; s,"github.com/docker/app/([^"]*)","unit/basic/\\1",g\' unit-coverage.xml'
129+
sh '[ ! -e e2e-coverage.xml ] || sed -i -E -e \'s,"github.com/docker/app/e2e","e2e/basic",g\' e2e-coverage.xml'
130+
archiveArtifacts '*.xml'
131+
junit '*.xml'
132+
}
118133
sh 'docker rmi docker/cnab-app-base:$BUILD_TAG-coverage'
119134
deleteDir()
120135
}
@@ -131,11 +146,20 @@ pipeline {
131146
unstash "coverage-experimental-invocation-image"
132147
sh 'docker load -i coverage-experimental-invocation-image.tar'
133148
}
134-
sh 'make EXPERIMENTAL=on -f docker.Makefile BUILD_TAG=$BUILD_TAG-coverage-experimental coverage'
149+
ansiColor('xterm') {
150+
sh 'make EXPERIMENTAL=on TEST_RESULTS_PREFIX="experimental-" -f docker.Makefile BUILD_TAG=$BUILD_TAG-coverage-experimental coverage-run || true'
151+
sh 'make EXPERIMENTAL=on TEST_RESULTS_PREFIX="experimental-" -f docker.Makefile BUILD_TAG=$BUILD_TAG-coverage-experimental coverage-results'
152+
}
135153
}
136154
}
137155
post {
138156
always {
157+
dir('src/github.com/docker/app/_build/test-results') {
158+
sh '[ ! -e experimental-unit-coverage.xml ] || sed -i -E -e \'s,"github.com/docker/app","unit/experimental",g; s,"github.com/docker/app/([^"]*)","unit/experimental/\\1",g\' experimental-unit-coverage.xml'
159+
sh '[ ! -e experimental-e2e-coverage.xml ] || sed -i -E -e \'s,"github.com/docker/app/e2e","e2e/experimental",g\' experimental-e2e-coverage.xml'
160+
archiveArtifacts '*.xml'
161+
junit '*.xml'
162+
}
139163
sh 'docker rmi docker/cnab-app-base:$BUILD_TAG-coverage-experimental'
140164
deleteDir()
141165
}
@@ -151,7 +175,9 @@ pipeline {
151175
dir("bin") {
152176
unstash "binaries"
153177
}
154-
sh 'make -f docker.Makefile gradle-test'
178+
ansiColor('xterm') {
179+
sh 'make -f docker.Makefile gradle-test'
180+
}
155181
}
156182
}
157183
post {
@@ -182,11 +208,15 @@ pipeline {
182208
dir('e2e'){
183209
unstash "e2e"
184210
}
185-
sh './docker-app-e2e-linux --e2e-path=e2e'
211+
ansiColor('xterm') {
212+
sh './gotestsum-linux --format short-verbose --junitfile e2e-linux.xml --raw-command -- ./test2json-linux -t -p e2e/linux ./docker-app-e2e-linux -test.v --e2e-path=e2e'
213+
}
186214
}
187215
}
188216
post {
189217
always {
218+
archiveArtifacts 'src/github.com/docker/app/e2e-linux.xml'
219+
junit 'src/github.com/docker/app/e2e-linux.xml'
190220
sh 'docker rmi docker/cnab-app-base:$BUILD_TAG'
191221
deleteDir()
192222
}

Jenkinsfile.baguette

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ pipeline {
2121
script {
2222
try {
2323
checkout scm
24-
sh 'make -f docker.Makefile lint'
25-
sh 'make -f docker.Makefile cli-cross cross e2e-cross tars'
24+
ansiColor('xterm') {
25+
sh 'make -f docker.Makefile lint'
26+
sh 'make -f docker.Makefile cli-cross cross e2e-cross tars'
27+
}
2628
dir('bin') {
2729
stash name: 'binaries'
2830
}
@@ -56,8 +58,10 @@ pipeline {
5658
steps {
5759
dir('src/github.com/docker/app') {
5860
checkout scm
59-
sh 'make -f docker.Makefile save-invocation-image'
60-
sh 'make -f docker.Makefile save-invocation-image-tag INVOCATION_IMAGE_TAG=$BUILD_TAG-coverage OUTPUT=coverage-invocation-image.tar'
61+
ansiColor('xterm') {
62+
sh 'make -f docker.Makefile save-invocation-image'
63+
sh 'make -f docker.Makefile save-invocation-image-tag INVOCATION_IMAGE_TAG=$BUILD_TAG-coverage OUTPUT=coverage-invocation-image.tar'
64+
}
6165
dir('_build') {
6266
stash name: 'invocation-image', includes: 'invocation-image.tar'
6367
stash name: 'coverage-invocation-image', includes: 'coverage-invocation-image.tar'
@@ -77,7 +81,7 @@ pipeline {
7781
}
7882
stage('Test') {
7983
parallel {
80-
stage("Unit Coverage") {
84+
stage("Coverage") {
8185
environment {
8286
DOCKERAPP_BINARY = '../e2e/coverage-bin'
8387
DOCKERCLI_BINARY = '../docker-linux'
@@ -93,14 +97,23 @@ pipeline {
9397
unstash "coverage-invocation-image"
9498
sh 'docker load -i coverage-invocation-image.tar'
9599
}
96-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG-coverage coverage'
100+
ansiColor('xterm') {
101+
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG-coverage coverage-run || true'
102+
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG-coverage coverage-results'
103+
}
97104
archiveArtifacts '_build/ci-cov/all.out'
98105
archiveArtifacts '_build/ci-cov/coverage.html'
99106
sh 'curl -s https://codecov.io/bash | bash -s - -f _build/ci-cov/all.out -K'
100107
}
101108
}
102109
post {
103110
always {
111+
dir('src/github.com/docker/app/_build/test-results') {
112+
sh '[ ! -e unit-coverage.xml ] || sed -i -E -e \'s,"github.com/docker/app","unit",g; s,"github.com/docker/app/([^"]*)","unit/\\1",g\' unit-coverage.xml'
113+
sh '[ ! -e e2e-coverage.xml ] || sed -i -E -e \'s,"github.com/docker/app/e2e","e2e/coverage",g\' e2e-coverage.xml'
114+
archiveArtifacts '*.xml'
115+
junit '*.xml'
116+
}
104117
sh 'docker rmi docker/cnab-app-base:$BUILD_TAG-coverage'
105118
deleteDir()
106119
}
@@ -116,7 +129,9 @@ pipeline {
116129
dir("bin") {
117130
unstash "binaries"
118131
}
119-
sh 'make -f docker.Makefile gradle-test'
132+
ansiColor('xterm') {
133+
sh 'make -f docker.Makefile gradle-test'
134+
}
120135
}
121136
}
122137
post {
@@ -148,11 +163,13 @@ pipeline {
148163
unstash "e2e"
149164
}
150165
sh './docker-linux version'
151-
sh './docker-app-e2e-linux -test.v --e2e-path=e2e'
166+
sh './gotestsum-linux --format short-verbose --junitfile e2e-linux.xml --raw-command -- ./test2json-linux -t -p e2e/linux ./docker-app-e2e-linux -test.v --e2e-path=e2e'
152167
}
153168
}
154169
post {
155170
always {
171+
archiveArtifacts 'src/github.com/docker/app/e2e-linux.xml'
172+
junit 'src/github.com/docker/app/e2e-linux.xml'
156173
sh 'docker rmi docker/cnab-app-base:$BUILD_TAG'
157174
deleteDir()
158175
}
@@ -181,11 +198,13 @@ pipeline {
181198
unstash "e2e"
182199
}
183200
sh './docker-darwin version'
184-
sh './docker-app-e2e-darwin -test.v --e2e-path=e2e'
201+
sh './gotestsum-darwin --format short-verbose --junitfile e2e-darwin.xml --raw-command -- ./test2json-darwin -t -p e2e/darwin ./docker-app-e2e-darwin -test.v --e2e-path=e2e'
185202
}
186203
}
187204
post {
188205
always {
206+
archiveArtifacts 'src/github.com/docker/app/e2e-darwin.xml'
207+
junit 'src/github.com/docker/app/e2e-darwin.xml'
189208
sh 'docker rmi docker/cnab-app-base:$BUILD_TAG'
190209
deleteDir()
191210
}
@@ -214,11 +233,13 @@ pipeline {
214233
dir('e2e'){
215234
unstash "e2e"
216235
}
217-
bat 'docker-app-e2e-windows.exe -test.v --e2e-path=e2e'
236+
bat 'gotestsum-windows.exe --format short-verbose --junitfile e2e-windows.xml --raw-command -- test2json-windows.exe -t -p e2e/windows docker-app-e2e-windows.exe -test.v --e2e-path=e2e'
218237
}
219238
}
220239
post {
221240
always {
241+
archiveArtifacts 'src/github.com/docker/app/e2e-windows.xml'
242+
junit 'src/github.com/docker/app/e2e-windows.xml'
222243
bat 'docker rmi docker/cnab-app-base:%BUILD_TAG%'
223244
deleteDir()
224245
}
@@ -245,7 +266,9 @@ pipeline {
245266
unstash "invocation-image"
246267
sh 'docker load -i invocation-image.tar'
247268
}
248-
sh 'make -f docker.Makefile push-invocation-image'
269+
ansiColor('xterm') {
270+
sh 'make -f docker.Makefile push-invocation-image'
271+
}
249272
}
250273
unstash 'artifacts'
251274
echo "Releasing $TAG_NAME"

Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ ifeq ($(OS),Windows_NT)
2424
EXEC_EXT := .exe
2525
endif
2626

27+
TEST_RESULTS_DIR = _build/test-results
2728
STATIC_FLAGS= CGO_ENABLED=0
2829
GO_BUILD = $(STATIC_FLAGS) go build -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
2930
GO_TEST = $(STATIC_FLAGS) go test -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
31+
GO_TESTSUM = $(STATIC_FLAGS) gotestsum --junitfile $(TEST_RESULTS_DIR)/$(TEST_RESULTS_PREFIX)$(1) -- -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
3032

3133
all: bin/$(BIN_NAME) test
3234

@@ -71,28 +73,32 @@ test: test-unit test-e2e ## run all tests
7173

7274
lint: ## run linter(s)
7375
@echo "Linting..."
74-
@gometalinter --config=gometalinter.json ./...
76+
@golangci-lint run ./...
7577

7678
test-e2e: bin/$(BIN_NAME) ## run end-to-end tests
7779
@echo "Running e2e tests..."
78-
$(GO_TEST) -v ./e2e/
80+
@$(call mkdir,$(TEST_RESULTS_DIR))
81+
$(call GO_TESTSUM,e2e.xml) -v ./e2e/
7982

8083
test-unit: ## run unit tests
8184
@echo "Running unit tests..."
82-
$(GO_TEST) $(shell go list ./... | grep -vE '/e2e')
85+
@$(call mkdir,$(TEST_RESULTS_DIR))
86+
$(call GO_TESTSUM,unit.xml) $(shell go list ./... | grep -vE '/e2e')
8387

8488
coverage-bin:
8589
CGO_ENABLED=0 go test -tags="$(BUILDTAGS) testrunmain" -ldflags=$(LDFLAGS) -coverpkg="./..." -c -o _build/$(BIN_NAME).cov ./cmd/docker-app
8690

8791
coverage-test-unit:
8892
@echo "Running unit tests (coverage)..."
8993
@$(call mkdir,_build/cov)
90-
$(GO_TEST) -cover -test.coverprofile=_build/cov/unit.out $(shell go list ./... | grep -vE '/e2e')
94+
@$(call mkdir,$(TEST_RESULTS_DIR))
95+
$(call GO_TESTSUM,unit-coverage.xml) -cover -test.coverprofile=_build/cov/unit.out $(shell go list ./... | grep -vE '/e2e')
9196

9297
coverage-test-e2e: coverage-bin
9398
@echo "Running e2e tests (coverage)..."
9499
@$(call mkdir,_build/cov)
95-
DOCKERAPP_BINARY=../e2e/coverage-bin $(GO_TEST) -v ./e2e
100+
@$(call mkdir,$(TEST_RESULTS_DIR))
101+
DOCKERAPP_BINARY=../e2e/coverage-bin $(call GO_TESTSUM,e2e-coverage.xml) -v ./e2e
96102

97103
coverage: coverage-test-unit coverage-test-e2e ## run tests with coverage
98104
go install ./vendor/github.com/wadey/gocovmerge/

cmd/cnab-run/render.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func renderAction(instanceName string) error {
3939
if err != nil {
4040
return err
4141
}
42-
fmt.Printf(res)
42+
fmt.Print(res)
4343

4444
return nil
4545
}

0 commit comments

Comments
 (0)