2019-11-25 14:06:34 +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}"
|
2020-06-17 02:23:25 +08:00
|
|
|
|
2020-02-20 03:50:26 +08:00
|
|
|
@groovy.transform.Field
|
2020-09-23 03:30:29 +08:00
|
|
|
def partitions = []
|
2020-03-07 05:49:29 +08:00
|
|
|
@groovy.transform.Field
|
|
|
|
def changed_tests = ''
|
2020-03-24 00:51:38 +08:00
|
|
|
@groovy.transform.Field
|
2020-09-29 23:46:14 +08:00
|
|
|
def fsc_status = null
|
2021-01-07 01:11:17 +08:00
|
|
|
def FSC_TIMEOUT = configuration.getInteger('fsc-timeout', 20)
|
2020-02-20 03:50:26 +08:00
|
|
|
|
2020-06-10 01:49:59 +08:00
|
|
|
def isPlugin() {
|
|
|
|
return env.GERRIT_PROJECT == "canvas-lms" ? "0" : "1"
|
|
|
|
}
|
|
|
|
|
|
|
|
def getDockerWorkDir() {
|
|
|
|
return env.GERRIT_PROJECT == "canvas-lms" ? "/usr/src/app" : "/usr/src/app/gems/plugins/${env.GERRIT_PROJECT}"
|
|
|
|
}
|
|
|
|
|
|
|
|
def getLocalWorkDir() {
|
|
|
|
return env.GERRIT_PROJECT == "canvas-lms" ? "." : "gems/plugins/${env.GERRIT_PROJECT}"
|
|
|
|
}
|
|
|
|
|
2020-09-24 03:42:51 +08:00
|
|
|
def setupNode() {
|
|
|
|
cleanAndSetup()
|
|
|
|
sh 'rm -vrf ./tmp'
|
2020-11-02 23:35:53 +08:00
|
|
|
def refspecToCheckout = env.GERRIT_PROJECT == "canvas-lms" ? env.GERRIT_REFSPEC : env.CANVAS_LMS_REFSPEC
|
|
|
|
|
2020-11-03 23:22:18 +08:00
|
|
|
checkoutRepo("canvas-lms", refspecToCheckout, 2)
|
2020-11-02 23:35:53 +08:00
|
|
|
|
2020-06-10 01:49:59 +08:00
|
|
|
if (env.IS_PLUGIN == "1") {
|
|
|
|
dir(env.LOCAL_WORKDIR) {
|
2020-11-03 23:22:18 +08:00
|
|
|
checkoutRepo(GERRIT_PROJECT, env.GERRIT_REFSPEC, 2)
|
2020-06-10 01:49:59 +08:00
|
|
|
}
|
|
|
|
}
|
2020-09-22 09:51:36 +08:00
|
|
|
|
|
|
|
sh 'build/new-jenkins/docker-compose-pull.sh'
|
|
|
|
sh 'build/new-jenkins/docker-compose-build-up.sh'
|
2020-09-24 03:42:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
def computeTestCount() {
|
2020-02-20 03:50:26 +08:00
|
|
|
// oops, probably should have added an easier way to _count_ tests...
|
2020-06-10 01:49:59 +08:00
|
|
|
sh 'rm -vrf $LOCAL_WORKDIR/tmp'
|
|
|
|
sh 'mkdir -v $LOCAL_WORKDIR/tmp'
|
|
|
|
sh 'chmod -vv 777 $LOCAL_WORKDIR/tmp'
|
2020-09-24 23:40:09 +08:00
|
|
|
|
|
|
|
if (FORCE_FAILURE == '1') {
|
|
|
|
changed_tests = 'spec/force_failure_spec.rb'
|
|
|
|
} else {
|
|
|
|
sh '''
|
|
|
|
docker run --volume $(pwd)/$LOCAL_WORKDIR/.git:$DOCKER_WORKDIR/.git \
|
|
|
|
--volume $(pwd)/$LOCAL_WORKDIR/tmp:$DOCKER_WORKDIR/tmp \
|
|
|
|
--env FSC_IGNORE_FILES \
|
|
|
|
-w=$DOCKER_WORKDIR \
|
|
|
|
$PATCHSET_TAG \
|
|
|
|
bash -c "flakey_spec_catcher --use-parent --dry-run-quiet > $DOCKER_WORKDIR/tmp/test_list"
|
|
|
|
'''
|
|
|
|
|
|
|
|
changed_tests = readFile("$env.LOCAL_WORKDIR/tmp/test_list").trim()
|
|
|
|
}
|
|
|
|
|
2020-03-07 05:49:29 +08:00
|
|
|
echo "raw result from catcher: \n====\n$changed_tests\n===="
|
2020-09-23 03:30:29 +08:00
|
|
|
|
2020-09-25 01:39:02 +08:00
|
|
|
if(changed_tests.length() == 0) {
|
|
|
|
echo "no tests found to execute"
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-30 00:01:18 +08:00
|
|
|
def changed_tests_arr = changed_tests.split('\n').collect {
|
|
|
|
"$DOCKER_WORKDIR/$it"
|
|
|
|
}
|
|
|
|
|
2020-09-22 09:51:36 +08:00
|
|
|
sh """
|
|
|
|
docker-compose --project-name canvas-lms0 run --rm -v \$(pwd)/\$LOCAL_WORKDIR/tmp:\$DOCKER_WORKDIR/tmp \
|
|
|
|
canvas \
|
2020-09-30 03:39:21 +08:00
|
|
|
bash -c "bundle exec rspec --dry-run ${changed_tests_arr.join(' ')} --require ./build/new-jenkins/rspec_location.rb --format RSpecLocationFormatter --out ${env.DOCKER_WORKDIR}/tmp/test_list_split"
|
2020-09-22 09:51:36 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
changed_tests = readFile("$env.LOCAL_WORKDIR/tmp/test_list_split").trim()
|
2020-09-30 03:39:21 +08:00
|
|
|
changed_tests_arr = changed_tests.split('\n')
|
2020-09-22 09:51:36 +08:00
|
|
|
|
2020-09-30 03:39:21 +08:00
|
|
|
echo "raw result from splitter: \n====\n$changed_tests\n===="
|
2020-09-30 00:01:18 +08:00
|
|
|
|
2020-10-07 08:31:43 +08:00
|
|
|
if(changed_tests.length() == 0) {
|
|
|
|
echo "no tests found to execute"
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-30 00:01:18 +08:00
|
|
|
def test_count = changed_tests_arr.size()
|
|
|
|
def weighted_values = changed_tests_arr.collect {
|
2020-09-30 03:39:21 +08:00
|
|
|
it.contains('selenium') ? env.SELENIUM_RATIO.toInteger() : 1
|
2020-09-28 23:23:32 +08:00
|
|
|
}
|
2020-09-23 03:30:29 +08:00
|
|
|
|
2020-09-28 23:23:32 +08:00
|
|
|
def distributed_factor = env.TESTS_PER_NODE.toInteger()
|
2020-02-20 03:50:26 +08:00
|
|
|
|
2020-09-28 23:23:32 +08:00
|
|
|
def i = 0
|
|
|
|
def cur_partition = []
|
|
|
|
def cur_weight = 0
|
|
|
|
|
|
|
|
while(i < test_count) {
|
|
|
|
cur_partition.add(changed_tests_arr[i])
|
|
|
|
cur_weight += weighted_values[i]
|
2020-09-23 03:30:29 +08:00
|
|
|
|
2020-09-28 23:23:32 +08:00
|
|
|
if(cur_weight >= distributed_factor) {
|
|
|
|
partitions.add(cur_partition)
|
2020-09-23 03:30:29 +08:00
|
|
|
|
2020-09-28 23:23:32 +08:00
|
|
|
cur_partition = []
|
|
|
|
cur_weight = 0
|
|
|
|
}
|
2020-09-23 03:30:29 +08:00
|
|
|
|
2020-09-28 23:23:32 +08:00
|
|
|
i++
|
2020-02-20 03:50:26 +08:00
|
|
|
}
|
2020-09-23 03:30:29 +08:00
|
|
|
|
2020-09-30 00:01:18 +08:00
|
|
|
if(cur_partition.size() > 0) {
|
|
|
|
partitions.add(cur_partition)
|
|
|
|
}
|
|
|
|
|
2020-09-23 03:30:29 +08:00
|
|
|
echo "expected nodes to run on for $test_count tests: ${partitions.size()}"
|
2020-02-20 03:50:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
def executeFlakeySpecCatcher(prefix = 'main') {
|
2020-03-10 23:14:44 +08:00
|
|
|
sh 'rm -vrf tmp'
|
2020-02-20 03:50:26 +08:00
|
|
|
try {
|
2021-01-07 01:11:17 +08:00
|
|
|
sh 'seq 0 $((DOCKER_PROCESSES-1)) | parallel "build/new-jenkins/rspec-flakey-spec-catcher.sh {}"'
|
2020-09-29 23:46:14 +08:00
|
|
|
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
|
|
|
|
if (e.causes[0] instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) {
|
2021-01-07 01:11:17 +08:00
|
|
|
echo "Failing the build due to timeouts"
|
2020-09-29 23:46:14 +08:00
|
|
|
fsc_status = 'timeout'
|
2021-01-07 01:11:17 +08:00
|
|
|
throw e
|
2020-09-29 23:46:14 +08:00
|
|
|
} else if(e.causes[0] instanceof jenkins.model.CauseOfInterruption.UserInterruption) {
|
|
|
|
echo "Build aborted"
|
|
|
|
fsc_status = 'aborted'
|
|
|
|
} else {
|
|
|
|
throw e
|
2020-03-24 00:51:38 +08:00
|
|
|
}
|
2020-09-29 23:46:14 +08:00
|
|
|
} finally {
|
2020-11-05 02:17:43 +08:00
|
|
|
sh "build/new-jenkins/docker-copy-files.sh /usr/src/app/tmp/fsc.out tmp canvas_ --allow-error --clean-dir"
|
|
|
|
archiveArtifacts artifacts: "tmp/**/fsc.out", allowEmptyArchive: true
|
2020-02-20 03:50:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 05:49:29 +08:00
|
|
|
def sendSlack(success) {
|
2020-09-29 23:46:14 +08:00
|
|
|
def color = fsc_status == 'timeout' ? 'warning' : (success ? 'good' : 'danger')
|
2020-03-07 05:49:29 +08:00
|
|
|
def jobInfo = "<https://gerrit.instructure.com/$env.GERRIT_CHANGE_NUMBER|Gerrit> | <$env.BUILD_URL|Jenkins>"
|
|
|
|
def message = "$jobInfo\n$changed_tests"
|
2020-09-29 23:46:14 +08:00
|
|
|
if (fsc_status == 'timeout') {
|
2020-03-24 00:51:38 +08:00
|
|
|
message = "Timeout Occurred!\n$message"
|
|
|
|
}
|
2020-03-07 05:49:29 +08:00
|
|
|
slackSend channel: '#flakey_spec_catcher_noisy', color: color, message: message
|
|
|
|
}
|
|
|
|
|
2020-07-27 21:22:42 +08:00
|
|
|
def cleanupFn(status) {
|
|
|
|
try {
|
2020-09-29 23:46:14 +08:00
|
|
|
if(fsc_status != 'aborted') {
|
|
|
|
sendSlack(status == 'SUCCESS')
|
|
|
|
}
|
2020-07-27 21:22:42 +08:00
|
|
|
} finally {
|
|
|
|
sh 'rm -vrf ./tmp/'
|
2021-01-12 07:33:50 +08:00
|
|
|
libraryScript.execute 'bash/docker-cleanup.sh --allow-failure'
|
2020-07-27 21:22:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-25 14:06:34 +08:00
|
|
|
pipeline {
|
2020-07-27 21:22:42 +08:00
|
|
|
agent none
|
2020-05-09 02:23:07 +08:00
|
|
|
options {
|
|
|
|
ansiColor('xterm')
|
2021-01-07 01:11:17 +08:00
|
|
|
timeout(time: FSC_TIMEOUT)
|
2020-05-09 02:23:07 +08:00
|
|
|
timestamps()
|
|
|
|
}
|
2019-11-25 14:06:34 +08:00
|
|
|
|
|
|
|
environment {
|
2020-06-10 01:49:59 +08:00
|
|
|
GERRIT_PORT = '29418'
|
|
|
|
GERRIT_URL = "$GERRIT_HOST:$GERRIT_PORT"
|
2020-07-21 22:16:43 +08:00
|
|
|
BUILD_REGISTRY_FQDN = configuration.buildRegistryFQDN()
|
2019-11-25 14:06:34 +08:00
|
|
|
COMPOSE_FILE = 'docker-compose.new-jenkins.yml:docker-compose.new-jenkins-selenium.yml:docker-compose.new-jenkins-flakey-spec-catcher.yml'
|
2020-06-10 01:49:59 +08:00
|
|
|
IS_PLUGIN = isPlugin()
|
|
|
|
DOCKER_WORKDIR = getDockerWorkDir()
|
|
|
|
LOCAL_WORKDIR = getLocalWorkDir()
|
2020-06-17 02:23:25 +08:00
|
|
|
FORCE_FAILURE = configuration.forceFailureFSC()
|
2020-04-15 04:30:00 +08:00
|
|
|
// fsc errors when running specs from gems.
|
|
|
|
// until we figure out how to run them, we should ignore them
|
2020-12-10 02:54:10 +08:00
|
|
|
FSC_IGNORE_FILES = "gems/.*/spec/,spec/contracts/"
|
2020-04-30 07:18:24 +08:00
|
|
|
POSTGRES_PASSWORD = 'sekret'
|
2020-12-15 00:53:00 +08:00
|
|
|
SELENIUM_VERSION = "3.141.59-20201119"
|
2020-09-28 23:23:32 +08:00
|
|
|
|
|
|
|
// Targeting 10 minutes / node, each node runs DOCKER_PROCESSES threads and
|
|
|
|
// repeats each test FSC_REPEAT_FACTOR times.
|
|
|
|
// Assumption: non-selenium tests take 500ms / test
|
|
|
|
// Assumption: selenium tests take 500ms * SELENIUM_RATIO / test
|
|
|
|
DOCKER_PROCESSES = 3
|
|
|
|
FSC_REPEAT_FACTOR = 10
|
2020-12-16 02:54:36 +08:00
|
|
|
MAX_NODES = configuration.getString('fsc-max-nodes', '10')
|
2020-09-28 23:23:32 +08:00
|
|
|
SELENIUM_RATIO = 20
|
|
|
|
TESTS_PER_NODE = 200
|
2019-11-25 14:06:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stages {
|
2020-07-27 21:22:42 +08:00
|
|
|
stage('Environment') {
|
2019-11-25 14:06:34 +08:00
|
|
|
steps {
|
2020-02-20 03:50:26 +08:00
|
|
|
script {
|
2020-07-27 21:22:42 +08:00
|
|
|
protectedNode('canvas-docker', { status -> cleanupFn(status) }) {
|
|
|
|
stage('Setup') {
|
2020-09-24 03:42:51 +08:00
|
|
|
setupNode()
|
2020-07-27 21:22:42 +08:00
|
|
|
}
|
2019-11-25 14:06:34 +08:00
|
|
|
|
2020-09-24 23:40:09 +08:00
|
|
|
stage("Compute Build Distribution") {
|
|
|
|
computeTestCount()
|
2020-07-27 21:22:42 +08:00
|
|
|
}
|
|
|
|
|
2020-09-24 23:40:09 +08:00
|
|
|
stage("Run Flakey Spec Catcher") {
|
|
|
|
if(partitions.size() == 0) {
|
2020-09-28 23:23:32 +08:00
|
|
|
return
|
|
|
|
} else if(partitions.size() >= env.MAX_NODES.toInteger()) {
|
|
|
|
error "Refusing to use more than ${env.MAX_NODES} nodes to catch flakey specs. Consider breaking this change into smaller pieces."
|
|
|
|
|
2020-09-24 23:40:09 +08:00
|
|
|
return
|
2020-09-25 04:12:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
def stages = [:]
|
|
|
|
|
|
|
|
stages["flakey set 00"] = {
|
2020-09-24 23:40:09 +08:00
|
|
|
withEnv(["FSC_TESTS=${partitions[0].join(',')}"]) {
|
2020-07-27 21:22:42 +08:00
|
|
|
executeFlakeySpecCatcher()
|
|
|
|
}
|
2020-09-25 04:12:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 1; i < partitions.size(); i++) {
|
|
|
|
// make sure to create a new index variable so this value gets
|
|
|
|
// captured by the lambda
|
|
|
|
def index = i
|
|
|
|
def node_number = (index).toString().padLeft(2, '0')
|
|
|
|
|
|
|
|
stages["flakey set $node_number"] = {
|
|
|
|
protectedNode('canvas-docker') {
|
|
|
|
withEnv(["FSC_TESTS=${partitions[index].join(',')}"]) {
|
|
|
|
try {
|
|
|
|
setupNode()
|
|
|
|
executeFlakeySpecCatcher("node$node_number")
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
sh 'rm -vrf ./tmp'
|
2021-01-12 07:33:50 +08:00
|
|
|
libraryScript.execute 'bash/docker-cleanup.sh --allow-failure'
|
2020-02-20 03:50:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-25 04:12:44 +08:00
|
|
|
parallel(stages)
|
2020-02-20 03:50:26 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-25 14:06:34 +08:00
|
|
|
}
|
|
|
|
}
|
2020-02-13 01:14:18 +08:00
|
|
|
}
|
2019-11-25 14:06:34 +08:00
|
|
|
}
|
|
|
|
}
|