-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
93 lines (79 loc) · 2.63 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
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
variables:
GO_IMAGE: "docker.io/library/golang"
GO_VERSION: "1.22.3-bookworm"
.go-cache:
variables:
GOPATH: ${CI_PROJECT_DIR}/.go
before_script:
- mkdir -p .go
cache:
## share cache across the same branch
key: ${CI_COMMIT_REF_SLUG}
policy: pull-push
paths:
- .go/pkg/mod/
test and coverage:
stage: test
retry: 2
coverage: '/coverage: (\d+.\d+)% of statements/'
extends:
- .go-cache
image: $GO_IMAGE:$GO_VERSION
script:
## generate files
- export PATH=$PATH:$GOPATH/bin
- |
## install dependencies
export CUR=$(pwd)
export G_OLD=$GOOS
export GOOS=linux
cd /
go install github.com/alvaroloes/enumer@latest
# run tests and generate Coverage report
go install github.com/jstemmer/go-junit-report/v2@latest
go install github.com/boumenot/gocover-cobertura@latest
## go back
cd "${CUR}"
export GOOS=$G_OLD
- |
echo "+ Path..: $PATH";
echo "+ GoPath: $GOPATH";
ls -lah $GOPATH/bin;
export COVDATA="${CI_PROJECT_DIR}/covdata";
export TEST_LOG="${CI_PROJECT_DIR}/unit_test.log";
mkdir -p ${COVDATA};
## Coverage Data #1: tests directly in the module (units tests, examples, ...)
go test -v \
-cover \
-covermode=atomic \
-coverpkg=go.l0nax.org/typact \
./... -args -test.gocoverdir="${COVDATA}" 2>&1 | tee -a "${TEST_LOG}";
## Coverage Data #2: unit tests/ integration tests which we placed in another module
cd ./testing/option/;
go test -v \
-cover \
-covermode=atomic \
-coverpkg=go.l0nax.org/typact \
./... -args -test.gocoverdir="${COVDATA}" 2>&1 | tee -a "${TEST_LOG}";
cd ${CI_PROJECT_DIR};
## Merge Coverage Data
cd ${CI_PROJECT_DIR};
echo "++++ Finished collecting coverage data: merging";
mkdir -p ./coverage;
go tool covdata merge -i="${COVDATA}" -o ./coverage;
# NOTE: Just to log the total percent
go tool covdata percent -i ./coverage;
go tool covdata textfmt -i ./coverage -o ./coverage.txt;
rm -rf ./coverage ${COVDATA};
## Now we can finally generate our reports
echo "++++ Finished merging and processing coverage data: generating reports";
gocover-cobertura < ./coverage.txt > coverage.xml;
cat "${TEST_LOG}" | go-junit-report -set-exit-code > unit-tests.xml
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: unit-tests.xml