forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.coverage-js
206 lines (171 loc) · 7.56 KB
/
Jenkinsfile.coverage-js
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
#!/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')
def setupNode() {
sh 'rm -vrf ./tmp'
checkout scm
distribution.stashBuildScripts()
}
def getKarmaRunnerImage() {
KARMA_RUNNER_PREFIX = configuration.buildRegistryPath('karma-runner')
if (env.GERRIT_REFSPEC.contains('master')) {
IMAGE_CACHE_UNIQUE_SCOPE = "${env.GERRIT_BRANCH}"
return "$KARMA_RUNNER_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
} else {
TAG_SUFFIX = imageTag.suffix()
IMAGE_CACHE_UNIQUE_SCOPE = "${imageTagVersion()}-$TAG_SUFFIX"
return "$KARMA_RUNNER_PREFIX:$IMAGE_CACHE_UNIQUE_SCOPE"
}
}
def getPatchsetTag() {
(env.GERRIT_REFSPEC.contains('master')) ? "${configuration.buildRegistryPath()}:${env.GERRIT_BRANCH}" : imageTag.patchset()
}
def generateSkippedSpecsReport() {
try {
copyArtifacts(
filter: 'js-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_js.json skipped_specs.json"
sh """
docker run -v \$(pwd)/\$LOCAL_WORKDIR/js-results/:/tmp/js-results \
-v \$(pwd)/\$LOCAL_WORKDIR/skipped_specs.json:/usr/src/app/skipped_specs.json \
--name skipped-spec-collator $PATCHSET_TAG bash -c \
"bundle install; ruby build/new-jenkins/skipped_specs_manager.rb js"
"""
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_js.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-js failed to generate skipped specs report!>"
}
}
def sendSkippedSpecsSlackReport() {
def jsSkippedSpecs = sh(script: "grep -o 'file_indicator' skipped_specs.json | wc -l", returnStdout: true).trim() ?: '0'
def color = 'danger'
if(jsSkippedSpecs.toInteger() < 100) {
color = 'good'
} else if (jsSkippedSpecs.toInteger() < 300) {
color = 'warning'
}
def jobInfo = "<$env.BUILD_URL|JS>"
slackSend channel: '#canvas-test-stats', color: color, message: "$jsSkippedSpecs 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-js.yml'
FORCE_FAILURE = commitMessageFlag('force-failure-js').asBooleanInteger()
KARMA_RUNNER_IMAGE = getKarmaRunnerImage()
PATCHSET_TAG = getPatchsetTag()
BUILD_REGISTRY_FQDN = configuration.buildRegistryFQDN()
COMPOSE_DOCKER_CLI_BUILD = 1
DOCKER_BUILDKIT = 1
PROGRESS_NO_TRUNC = 1
}
stages {
stage('Environment') {
steps {
script {
def rspecNodeRequirements = [label: 'canvas-docker']
def postBuildHandler = [
onNodeReleasing: { stageName, stageConfig, result ->
buildSummaryReport.saveRunManifest()
copyArtifacts(
filter: 'coverage-report-js/**',
optional: false,
projectName: env.JOB_NAME,
selector: specific(env.BUILD_NUMBER),
)
withEnv(['COMPOSE_FILE=docker-compose.new-jenkins.yml']) {
sh """
docker run --interactive \
--volume \$(pwd)/coverage-report-js:/usr/src/app/tmp/coverage-report-js \
--name coverage-collator \
$KARMA_RUNNER_IMAGE bash -c "./build/new-jenkins/js/coverage-report.sh"
"""
sh 'docker cp coverage-collator:/usr/src/app/report-html coverage-report-js/report-html'
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: './coverage-report-js/report-html',
reportFiles: 'index.html',
reportName: 'Coverage Report'
]
uploadCoverage([
uploadSource: '/coverage-report-js/report-html',
uploadDest: 'canvas-lms-js/coverage'
])
}
if (env.GERRIT_EVENT_TYPE != 'comment-added') {
generateSkippedSpecsReport()
}
}
]
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 jsStages = [:]
// increate node count for coverage
jsStage.JEST_NODE_COUNT = 4
for (int i = 0; i < jsStage.JEST_NODE_COUNT; i++) {
String index = i
extendedStage("Runner - Jest ${i}").nodeRequirements(label: 'canvas-docker', podTemplate: jsStage.jestNodeRequirementsTemplate(index)).obeysAllowStages(false).timeout(10).queue(jsStages) {
def tests = [:]
callableWithDelegate(jsStage.queueJestDistribution(index))(tests)
parallel(tests)
}
}
extendedStage('Runner - Coffee').nodeRequirements(label: 'canvas-docker', podTemplate: jsStage.coffeeNodeRequirementsTemplate()).obeysAllowStages(false).timeout(10).queue(jsStages) {
def tests = [:]
callableWithDelegate(jsStage.queueCoffeeDistribution())(tests)
parallel(tests)
}
extendedStage('Runner - Karma').nodeRequirements(label: 'canvas-docker', podTemplate: jsStage.karmaNodeRequirementsTemplate()).obeysAllowStages(false).timeout(10).queue(jsStages) {
def tests = [:]
callableWithDelegate(jsStage.queueKarmaDistribution())(tests)
parallel(tests)
}
parallel(jsStages)
} //parallel tests
} //builder
} //runner
} //script
} //steps
} //environment
} //stages
} //pipeline