Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 54 additions & 29 deletions Jenkinsfile-SmokeTest
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,21 @@ properties([

// Generates a custom route file that contains the next version of Angular to test against
def generateNPMVersionRouteFile(Map args = new LinkedHashMap()) {
// @angular/core's version is the one baked into the angular app
def nextVersion = sh(script: "npm view @angular/core@${args.npm_tag} version", returnStdout: true).trim()

echo "Target framework version: ${nextVersion}"

def routeFileContent = readJSON text: """
[{
"request": {
"method": "get",
"path": "/custom/integration/info"
},
"response": {
"status": 200,
"json": {
"version": "${nextVersion}"
}
}
}]
"""
writeJSON file: "${args.filePath}", json: routeFileContent
writeJSON file: "${args.filePath}", json: args.content
}

// Updates the Angular dependencies to the version specified by the npm tag
def updateDependenciesWithTag(Map args = new LinkedHashMap()) {
String npm_tag = args.npm_tag
sh "yarn add @angular/core@${npm_tag} @angular/animations@${npm_tag} @angular/common@${npm_tag} @angular/compiler@${npm_tag} @angular/core@${npm_tag} @angular/forms@${npm_tag} @angular/platform-browser@${npm_tag} @angular-devkit/build-angular@${npm_tag} @angular/cli@${npm_tag} @angular/compiler-cli@${npm_tag}"
String npmTag = args.npmTag ?: 'latest'
sh "yarn add @angular/core@${npmTag} @angular/animations@${npmTag} @angular/common@${npmTag} @angular/compiler@${npmTag} @angular/core@${npmTag} @angular/forms@${npmTag} @angular/platform-browser@${npmTag} @angular-devkit/build-angular@${npmTag} @angular/cli@${npmTag} @angular/compiler-cli@${npmTag}"
}

def runSmokeTests(Map args = new LinkedHashMap()) {
def platforms = args.platforms ?: [
[ browser: "chrome", provider: "lambdatest" ]
]
String customRouteFilePath = "${WORKSPACE}/version.json"
String additionalArgs = "--chunk 20 --totalTimeout 1800000 --singleTimeout 90000 --retries 3 --customRoutes ${customRouteFilePath}"
String routeFilePath = "${WORKSPACE}/customRoutes.json"
String additionalArgs = "--chunk 20 --totalTimeout 1800000 --singleTimeout 90000 --retries 3 --customRoutes ${routeFilePath}"

def processes = [:]

Expand Down Expand Up @@ -77,8 +58,8 @@ def runSmokeTests(Map args = new LinkedHashMap()) {
customArgs = customArgs + " --platformName \"${platform.os}\""
}

generateNPMVersionRouteFile(npm_tag: args.npm_tag, filePath: customRouteFilePath)
updateDependenciesWithTag(npm_tag: args.npm_tag)
generateNPMVersionRouteFile(content: args.routeContent, filePath: routeFilePath)
updateDependenciesWithTag(npmTag: args.npmTag)
bedrockTests(
name: name,
browser: platform.browser,
Expand All @@ -95,8 +76,8 @@ def runSmokeTests(Map args = new LinkedHashMap()) {
def name = "headless-${platform.browser}${suffix}"
processes[name] = {
stage("${name}") {
generateNPMVersionRouteFile(npm_tag: args.npm_tag, filePath: customRouteFilePath)
updateDependenciesWithTag(npm_tag: args.npm_tag)
generateNPMVersionRouteFile(content: args.routeContent, filePath: routeFilePath)
updateDependenciesWithTag(npmTag: args.npmTag)
bedrockTests(
name: name,
browser: platform.browser,
Expand All @@ -114,6 +95,14 @@ def runSmokeTests(Map args = new LinkedHashMap()) {
parallel processes
}

def notify(Map slackArgs) {
// In shared libraries, the `call` method is not in the pipeline CPS context. We need to call the `steps` object to safely call jenkins steps
steps.retry(3) {
return steps.slackSend([ username: 'TinyMCE Integration Smoke Test', failOnError: true ] + slackArgs)
}
}


timestamps {
tinyPods.node() {
stage('deps') {
Expand All @@ -125,7 +114,43 @@ timestamps {
}

stage('tests') {
runSmokeTests(npm_tag: params.NPM_TAG ?: 'latest')
String npmTag = params.NPM_TAG ?: 'latest'
// @angular/core's version is the one baked into the angular app
String nextVersion = sh(script: "npm view @angular/core@${npmTag} version", returnStdout: true).trim()
echo "The upcoming Angular version: ${nextVersion}"

def customRouteContent = readJSON text: """
[{
"request": {
"method": "get",
"path": "/custom/integration/info"
},
"response": {
"status": 200,
"json": {
"version": "${nextVersion}"
}
}
}]
"""

try {
runSmokeTests(npmTag: npmTag, routeContent: customRouteContent)
} catch (Exception e) {
echo "Exception was caught: ${e}"
currentBuild.result = 'FAILURE'
} finally {
if (currentBuild.resultIsWorseOrEqualTo('UNSTABLE')) {
def color = ['UNSTABLE': 'warning', 'FAILURE': 'danger']
def message = currentBuild.result == 'UNSTABLE' ? "Tests failed" : 'An unexpected error occurred while running tests'

notify(
channel: '#tiny-integrations-dev',
color: color.get(currentBuild.result, '#808080'),
message: "${env.JOB_NAME} against ${nextVersion} failed: ${message} (<${env.BUILD_URL}|Open>)"
)
}
}
}
}
}
Loading