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.yml
More file actions
120 lines (112 loc) · 4.18 KB
/
Copy path.gitlab-ci-check-golang-unittests.yml
File metadata and controls
120 lines (112 loc) · 4.18 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
# .gitlab-ci-check-golang-unittests.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.yml'
#
# If the repo has some compile time dependencies, the template expect to
# exist a deb-requirements.txt file with the Debian OS required packages
#
# The template uses latest Mender supported golang version.
# To override the version to use, append to your .gitlab-ci.yml:
# test:unit:
# image: golang:1.11.4
#
# Requires the following variables set in the project CI/CD settings:
# CODECOV_TOKEN: Token from codecov.io for this repository
#
# By default, it installs MongoDB version 4.4 for Debian buster. You can
# specify the Debian release name for the upstream APT repository and
# the MongoDB version overriding the variables below:
#
# test:unit:
# variables:
# MONGODB_DEBIAN_RELEASE: "stretch"
# MONGODB_VERSION: "3.6"
#
stages:
- test
- publish
test:unit:
tags:
- k8s
stage: test
needs: []
except:
- /^saas-[a-zA-Z0-9.]+$/
image: golang:1.23.4
services:
- mongo:8.0
variables:
GIT_STRATEGY: clone # clone entire repo instead of reusing workspace
GIT_DEPTH: 0 # avoid shallow clone, this test requires full git history
MONGODB_DEBIAN_RELEASE: "bookworm"
MONGODB_VERSION: "8.0"
TEST_MONGO_URL: "mongodb://mongo"
before_script:
- !reference [.qa-common-network-go-retry, before_script]
- !reference [.qa-common-network-apt-retry, before_script]
# Install JUnit test reporting formatter
- go install github.com/jstemmer/go-junit-report@v1.0.0
# mongodb-org package needs systemd, this circumnavigates the issue providing a fake systemctl command
- ln -s /bin/true /usr/sbin/systemctl
# Install mongodb for the tests that use it locally
- wget -qO - https://www.mongodb.org/static/pgp/server-${MONGODB_VERSION}.asc | apt-key add -
- echo "deb http://repo.mongodb.org/apt/debian ${MONGODB_DEBIAN_RELEASE}/mongodb-org/${MONGODB_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGODB_VERSION}.list
- apt-get -qq update
- apt-get install -qy mongodb-org
# Install compile dependencies
- if [ -f deb-requirements.txt ]; then
- apt install -yq $(cat deb-requirements.txt)
- fi
# Rename the branch we're on, so that it's not in the way for the
# subsequent fetch. It's ok if this fails, it just means we're not on any
# branch.
- git branch -m temp-branch || true
# Git trick: Fetch directly into our local branches instead of remote
# branches.
- git fetch -f origin 'refs/heads/*:refs/heads/*'
# Get last remaining tags, if any.
- git fetch --tags origin
# Prepare GOPATH
- mkdir -p /go/src/github.com/mendersoftware
- cp -r ${CI_PROJECT_DIR} /go/src/github.com/mendersoftware/${CI_PROJECT_NAME}
- cd /go/src/github.com/mendersoftware/${CI_PROJECT_NAME}
script:
- go list ./... | grep -v vendor | xargs -n1 -I {} go test -v -covermode=atomic -coverprofile=../../../{}/coverage.txt {} 2>&1 | tee /dev/stderr | go-junit-report > ${CI_PROJECT_DIR}/test-results.xml || exit $?
- mkdir -p tests/unit-coverage && find . -name 'coverage.txt' -exec cp --parents {} ./tests/unit-coverage \;
- tar -cvf ${CI_PROJECT_DIR}/unit-coverage.tar tests/unit-coverage
artifacts:
expire_in: 2w
paths:
- unit-coverage.tar
reports:
junit: test-results.xml
when: always
publish:unittests:
tags:
- k8s-small
stage: publish
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
allow_failure: true
dependencies:
- test:unit
script:
- tar -xvf unit-coverage.tar
- 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_//')
$(find tests/unit-coverage -name 'coverage.txt' | sed 's/^/--file /')
--flag unittests