forked from vegaprotocol/vegawallet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
187 lines (181 loc) · 7.53 KB
/
Jenkinsfile
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* properties of scmVars (example):
- GIT_BRANCH:PR-40
- GIT_COMMIT:05a1c6fbe7d1ff87cfc40a011a63db574edad7e6
- GIT_PREVIOUS_COMMIT:5d02b46fdb653f789e799ff6ad304baccc32cbf9
- GIT_PREVIOUS_SUCCESSFUL_COMMIT:5d02b46fdb653f789e799ff6ad304baccc32cbf9
- GIT_URL:https://github.com/vegaprotocol/go-wallet.git
*/
def scmVars = null
def version = 'UNKNOWN'
def versionHash = 'UNKNOWN'
pipeline {
agent { label 'general' }
environment {
CGO_ENABLED = 0
GO111MODULE = 'on'
SLACK_MESSAGE = "Go Wallet CI » <${RUN_DISPLAY_URL}|Jenkins ${BRANCH_NAME} Job>${ env.CHANGE_URL ? " » <${CHANGE_URL}|GitHub PR #${CHANGE_ID}>" : '' }"
}
stages {
stage('Config') {
steps {
cleanWs()
sh 'printenv'
echo "${params}"
}
}
stage('Git clone') {
options { retry(3) }
steps {
script {
scmVars = checkout(scm)
versionHash = sh (returnStdout: true, script: "echo \"${scmVars.GIT_COMMIT}\"|cut -b1-8").trim()
version = sh (returnStdout: true, script: "git describe --tags 2>/dev/null || echo ${versionHash}").trim()
}
}
}
stage('Download dependencies') {
options { retry(3) }
steps {
sh 'go mod download -x'
}
}
stage('Compile') {
environment {
LDFLAGS = "-X code.vegaprotocol.io/go-wallet/version.Version=\"${version}\" -X code.vegaprotocol.io/go-wallet/version.VersionHash=\"${versionHash}\""
}
failFast true
parallel {
stage('Linux build') {
environment {
GOOS = 'linux'
GOARCH = 'amd64'
OUTPUT = './build/vegawallet-linux-amd64'
}
options { retry(3) }
steps {
sh label: 'Compile', script: '''
go build -v -o "${OUTPUT}" -ldflags "${LDFLAGS}"
'''
sh label: 'Sanity check', script: '''
file ${OUTPUT}
${OUTPUT} version --output json
'''
}
}
stage('MacOS build') {
environment {
GOOS = 'darwin'
GOARCH = 'amd64'
OUTPUT = './build/vegawallet-darwin-amd64'
}
options { retry(3) }
steps {
sh label: 'Compile', script: '''
go build -v -o "${OUTPUT}" -ldflags "${LDFLAGS}"
'''
sh label: 'Sanity check', script: '''
file ${OUTPUT}
'''
}
}
stage('Windows build') {
environment {
GOOS = 'windows'
GOARCH = 'amd64'
OUTPUT = './build/vegawallet-windows-amd64'
}
options { retry(3) }
steps {
sh label: 'Compile', script: '''
go build -v -o "${OUTPUT}" -ldflags "${LDFLAGS}"
'''
sh label: 'Sanity check', script: '''
file ${OUTPUT}
'''
}
}
}
}
stage('Tests') {
parallel {
stage('unit tests') {
options { retry(3) }
steps {
sh 'go test -v ./... 2>&1 | tee unit-test-results.txt && cat unit-test-results.txt | go-junit-report > unit-test-report.xml'
junit checksName: 'Unit Tests', testResults: 'unit-test-report.xml'
}
}
stage('unit tests with race') {
environment {
CGO_ENABLED = 1
}
options { retry(3) }
steps {
sh 'go test -v -race ./... 2>&1 | tee unit-test-race-results.txt && cat unit-test-race-results.txt | go-junit-report > unit-test-race-report.xml'
junit checksName: 'Unit Tests with Race', testResults: 'unit-test-race-report.xml'
}
}
stage('70+ linters [TODO improve]') {
steps {
sh '''#!/bin/bash -e
golangci-lint run -v \
--allow-parallel-runners \
--config .golangci.toml \
--enable-all \
--color always \
--disable paralleltest \
--disable wrapcheck \
--disable thelper \
--disable tagliatelle \
--disable noctx \
--disable nlreturn \
--disable ifshort \
--disable gomnd \
--disable goerr113 \
--disable gochecknoglobals \
--disable forcetypeassert \
--disable exhaustivestruct \
--disable errorlint \
--disable cyclop \
--disable bodyclose \
--disable wsl \
--disable prealloc \
--disable nestif \
--disable misspell \
--disable maligned \
--disable lll \
--disable golint \
--disable goimports \
--disable gofumpt \
--disable whitespace \
--disable revive \
--disable gofmt \
--disable godot \
--disable gocritic \
--disable goconst \
--disable gochecknoinits \
--disable gci \
--disable funlen \
--disable stylecheck \
--disable gocognit \
--disable forbidigo \
--disable dupl
'''
}
}
}
}
}
post {
success {
retry(3) {
slackSend(channel: "#tradingcore-notify", color: "good", message: ":white_check_mark: ${SLACK_MESSAGE} (${currentBuild.durationString.minus(' and counting')})")
}
}
unsuccessful {
retry(3) {
slackSend(channel: "#tradingcore-notify", color: "danger", message: ":red_circle: *${currentBuild.result}* ${SLACK_MESSAGE} (${currentBuild.durationString.minus(' and counting')})")
}
}
}
}