-
Notifications
You must be signed in to change notification settings - Fork 5
/
.gitlab-ci.yml
227 lines (199 loc) · 5.33 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
image: registry.gitlab.com/orobardet/gitlab-ci-linter/build:1.13
stages:
- vendors
- checks
- tests
- build
- publish
- latest
- releasenote
variables:
AF_BINARY_URL: "https://api.bintray.com/"
AF_BINARY_SUBJECT: "orobardet"
AF_BINARY_REPO: "gitlab-ci-linter"
AF_BINARY_PACKAGE: "gitlab-ci-linter"
BINARY_NAME: "gitlab-ci-linter"
CI_GITLAB_URL: "https://gitlab.com"
GOFLAGS: "-mod=vendor"
COVERAGEREPORTDIR: "coverage"
DOCBUILDDIR: "godoc"
## -- Vendor stage ------------------------------------------------------------
# Retrieve dependencies
get vendors:
stage: vendors
script:
- go mod vendor
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
paths:
- vendor/
expire_in: 1 hour
## -- Check stage -------------------------------------------------------------
gofmt:
stage: checks
script: make fmt
govet:
stage: checks
script: make vet
checkstyle:
stage: checks
script: make checkstyle
gocyclo:
stage: checks
script: make cyclo
gosec:
stage: checks
script: make secucheck
snyk:
stage: checks
script:
- snyk test
- snyk monitor
only:
- branches@orobardet/gitlab-ci-linter
## -- Test stage -------------------------------------------------------------
# A test job template, to make different test jobs by branch/tags
.go test: &_go_test_template
stage: tests
variables:
GOTESTFLAGS: -v
script:
- make test
- make html-cover
coverage: /^total:\s*\(statements\)\s*(\d+.\d+)\%/
# Coverage on branches are only kept for 1 week
go test:
<<: *_go_test_template
only:
- branches
artifacts:
paths:
- $COVERAGEREPORTDIR/
expire_in: 1 week
# Coverage results on tags are kept much longer (1 year)
go test release:
<<: *_go_test_template
only:
- tags
artifacts:
paths:
- $COVERAGEREPORTDIR/
expire_in: 1 year
## -- Build stage -------------------------------------------------------------
# Job template to build a go binary from source, for a given platform and architecture.
# The job name contains pf and arch: job name is supposed to ends with "PF-ARCH"
# e.g.:
# - build dev linux-amd64
# - release build linux-i386
.build_binary: &_binary
stage: build
script:
- export GOTARGET=${CI_JOB_NAME##* }
- export GOOS=${GOTARGET%%-*}
- export GOARCH=${GOTARGET##*-}
- export EXT="$([[ "$GOOS" = "windows" ]] && echo ".exe")"
- export BINARY=bin/${BINARY_NAME}.${GOOS}-${GOARCH}${EXT}
- if [[ $VERSION ]] ; then export VERSION=${VERSION##v} ; fi
- if [[ "$RELEASE" -eq 1 ]] ; then make release ; else make build ; fi
- if [[ "$UPLOAD" -eq 1 ]] ; then curl -T $BINARY -u${AF_API_USER}:${AF_API_KEY} "$AF_BINARY_URL/content/$AF_BINARY_SUBJECT/$AF_BINARY_REPO/$AF_BINARY_PACKAGE/${VERSION}/v${VERSION}/$(basename $BINARY)?override=1&publish=1" ; fi
# Job template for building **development** binary, using general build job template and adding:
# - Enable debug
# - Only on branches
# - Binary kept as artifact for a week
.build_binary_dev: &_binary_dev
<<: *_binary
variables:
DEBUG: "1"
only:
- branches
artifacts:
name: "${CI_JOB_NAME}"
paths:
- bin/*
expire_in: 1 week
# Job template for building **release** binary, using general build job template and adding:
# - Versioning
# - Release optimization
# - Only on tags
# - Binary kept as artifact for a year (much longer than dev build)
.build_binary_release: &_binary_release
<<: *_binary
variables:
VERSION: ${CI_COMMIT_TAG}
RELEASE: "1"
UPLOAD: "1"
only:
- tags@orobardet/gitlab-ci-linter
artifacts:
name: "${CI_JOB_NAME}"
paths:
- bin/*
expire_in: 1 year
# Jobs to build dev binaries
dev build linux-386: *_binary_dev
dev build linux-amd64: *_binary_dev
dev build linux-arm: *_binary_dev
dev build linux-arm64: *_binary_dev
dev build windows-386: *_binary_dev
dev build windows-amd64: *_binary_dev
dev build darwin-386: *_binary_dev
dev build darwin-amd64: *_binary_dev
# Jobs release binaries
release build linux-386: *_binary_release
release build linux-amd64: *_binary_release
release build linux-arm: *_binary_release
release build linux-arm64: *_binary_release
release build windows-386: *_binary_release
release build windows-amd64: *_binary_release
release build darwin-386: *_binary_release
release build darwin-amd64: *_binary_release
# Build godoc
.godoc: &_godoc
stage: build
script:
- mkdir -p $GOPATH/src/$HOSTED_PATH
- cp -r * $GOPATH/src/$HOSTED_PATH
- make godoc
dev godoc:
<<: *_godoc
only:
- branches
artifacts:
name: "${CI_JOB_NAME}"
paths:
- $DOCBUILDDIR
expire_in: 1 week
godoc:
<<: *_godoc
only:
- tags@orobardet/gitlab-ci-linter
artifacts:
name: "${CI_JOB_NAME}"
paths:
- $DOCBUILDDIR
expire_in: 1 year
## -- Publishing stage --------------------------------------------------------
pages:
stage: publish
environment:
name: Gitlab Pages
url: https://orobardet.gitlab.io/gitlab-ci-linter/
script:
- cp -r doc/pages public
- cp -r $COVERAGEREPORTDIR public/coverage
- cp -r $DOCBUILDDIR public/godoc
artifacts:
paths:
- public
only:
- master
except:
- tags
#Update Release note:
# stage: releasenote
# allow_failure: true
# variables:
# VERSION: ${CI_COMMIT_TAG}
# script: ci/update-gitlab-release.sh
# only:
# - tags@orobardet/gitlab-ci-linter