-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
448 lines (443 loc) · 14.1 KB
/
.gitlab-ci.yml
File metadata and controls
448 lines (443 loc) · 14.1 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
stages:
- bots
- lint
- checks
- build
- test
- e2e
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_BASE_IMAGE: $CI_REGISTRY_GO/haproxy-debian
BATS_VERSION: v1.10.0
GO_VERSION: "1.26"
DOCKER_VERSION: "29.1"
JUNIT_FILE: "junit-report.xml"
pipelines-check:
stage: bots
needs: []
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [""]
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
tags:
- go
script:
- go run cmd/gitlab-mr-pipelines/main.go
after_script:
- |
if [ "$CI_JOB_STATUS" == "success" ]; then
junit-report add --status=ok --message="pipelines check passed"
else
junit-report add --status=failed --message="pipelines check failed"
fi
artifacts:
when: on_failure
paths:
- junit-report.xml
reports:
junit: junit-report.xml
mr-backport-question:
stage: bots
needs: []
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [ "" ]
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
tags:
- go
script:
- go run cmd/gitlab-mr-checker/main.go
after_script:
- |
if [ "$CI_JOB_STATUS" == "success" ]; then
junit-report add --status=ok --message="backport check passed"
else
junit-report add --status=failed --message="backport check failed"
fi
artifacts:
when: on_failure
paths:
- junit-report.xml
reports:
junit: junit-report.xml
diff:
stage: lint
needs: [pipelines-check]
image:
name: $CI_REGISTRY_GO/docker:$DOCKER_VERSION-go$GO_VERSION
entrypoint: [""]
services:
- name: $CI_REGISTRY_GO/docker:$DOCKER_VERSION-dind
alias: docker
tags:
- go
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push'
script:
#- apk add make curl bash jq
- SWAGGER_VERSION=$(curl -s https://raw.githubusercontent.com/haproxytech/client-native/master/Makefile | grep SWAGGER_VERSION -m 1 | awk -F"=" '{print $2}')
- wget -q "https://github.com/go-swagger/go-swagger/releases/download/${SWAGGER_VERSION}/swagger_linux_amd64" -O /usr/local/bin/swagger && chmod +x /usr/local/bin/swagger
- make generate-native
- test -z "$(git diff 2> /dev/null)" || exit "Specification is not generated, issue \`make generate\` and commit the result"
- test -z "$(git ls-files --others --exclude-standard 2> /dev/null)" || exit "Specification generation created untracked files, cannot proceed"
diff-spec-parent:
stage: lint
needs: [pipelines-check]
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [""]
tags:
- go
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push'
script:
- make generate-parent-aliases
- test -z "$(git diff 2> /dev/null)" || exit "Parent aliases are not generated, issue \`make generate-parent-aliases\` and commit the result"
- test -z "$(git ls-files --others --exclude-standard 2> /dev/null)" || exit "Parent aliases created untracked files, cannot proceed"
after_script:
- |
if [ "$CI_JOB_STATUS" == "success" ]; then
junit-report add --status=ok --message="parent aliases diff is clean"
else
junit-report add --status=failed --message="parent aliases not generated" --description="$(git diff)"
fi
artifacts:
when: on_failure
paths:
- junit-report.xml
reports:
junit: junit-report.xml
golangci-lint:
stage: lint
needs: [pipelines-check]
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [""]
tags:
- go
script:
- make lint
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push'
after_script:
- |
if [ "$CI_JOB_STATUS" == "success" ]; then
junit-report add --status=ok --message="linting passed successfully"
else
junit-report add --status=failed --message="linting failed"
fi
artifacts:
when: on_failure
paths:
- build
- junit-report.xml
reports:
junit: junit-report.xml
gofumpt:
stage: lint
needs: [pipelines-check]
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push'
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [""]
tags:
- go
script:
- make gofumpt
- test -z "$(git diff 2> /dev/null)" || exit 'Go code not formatted, issue \`make gofumpt\` and commit the result'
after_script:
- |
if [ "$CI_JOB_STATUS" == "success" ]; then
junit-report add --status=ok --message="format check passed successfully"
else
junit-report add --status=failed --message="go code not formatted" --description="$(git diff)"
fi
artifacts:
when: on_failure
paths:
- junit-report.xml
reports:
junit: junit-report.xml
commit-policy:
stage: lint
needs: [pipelines-check]
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
image:
name: $CI_REGISTRY_GO/commit-check:latest
entrypoint: [""]
tags:
- go
script:
- /check
artifacts:
when: on_failure
paths:
- junit-report.xml
reports:
junit: junit-report.xml
check-dependencies:
stage: lint
allow_failure: true
needs: [pipelines-check]
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [""]
tags:
- go
script:
- |
git fetch origin ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
# skip check if all go.mod changes are from Gopher Bot
BOT_COMMITS=$(git log --author="noreply-gopher@haproxy.com" --format='%H' origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}..HEAD -- go.mod || true)
ALL_COMMITS=$(git log --format='%H' origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}..HEAD -- go.mod || true)
if [ -n "$ALL_COMMITS" ] && [ "$BOT_COMMITS" = "$ALL_COMMITS" ]; then
echo "All go.mod changes are from Gopher Bot, skipping."
junit-report add --status=ok --file="go.mod" --message="go.mod changes from Gopher Bot, skipped" --description="go.mod dependency check skipped"
exit 0
fi
NEW_DEPS=$(git diff origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}...HEAD -- go.mod \
| grep -E '^\+\s' \
| grep -v '^\+\+\+' \
| grep -v '^\+\s*\/\/' \
|| true)
if [ -n "$NEW_DEPS" ]; then
echo "New dependencies detected in go.mod:"
echo "$NEW_DEPS"
junit-report add --status=failed --file="go.mod" --message="new dependencies added to go.mod" --description="$(printf "The following dependencies were added:\n\n%s" "$NEW_DEPS")"
exit 1
else
echo "No new dependencies added to go.mod."
junit-report add --status=ok --file="go.mod" --message="no new dependencies added to go.mod" --description="go.mod dependency check passed"
fi
artifacts:
when: on_failure
paths:
- junit-report.xml
reports:
junit: junit-report.xml
check-committer:
stage: lint
allow_failure: true
needs: [pipelines-check]
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [ "" ]
tags:
- go
script:
- |
git fetch origin ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
BAD_EMAILS=""
for COMMIT in $(git log --format='%H' origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}..HEAD); do
EMAIL=$(git log -1 --format='%ae' "$COMMIT")
MSG=$(git log -1 --format='%s' "$COMMIT")
case "$EMAIL" in
*@haproxy.com) ;;
*)
SHORT=$(echo "$COMMIT" | cut -c1-8)
BAD_EMAILS="${BAD_EMAILS}${SHORT} ${MSG} (${EMAIL})\n"
junit-report add --status=failed --file="$EMAIL" --message="$EMAIL: $MSG" --description="$(printf "committer email not @haproxy.com\n\n%s\n%s" "$MSG" "$EMAIL")"
;;
esac
done
CO_AUTHORED=""
ASSISTED=""
SIGNED_OFF=""
for COMMIT in $(git log --format='%H' origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}..HEAD); do
BODY=$(git log -1 --format='%b' "$COMMIT")
MSG=$(git log -1 --format='%s' "$COMMIT")
MATCHED=$(echo "$BODY" | grep -i 'Co-authored-by' || true)
if [ -n "$MATCHED" ]; then
SHORT=$(echo "$COMMIT" | cut -c1-8)
CO_AUTHORED="${CO_AUTHORED}${SHORT} ${MSG}\n$(echo "$MATCHED" | sed 's/^/ /')\n"
junit-report add --status=failed --file="co-authored-by" --message="$MSG" --description="$(printf "commit contains Co-authored-by trailer\n\n%s\n%s" "$MSG" "$MATCHED")"
fi
MATCHED=$(echo "$BODY" | grep -i 'Assisted-by' || true)
if [ -n "$MATCHED" ]; then
SHORT=$(echo "$COMMIT" | cut -c1-8)
ASSISTED="${ASSISTED}${SHORT} ${MSG}\n$(echo "$MATCHED" | sed 's/^/ /')\n"
junit-report add --status=failed --file="assisted-by" --message="$MSG" --description="$(printf "commit contains Assisted-by trailer\n\n%s\n%s" "$MSG" "$MATCHED")"
fi
MATCHED=$(echo "$BODY" | grep -i 'Signed-off-by' || true)
if [ -n "$MATCHED" ]; then
SHORT=$(echo "$COMMIT" | cut -c1-8)
SIGNED_OFF="${SIGNED_OFF}${SHORT} ${MSG}\n$(echo "$MATCHED" | sed 's/^/ /')\n"
junit-report add --status=failed --file="signed-off-by" --message="$MSG" --description="$(printf "commit contains Signed-off-by trailer\n\n%s\n%s" "$MSG" "$MATCHED")"
fi
done
FAILED=""
if [ -n "$BAD_EMAILS" ]; then
echo "The following committer emails are not @haproxy.com:"
printf "$BAD_EMAILS"
FAILED=1
else
echo "All committer emails end with @haproxy.com."
junit-report add --status=ok --file=committer-email --description="all emails valid" --message="All committer emails end with @haproxy.com."
fi
if [ -n "$CO_AUTHORED" ]; then
echo "The following commits contain Co-authored-by:"
printf "$CO_AUTHORED"
FAILED=1
else
echo "No commits contain Co-authored-by."
junit-report add --status=ok --file=co-authored-by --description="no co-authored-by found" --message="No commits contain Co-authored-by."
fi
if [ -n "$ASSISTED" ]; then
echo "The following commits contain Assisted-by:"
printf "$ASSISTED"
FAILED=1
else
echo "No commits contain Assisted-by."
junit-report add --status=ok --file=assisted-by --description="no assisted-by found" --message="No commits contain Assisted-by."
fi
if [ -n "$SIGNED_OFF" ]; then
echo "The following commits contain Signed-off-by:"
printf "$SIGNED_OFF"
FAILED=1
else
echo "No commits contain Signed-off-by."
junit-report add --status=ok --file=signed-off-by --description="no signed-off-by found" --message="No commits contain Signed-off-by."
fi
if [ -n "$FAILED" ]; then
exit 1
fi
artifacts:
when: on_failure
paths:
- junit-report.xml
reports:
junit: junit-report.xml
build:
stage: build
needs: []
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [""]
tags:
- go
script:
- go env
- go mod verify
- make build
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push'
after_script:
- |
if [ "$CI_JOB_STATUS" == "success" ]; then
junit-report add --status=ok --message="build passed successfully"
else
junit-report add --status=failed --message="build failed"
fi
artifacts:
paths:
- build
reports:
junit: junit-report.xml
test:
stage: test
needs: [pipelines-check]
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [ "" ]
tags:
- go
before_script:
- go env -w "GONOSUMDB=gitlab.int.haproxy.com/*" "GOPROXY=http://goproxy.int.haproxy.com"
script:
- go test ./...
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: "$CI_PROJECT_NAMESPACE == 'haproxy-controller' && $CI_PIPELINE_SOURCE == 'push'"
after_script:
- |
if [ "$CI_JOB_STATUS" == "success" ]; then
junit-report add --status=ok --message="tests passed successfully"
else
junit-report add --status=failed --message="tests failed"
fi
artifacts:
when: on_failure
paths:
- junit-report.xml
reports:
junit: junit-report.xml
.e2e:
stage: e2e
needs: [pipelines-check, build]
artifacts:
paths:
- build
- e2e/logs/*
when: on_failure
image:
name: $CI_REGISTRY_GO/docker:$DOCKER_VERSION
entrypoint: [""]
services:
- name: $CI_REGISTRY_GO/docker:$DOCKER_VERSION-dind
alias: docker
variables:
LOCAL_IP_ADDRESS: docker
tags:
- go
before_script:
- apk add git bash curl jq git
- git clone https://github.com/bats-core/bats-core.git && cd bats-core && git checkout $BATS_VERSION && ./install.sh /usr/local && cd ..
- docker login -u='$app' -p $CI_REGISTRY_TOKEN $CI_REGISTRY_GO
script:
- bash -x ./e2e/run.bash
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push'
govulncheck:
stage: checks
needs: []
image:
name: $CI_REGISTRY_GO/golang:latest-alpine
entrypoint: [ "" ]
rules:
- if: $CI_PIPELINE_SOURCE == 'schedule' && $SCHEDULE_TYPE == 'daily'
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
changes:
- go.mod
- if: "$CI_PROJECT_NAMESPACE == 'haproxy-controller' && $CI_PIPELINE_SOURCE == 'push'"
changes:
- go.mod
tags:
- go
script:
- go install golang.org/x/vuln/cmd/govulncheck@latest
- govulncheck -version
- go mod tidy
- go run cmd/govulncheck-report/main.go
after_script:
- |
if [ "$CI_JOB_STATUS" == "success" ]; then
junit-report add --status=ok --message="govulncheck passed"
else
junit-report add --status=failed --message="govulncheck found vulnerabilities"
fi
artifacts:
when: on_failure
paths:
- junit-report.xml
reports:
junit: junit-report.xml
HAProxy_3.4:
extends: .e2e
parallel:
matrix:
- TESTPART: ["1/4", "2/4", "3/4", "4/4"]
HAPROXY_VERSION: "3.4"