-
Notifications
You must be signed in to change notification settings - Fork 18
/
.gitlab-ci-check-golang-static.yml
67 lines (64 loc) · 2.03 KB
/
.gitlab-ci-check-golang-static.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
# .gitlab-ci-check-golang-static.yml
#
# NOTE: This template is deprecated, use .gitlab-ci-check-golang-lint.yml
#
# This gitlab-ci template performs the following static checks on Go code:
# - check format with go fmt
# - check code health with go vet
# - check complexity with gocyclo
#
# Add it to the project in hand through Gitlab's include functionality
#
# include:
# - project: 'Northern.tech/Mender/mendertesting'
# file: '.gitlab-ci-check-golang-static.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
#
stages:
- test
test:static:
tags:
- mender-qa-worker-generic-light
stage: test
needs: []
except:
- /^saas-[a-zA-Z0-9.]+$/
image: golang:1.20
before_script:
# Install cyclomatic dependency analysis tool
- GO111MODULE=off go get -u github.com/fzipp/gocyclo/...
# Install compile dependencies
- if [ -f deb-requirements.txt ]; then
apt-get -qq update &&
apt install -yq $(cat deb-requirements.txt);
fi
# Prepare GOPATH for the build
- 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:
# Test if code was formatted with 'go fmt'
# Command will format code and return modified files
# fail if any have been modified.
- if [ -n "$(go fmt ./...)" ]; then echo 'Code is not formatted with "go fmt"'; false; fi
# Perform static code analysys
- go vet `go list ./... | grep -v vendor`
# Fail builds when the cyclomatic complexity reaches 20 or more
- gocyclo -over 20 `find . -iname '*.go' | grep -v 'vendor' | grep -v '_test.go'`
test:govendor-check:
tags:
- mender-qa-worker-generic-light
stage: test
needs: []
rules:
- exists:
- vendor
variables:
GOLANG_VERSION: "1.20"
image: golang:${GOLANG_VERSION}
script:
- go mod tidy
- go mod vendor
- git diff --exit-code