-
Notifications
You must be signed in to change notification settings - Fork 8
/
Jenkinsfile
141 lines (127 loc) · 5.7 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
pipeline {
agent {
docker {
label 'main'
image 'storjlabs/ci:latest'
alwaysPull true
args '-u root:root --cap-add SYS_PTRACE -v "/tmp/gomod":/go/pkg/mod'
}
}
options {
timeout(time: 26, unit: 'MINUTES')
}
environment {
NPM_CONFIG_CACHE = '/tmp/npm/cache'
COVERDIR = "${ env.BRANCH_NAME != 'main' ? '' : env.WORKSPACE + '/.build/cover' }"
COCKROACH_MEMPROF_INTERVAL=0
}
stages {
stage('Build') {
steps {
checkout scm
sh 'git restore-mtime'
sh 'mkdir -p .build $COVERDIR'
sh 'service postgresql start'
// make a backup of the mod file, because sometimes they get modified by tools
// this allows to lint the unmodified files
sh 'cp go.mod .build/go.mod.orig'
sh 'cp testsuite/go.mod .build/testsuite.go.mod.orig'
dir(".build") {
sh 'cockroach start-single-node --insecure --store=\'/tmp/crdb\' --listen-addr=localhost:26257 --http-addr=localhost:8080 --cache 512MiB --max-sql-memory 512MiB --background'
}
}
}
stage('Verification') {
parallel {
stage('Lint') {
steps {
sh 'check-copyright'
sh 'check-large-files'
sh 'check-imports ./...'
sh 'check-peer-constraints'
sh 'check-atomic-align ./...'
sh 'check-monkit ./...'
sh 'check-errs ./...'
sh 'go vet ./...'
dir('testsuite') {
sh 'go vet ./...'
sh 'check-mod-tidy -mod ../.build/testsuite.go.mod.orig'
}
sh 'staticcheck ./...'
sh 'golangci-lint --config /go/ci/.golangci.yml -j=2 run'
sh 'check-mod-tidy -mod .build/go.mod.orig'
sh 'go-licenses check ./...'
sh 'make format-c-check'
}
}
stage('Build') {
steps {
sh 'make build'
}
}
stage('Tests') {
environment {
COVERFLAGS = "${ env.COVERDIR ? '-coverprofile=' + env.COVERDIR + '/tests.coverprofile -coverpkg=./...' : ''}"
}
steps {
sh 'go test -parallel 4 -p 6 -vet=off $COVERFLAGS -timeout 20m -json -race ./... | tee .build/tests.json | xunit -out .build/tests.xml'
// TODO enable this later
// sh 'check-clean-directory'
}
post {
always {
sh script: 'cat .build/tests.json | tparse -all -slow 100', returnStatus: true
archiveArtifacts artifacts: '.build/tests.json'
junit '.build/tests.xml'
}
}
}
stage('Testsuite') {
environment {
STORJ_TEST_COCKROACH = 'cockroach://root@localhost:26257/testcockroach?sslmode=disable'
STORJ_TEST_POSTGRES = 'postgres://postgres@localhost/teststorj?sslmode=disable'
COVERFLAGS = "${ env.COVERDIR ? '-coverprofile=' + env.COVERDIR + '/testsuite.coverprofile -coverpkg=../...' : ''}"
}
steps {
sh 'cockroach sql --insecure --host=localhost:26257 -e \'create database testcockroach;\''
sh 'psql -U postgres -c \'create database teststorj;\''
sh 'use-ports -from 1024 -to 10000 &'
dir('testsuite'){
sh 'go test -parallel 4 -p 6 -vet=off $COVERFLAGS -timeout 20m -json -race ./... 2>&1 | tee ../.build/testsuite.json | xunit -out ../.build/testsuite.xml'
}
// TODO enable this later
// sh 'check-clean-directory'
}
post {
always {
sh script: 'cat .build/testsuite.json | tparse -all -slow 100', returnStatus: true
archiveArtifacts artifacts: '.build/testsuite.json'
junit '.build/testsuite.xml'
}
}
}
}
}
stage('Coverage') {
when { not { environment name: 'COVERDIR', value: '' } }
steps {
script {
def cleaned = []
findFiles(glob: '.build/cover/**.coverprofile').each { file ->
sh script: "filter-cover-profile < ${file.path} > ${file.path}.clean", returnStatus: true
cleaned.push(file.path + '.clean')
}
sh script: "gocov convert ${cleaned.join(' ')} > .build/cover/combined.json", returnStatus: true
sh script: "gocov-xml < .build/cover/combined.json > .build/cover/combined.xml", returnStatus: true
cobertura coberturaReportFile: ".build/cover/combined.xml"
}
}
}
}
post {
always {
sh "chmod -R 777 ." // ensure Jenkins agent can delete the working directory
deleteDir()
}
}
}