Skip to content
82 changes: 53 additions & 29 deletions Jenkinsfile-SmokeTest
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,20 @@ 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}"
sh "yarn add @angular/core@${args.npmTag} @angular/animations@${args.npmTag} @angular/common@${args.npmTag} @angular/compiler@${args.npmTag} @angular/core@${args.npmTag} @angular/forms@${args.npmTag} @angular/platform-browser@${args.npmTag} @angular-devkit/build-angular@${args.npmTag} @angular/cli@${args.npmTag} @angular/compiler-cli@${args.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 +57,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 +75,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 +94,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 +113,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')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to handle a case where this condition isn't met?

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