forked from mendersoftware/mendertesting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci-check-golang-unittests-v2.yml
More file actions
89 lines (85 loc) · 2.56 KB
/
Copy path.gitlab-ci-check-golang-unittests-v2.yml
File metadata and controls
89 lines (85 loc) · 2.56 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
# .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:
# CODECOV_TOKEN: Token from codecov.io for this repository
#
stages:
- test
- publish
test:unit:
variables:
MONGO_VERSION: "8.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"
GO_VERSION: "1.26"
# Override to a prebuilt image (e.g. base-mender-go) to skip runtime installs.
GO_TEST_IMAGE: "golang:${GO_VERSION}"
tags:
- k8s
stage: test
needs: []
retry:
max: 2
when:
- runner_system_failure
- stuck_or_timeout_failure
except:
- /^saas-[a-zA-Z0-9.]+$/
image: ${GO_TEST_IMAGE}
services:
- "mongo:${MONGO_VERSION}"
before_script:
- !reference [.qa-common-network-go-retry, before_script]
- !reference [.qa-common-network-apt-retry, 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 the test runner unless it is baked into the image (e.g. base-mender-go)
- if ! command -v gotestsum >/dev/null 2>&1; then go install gotest.tools/gotestsum@v1.13.0; fi
# Run tests -> JUnit report + coverage profile (gotestsum sets the exit code)
- gotestsum --junitfile test-results.xml --format testname -- ./... -covermode=atomic -coverprofile=coverage.txt
artifacts:
expire_in: 2w
paths:
- coverage.txt
reports:
junit: test-results.xml
when: always
publish:unittests:
tags:
- k8s-small
stage: publish
allow_failure: true
retry:
max: 2
when:
- runner_system_failure
- stuck_or_timeout_failure
rules:
- if: '$CI_COMMIT_TAG =~ /^saas-[a-zA-Z0-9.]+$/'
when: never
- when: on_success
image: registry.gitlab.com/northern.tech/mender/mender-test-containers/codecov:master
dependencies:
- test:unit
script:
- codecov upload-process
--fail-on-error
--git-service github
--slug mendersoftware/${CI_PROJECT_NAME}
--sha ${CI_COMMIT_SHA}
--pr $(echo "${CI_COMMIT_BRANCH}" | sed 's/^pr_//')
--file coverage.txt
--flag unittests