forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.coverage
282 lines (246 loc) · 12.4 KB
/
Jenkinsfile.coverage
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env groovy
/*
* Copyright (C) 2022 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
library "canvas-builds-library@${env.CANVAS_BUILDS_REFSPEC}"
loadLocalLibrary('local-lib', 'build/new-jenkins/library')
@groovy.transform.Field
def rspecqNodeTotal = 23
@groovy.transform.Field
def rspecNodeTotal = 27
def setupNode() {
sh 'rm -vrf ./tmp'
checkout scm
distribution.stashBuildScripts()
credentials.withStarlordCredentials { ->
sh(script: 'build/new-jenkins/docker-compose-pull.sh', label: 'Pull Images')
}
sh(script: 'build/new-jenkins/docker-compose-build-up.sh', label: 'Start Containers')
}
def getPatchsetTag() {
(env.GERRIT_REFSPEC.contains('master')) ? "${configuration.buildRegistryPath()}:${env.GERRIT_BRANCH}" : imageTag.patchset()
}
def redisUrl() {
return "redis://${TEST_QUEUE_HOST}:6379"
}
def generateSkippedSpecsReport() {
try{
copyArtifacts(
filter: 'tmp/rspec_results/**',
optional: false,
projectName: env.JOB_NAME,
selector: specific(env.BUILD_NUMBER),
)
withEnv(['COMPOSE_FILE=docker-compose.new-jenkins.yml']) {
withCredentials([usernamePassword(credentialsId: 'INSENG_CANVAS_CI_AWS_ACCESS', usernameVariable: 'INSENG_AWS_ACCESS_KEY_ID', passwordVariable: 'INSENG_AWS_SECRET_ACCESS_KEY')]) {
def awsCreds = "AWS_DEFAULT_REGION=us-west-2 AWS_ACCESS_KEY_ID=${INSENG_AWS_ACCESS_KEY_ID} AWS_SECRET_ACCESS_KEY=${INSENG_AWS_SECRET_ACCESS_KEY}"
sh "$awsCreds aws s3 cp s3://instructure-canvas-ci/skipped_specs_ruby.json skipped_specs.json"
sh """
docker-compose run -v \$(pwd)/\$LOCAL_WORKDIR/tmp/rspec_results/:/tmp/rspec_results \
-v \$(pwd)/\$LOCAL_WORKDIR/skipped_specs.json/:/usr/src/app/skipped_specs.json \
--name skipped-spec-collator canvas bash -c \
"bundle install; ruby build/new-jenkins/skipped_specs_manager.rb ruby"
"""
sh 'docker cp skipped-spec-collator:/tmp/skipped_specs.json skipped_specs.json'
sh "$awsCreds aws s3 cp skipped_specs.json s3://instructure-canvas-ci/skipped_specs_ruby.json"
}
sendSkippedSpecsSlackReport()
archiveArtifacts allowEmptyArchive: true, artifacts: 'skipped_specs.json'
}
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
slackSend channel: '#canvas-test-stats', color: 'danger', message: "<$env.BUILD_URL|coverage-ruby failed to generate skipped specs report!>"
}
}
def sendSkippedSpecsSlackReport() {
def rubySkippedSpecs = sh(script: "grep -o 'file_indicator' skipped_specs.json | wc -l", returnStdout: true).trim() ?: '0'
def color = 'danger'
if(rubySkippedSpecs.toInteger() < 100) {
color = 'good'
} else if (rubySkippedSpecs.toInteger() < 300) {
color = 'warning'
}
def jobInfo = "<$env.BUILD_URL|Ruby>"
slackSend channel: '#canvas-test-stats', color: color, message: "$rubySkippedSpecs skipped specs in $jobInfo! "
}
pipeline {
agent none
options {
ansiColor('xterm')
timeout(60)
timestamps()
}
environment {
COMPOSE_FILE = 'docker-compose.new-jenkins.yml:docker-compose.new-jenkins-selenium.yml'
FORCE_FAILURE = "${configuration.isForceFailureSelenium() ? '1' : ''}"
RERUNS_RETRY = "${configuration.getInteger('rspecq-max-requeues')}"
RSPECQ_FILE_SPLIT_THRESHOLD = "${configuration.fileSplitThreshold()}"
RSPECQ_MAX_REQUEUES = "${configuration.getInteger('rspecq-max-requeues')}"
SELENIUM_TEST_PATTERN = '^./(spec|gems/plugins/.*/spec_canvas)/selenium'
TEST_PATTERN = '^./(spec|gems/plugins/.*/spec_canvas)/'
EXCLUDE_TESTS = '.*/(selenium|contracts)'
RSPECQ_UPDATE_TIMINGS = "${env.GERRIT_EVENT_TYPE == 'change-merged' ? '1' : '0'}"
ENABLE_AXE_SELENIUM = "${env.ENABLE_AXE_SELENIUM}"
POSTGRES_PASSWORD = 'sekret'
RSPECQ_REDIS_URL = redisUrl()
PATCHSET_TAG = getPatchsetTag()
CASSANDRA_PREFIX = configuration.buildRegistryPath('cassandra-migrations')
DYNAMODB_PREFIX = configuration.buildRegistryPath('dynamodb-migrations')
POSTGRES_PREFIX = configuration.buildRegistryPath('postgres-migrations')
IMAGE_CACHE_MERGE_SCOPE = configuration.gerritBranchSanitized()
RSPEC_PROCESSES = 6
CASSANDRA_IMAGE_TAG = "$CASSANDRA_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-$RSPEC_PROCESSES"
DYNAMODB_IMAGE_TAG = "$DYNAMODB_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-$RSPEC_PROCESSES"
POSTGRES_IMAGE_TAG = "$POSTGRES_PREFIX:$IMAGE_CACHE_MERGE_SCOPE-$RSPEC_PROCESSES"
COVERAGE_LOCATION = "${env.COVERAGE_TYPE == 'ruby-selenium' ? 'canvas__master__selenium--coverage/coverage' : (env.COVERAGE_TYPE == 'ruby-nonselenium' ? 'canvas__master__rspec--coverage/coverage' : 'canvas-lms-rspec/coverage')}"
}
stages {
stage('Environment') {
steps {
script {
def rspecNodeRequirements = [label: 'canvas-docker']
def postBuildHandler = [
onNodeReleasing: { stageName, stageConfig, result ->
buildSummaryReport.saveRunManifest()
copyArtifacts(
filter: 'tmp/coverage/**',
optional: false,
projectName: env.JOB_NAME,
selector: specific(env.BUILD_NUMBER),
)
withEnv(['COMPOSE_FILE=docker-compose.new-jenkins.yml']) {
sh """
docker-compose run -v \$(pwd)/\$LOCAL_WORKDIR/tmp/coverage/:/tmp/coverage \
--name coverage-collator canvas bash -c \
"bundle install; bundle exec rake coverage:report['/tmp/coverage/canvas__*/**']"
"""
sh 'docker cp coverage-collator:/usr/src/app/coverage/ coverage'
archiveArtifacts allowEmptyArchive: true, artifacts: 'coverage/**'
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: './coverage',
reportFiles: 'index.html',
reportName: 'Ruby Coverage Report'
]
uploadCoverage([
uploadSource: '/coverage',
uploadDest: env.COVERAGE_LOCATION
])
}
if (env.GERRIT_EVENT_TYPE != 'comment-added' && env.COVERAGE_TYPE == 'ruby-total') {
generateSkippedSpecsReport()
}
}
]
def postStageHandler = [
onStageEnded: { stageName, stageConfig, result ->
buildSummaryReport.setStageTimings(stageName, stageConfig.timingValues())
}
]
extendedStage('Runner').obeysAllowStages(false).execute {
extendedStage('Builder').hooks(postBuildHandler).obeysAllowStages(false).nodeRequirements(rspecNodeRequirements).execute {
stage('Setup') {
setupNode()
}
extendedStage('Parallel Run Tests').obeysAllowStages(false).execute { stageConfig, buildConfig ->
def rspecqStages = [:]
if (env.COVERAGE_TYPE != 'ruby-selenium') {
extendedStage('RSpecQ Reporter for Rspec').timeout(30).queue(rspecqStages) {
try {
sh(script: "docker run -e SENTRY_DSN -e RSPECQ_REDIS_URL -t $PATCHSET_TAG bundle exec rspecq \
--build=${JOB_NAME}_build${BUILD_NUMBER}_rspec \
--queue-wait-timeout 240 \
--redis-url $RSPECQ_REDIS_URL \
--report", label: 'Reporter')
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
if (e.causes[0] instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) {
/* groovylint-disable-next-line GStringExpressionWithinString, SpaceInsideParentheses */
sh '''#!/bin/bash
ids=( $(docker ps -aq --filter "name=canvas_") )
for i in "${ids[@]}"
do
docker exec $i bash -c "cat /usr/src/app/log/cmd_output/*.log"
done
'''
}
throw e
}
}
}
if (env.COVERAGE_TYPE != 'ruby-nonselenium') {
extendedStage('RSpecQ Reporter for Selenium').timeout(30).queue(rspecqStages) {
try {
sh(script: "docker run -e SENTRY_DSN -e RSPECQ_REDIS_URL -t $PATCHSET_TAG bundle exec rspecq \
--build=${JOB_NAME}_build${BUILD_NUMBER}_selenium \
--queue-wait-timeout 120 \
--redis-url $RSPECQ_REDIS_URL \
--report", label: 'Reporter')
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
if (e.causes[0] instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) {
/* groovylint-disable-next-line GStringExpressionWithinString, SpaceInsideParentheses */
sh '''#!/bin/bash
ids=($(docker ps -aq --filter "name=canvas_"))
for i in "${ids[@]}"
do
docker exec $i bash -c "cat /usr/src/app/log/cmd_output/*.log"
done
'''
}
throw e
}
}
extendedStage('RSpecQ Selenium Set 00')
.envVars(['CI_NODE_INDEX=0',
"BUILD_NAME=${env.JOB_NAME}_build${env.BUILD_NUMBER}_selenium",
"TEST_PATTERN=${env.SELENIUM_TEST_PATTERN}",
'EXCLUDE_TESTS=.*/(selenium/performance|instfs/selenium|contracts)'])
.hooks(postStageHandler + [onNodeAcquired: { rspecStage.setupNode() }, onNodeReleasing: { rspecStage.tearDownNode('selenium') }])
.timeout(30)
.queue(rspecqStages) { rspecStage.runRspecqSuite() }
for (int i = 1; i < rspecqNodeTotal; i++) {
def index = i
extendedStage("RSpecQ Selenium Set ${(index).toString().padLeft(2, '0')}")
.envVars(["CI_NODE_INDEX=$index",
"BUILD_NAME=${env.JOB_NAME}_build${env.BUILD_NUMBER}_selenium",
"TEST_PATTERN=${env.SELENIUM_TEST_PATTERN}",
'EXCLUDE_TESTS=.*/(selenium/performance|instfs/selenium|contracts)'])
.hooks(postStageHandler + [onNodeAcquired: { rspecStage.setupNode() }, onNodeReleasing: { rspecStage.tearDownNode('selenium') }])
.nodeRequirements(rspecNodeRequirements)
.timeout(30)
.queue(rspecqStages) { rspecStage.runRspecqSuite() }
}
}
if (env.COVERAGE_TYPE != 'ruby-selenium') {
rspecNodeTotal.times { index ->
extendedStage("RSpecQ Rspec Set ${(index + 1).toString().padLeft(2, '0')}")
.envVars(["CI_NODE_INDEX=$index", "BUILD_NAME=${env.JOB_NAME}_build${env.BUILD_NUMBER}_rspec"])
.hooks(postStageHandler + [onNodeAcquired: { rspecStage.setupNode() }, onNodeReleasing: { rspecStage.tearDownNode('rspec') }])
.nodeRequirements(rspecNodeRequirements)
.timeout(30)
.queue(rspecqStages) { rspecStage.runRspecqSuite() }
}
}
parallel(rspecqStages)
} //rspecQ
} //builder
} //runner
} //script
} //steps
} //environment
} //stages
} //pipeline