-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path.gitlab-ci-check-golang-unittests-v2.yml
94 lines (90 loc) · 2.86 KB
/
.gitlab-ci-check-golang-unittests-v2.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
# .gitlab-ci-check-golang-unittests-v2.yml
#
# This gitlab-ci template runs unit tests and publishes code coverage
# from a Go repository
#
# Add it to the project in hand through Gitlab's include functionality
#
# include:
# - project: 'Northern.tech/Mender/mendertesting'
# file: '.gitlab-ci-check-golang-unittests-v2.yml'
#
# Requires the following variables set in the project CI/CD settings:
# COVERALLS_TOKEN: Token from coveralls.io for this repository
#
stages:
- test
- publish
test:unit:
variables:
MONGO_VERSION: "6.0"
GIT_STRATEGY: clone # clone entire repo instead of reusing workspace
GIT_DEPTH: 0 # avoid shallow clone, this test requires full git history
TEST_MONGO_URL: "mongodb://mongo"
tags:
- mender-qa-worker-generic-light
stage: test
needs: []
except:
- /^saas-[a-zA-Z0-9.]+$/
image: golang:1.23.4
services:
- "mongo:${MONGO_VERSION}"
before_script:
# Install compile dependencies
- if [ -f deb-requirements.txt ]; then
- apt-get -qq update && apt-get install -yq $(cat deb-requirements.txt)
- fi
script:
# Install JUnit test reporting formatter
- go install github.com/jstemmer/[email protected]
# Run tests
- go test ./... -v -covermode=atomic -coverprofile=coverage.txt 2>&1 |
tee /dev/stderr |
go-junit-report > test-results.xml || exit $?
artifacts:
expire_in: 2w
paths:
- coverage.txt
reports:
junit: test-results.xml
when: always
publish:unittests:
tags:
- mender-qa-worker-generic-light
stage: publish
except:
- /^saas-[a-zA-Z0-9.]+$/
image: golang:1.23.4
dependencies:
- test:unit
before_script:
# Install dependencies
- go install github.com/mattn/[email protected]
# Coveralls env variables:
# According to https://docs.coveralls.io/supported-ci-services
# we should set CI_NAME, CI_BUILD_NUMBER, etc. But according
# to goveralls source code (https://github.com/mattn/goveralls)
# many of these are not supported. Set CI_BRANCH,
# and pass few others as command line arguments.
# See also https://docs.coveralls.io/api-reference
- export CI_BRANCH=${CI_COMMIT_BRANCH}
script:
- goveralls
-coverprofile coverage.txt
-service gitlab-ci
-jobid $CI_PIPELINE_ID
-flagname unittests
-parallel
coveralls:finish-build:
tags:
- mender-qa-worker-generic-light
stage: .post
# See https://docs.coveralls.io/parallel-build-webhook
variables:
COVERALLS_WEBHOOK_URL: "https://coveralls.io/webhook"
COVERALLS_RERUN_BUILD_URL: "https://coveralls.io/rerun_build"
image: curlimages/curl-base
script:
- 'curl -k ${COVERALLS_WEBHOOK_URL}?repo_token=${COVERALLS_TOKEN} -d "payload[build_num]=$CI_PIPELINE_ID&payload[status]=done"'
- 'curl -k "${COVERALLS_RERUN_BUILD_URL}?repo_token=${COVERALLS_TOKEN}&build_num=${CI_PIPELINE_ID}"'