2019-08-15 02:43:09 +08:00
|
|
|
#!/usr/bin/env groovy
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 - 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-11-02 23:39:02 +08:00
|
|
|
library "canvas-builds-library@${env.CANVAS_BUILDS_REFSPEC}"
|
2019-12-21 04:37:59 +08:00
|
|
|
|
2020-11-21 02:58:35 +08:00
|
|
|
def COFFEE_NODE_COUNT = 4
|
2020-07-10 06:43:39 +08:00
|
|
|
def DEFAULT_NODE_COUNT = 1
|
|
|
|
def JSG_NODE_COUNT = 3
|
|
|
|
|
2020-04-16 23:02:58 +08:00
|
|
|
def copyFiles(dockerName, dockerPath, hostPath) {
|
|
|
|
sh "mkdir -vp ./$hostPath"
|
|
|
|
sh "docker cp \$(docker ps -qa -f name=$dockerName):/usr/src/app/$dockerPath ./$hostPath"
|
2020-01-07 03:31:16 +08:00
|
|
|
}
|
|
|
|
|
2020-07-10 06:43:39 +08:00
|
|
|
def makeKarmaStage(group, ciNode, ciTotal) {
|
|
|
|
return {
|
|
|
|
withEnv([
|
|
|
|
"CI_NODE_INDEX=${ciNode}",
|
|
|
|
"CI_NODE_TOTAL=${ciTotal}",
|
|
|
|
"CONTAINER_NAME=tests-karma-${group}-${ciNode}",
|
|
|
|
"JSPEC_GROUP=${group}"
|
|
|
|
]) {
|
|
|
|
try {
|
|
|
|
credentials.withSentryCredentials {
|
|
|
|
sh 'build/new-jenkins/js/tests-karma.sh'
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
copyFiles(env.CONTAINER_NAME, 'coverage-js', "./tmp/${env.CONTAINER_NAME}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 04:06:21 +08:00
|
|
|
def cleanupFn() {
|
2021-01-07 01:11:17 +08:00
|
|
|
timeout(time: 2) {
|
2021-04-14 00:48:18 +08:00
|
|
|
if(env.TEST_SUITE != 'upload') {
|
|
|
|
archiveArtifacts artifacts: 'tmp/**/*.xml'
|
|
|
|
junit "tmp/**/*.xml"
|
2020-10-06 00:22:13 +08:00
|
|
|
}
|
2020-07-23 04:06:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-05 05:17:51 +08:00
|
|
|
def getLoadAllLocales() {
|
|
|
|
return configuration.isChangeMerged() ? 1 : 0
|
|
|
|
}
|
|
|
|
|
2019-08-15 02:43:09 +08:00
|
|
|
pipeline {
|
2020-07-23 04:06:21 +08:00
|
|
|
agent none
|
2021-01-07 01:11:17 +08:00
|
|
|
options {
|
|
|
|
ansiColor('xterm')
|
|
|
|
timeout(time: 20)
|
|
|
|
timestamps()
|
|
|
|
}
|
2019-08-15 02:43:09 +08:00
|
|
|
|
|
|
|
environment {
|
2020-11-18 01:08:45 +08:00
|
|
|
COMPOSE_DOCKER_CLI_BUILD=1
|
|
|
|
COMPOSE_FILE = 'docker-compose.new-jenkins-js.yml'
|
|
|
|
DOCKER_BUILDKIT=1
|
2020-06-17 02:23:25 +08:00
|
|
|
FORCE_FAILURE = configuration.forceFailureJS()
|
2020-11-18 01:08:45 +08:00
|
|
|
PROGRESS_NO_TRUNC=1
|
2021-02-05 05:17:51 +08:00
|
|
|
RAILS_LOAD_ALL_LOCALES = getLoadAllLocales()
|
2020-01-07 03:31:16 +08:00
|
|
|
SENTRY_URL="https://sentry.insops.net"
|
|
|
|
SENTRY_ORG="instructure"
|
|
|
|
SENTRY_PROJECT="master-javascript-build"
|
2019-08-15 02:43:09 +08:00
|
|
|
}
|
2020-02-15 06:02:23 +08:00
|
|
|
|
2019-08-15 02:43:09 +08:00
|
|
|
stages {
|
2020-07-23 04:06:21 +08:00
|
|
|
stage('Environment') {
|
2020-01-18 04:22:04 +08:00
|
|
|
steps {
|
2020-07-23 04:06:21 +08:00
|
|
|
script {
|
2021-04-20 07:26:13 +08:00
|
|
|
extendedStage('Runner').nodeRequirements(label: 'canvas-docker').obeysAllowStages(false).execute {
|
2020-07-23 04:06:21 +08:00
|
|
|
stage('Setup') {
|
2021-01-07 01:11:17 +08:00
|
|
|
timeout(time: 3) {
|
2020-07-23 04:06:21 +08:00
|
|
|
sh 'rm -vrf ./tmp/*'
|
2020-11-18 02:50:39 +08:00
|
|
|
def refspecToCheckout = env.GERRIT_PROJECT == "canvas-lms" ? env.JENKINSFILE_REFSPEC : env.CANVAS_LMS_REFSPEC
|
2020-11-02 23:35:53 +08:00
|
|
|
|
2020-11-03 23:22:18 +08:00
|
|
|
checkoutRepo("canvas-lms", refspecToCheckout, 1)
|
2021-02-08 23:36:36 +08:00
|
|
|
|
2021-03-19 00:37:08 +08:00
|
|
|
credentials.withStarlordCredentials { ->
|
|
|
|
sh "./build/new-jenkins/docker-with-flakey-network-protection.sh pull $KARMA_RUNNER_IMAGE"
|
|
|
|
}
|
2020-01-17 03:16:25 +08:00
|
|
|
}
|
2020-01-09 06:30:07 +08:00
|
|
|
}
|
2020-01-18 04:22:04 +08:00
|
|
|
|
2021-04-14 04:56:28 +08:00
|
|
|
def postBuildHandler = [
|
2021-04-15 06:53:28 +08:00
|
|
|
onStageEnded: { _ ->
|
2021-04-14 04:56:28 +08:00
|
|
|
cleanupFn()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2021-04-15 06:16:39 +08:00
|
|
|
extendedStage('Run Tests').hooks(postBuildHandler).obeysAllowStages(false).execute {
|
2021-01-07 01:11:17 +08:00
|
|
|
timeout(time: 10) {
|
2020-07-23 04:06:21 +08:00
|
|
|
script {
|
|
|
|
def tests = [:]
|
|
|
|
|
2021-02-02 01:47:21 +08:00
|
|
|
if(env.TEST_SUITE == 'jest') {
|
2020-07-23 04:06:21 +08:00
|
|
|
tests['Jest'] = {
|
|
|
|
withEnv(['CONTAINER_NAME=tests-jest']) {
|
|
|
|
try {
|
|
|
|
credentials.withSentryCredentials {
|
|
|
|
sh 'build/new-jenkins/js/tests-jest.sh'
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
copyFiles(env.CONTAINER_NAME, 'coverage-js', "./tmp/${env.CONTAINER_NAME}")
|
|
|
|
}
|
|
|
|
}
|
2020-07-02 21:15:23 +08:00
|
|
|
}
|
2020-11-21 02:58:35 +08:00
|
|
|
} else if(env.TEST_SUITE == 'coffee') {
|
|
|
|
for(int i = 0; i < COFFEE_NODE_COUNT; i++) {
|
|
|
|
tests["Karma - Spec Group - coffee${i}"] = makeKarmaStage('coffee', i, COFFEE_NODE_COUNT)
|
|
|
|
}
|
|
|
|
} else if(env.TEST_SUITE == 'karma') {
|
2020-07-23 04:06:21 +08:00
|
|
|
tests['Packages'] = {
|
|
|
|
withEnv(['CONTAINER_NAME=tests-packages']) {
|
|
|
|
try {
|
|
|
|
credentials.withSentryCredentials {
|
|
|
|
sh 'build/new-jenkins/js/tests-packages.sh'
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
copyFiles(env.CONTAINER_NAME, 'packages', "./tmp/${env.CONTAINER_NAME}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 05:43:54 +08:00
|
|
|
|
2020-07-23 04:06:21 +08:00
|
|
|
for(int i = 0; i < JSG_NODE_COUNT; i++) {
|
|
|
|
tests["Karma - Spec Group - jsg${i}"] = makeKarmaStage('jsg', i, JSG_NODE_COUNT)
|
|
|
|
}
|
|
|
|
|
|
|
|
['jsa', 'jsh'].each { group ->
|
|
|
|
tests["Karma - Spec Group - ${group}"] = makeKarmaStage(group, 0, DEFAULT_NODE_COUNT)
|
|
|
|
}
|
|
|
|
}
|
2020-07-10 06:43:39 +08:00
|
|
|
|
2020-07-23 04:06:21 +08:00
|
|
|
parallel(tests)
|
|
|
|
}
|
2020-01-17 03:16:25 +08:00
|
|
|
}
|
2020-01-09 06:30:07 +08:00
|
|
|
}
|
2020-04-16 23:02:58 +08:00
|
|
|
}
|
2019-08-30 06:03:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-15 02:43:09 +08:00
|
|
|
}
|
2020-01-16 22:55:14 +08:00
|
|
|
}
|