diff --git a/ci/Jenkinsfile.android b/ci/Jenkinsfile.android index 5015c84cfd..9d867e5442 100644 --- a/ci/Jenkinsfile.android +++ b/ci/Jenkinsfile.android @@ -94,7 +94,7 @@ pipeline { } stage('Notify') { steps { - script { cmn.gitHubNotifyPRSuccess() } + script { cmn.notifyPRSuccess() } } } stage('Cleanup') { @@ -104,6 +104,6 @@ pipeline { } } post { - failure { script { load('ci/common.groovy').gitHubNotifyPRFail() } } + failure { script { load('ci/common.groovy').notifyPRFailure() } } } } diff --git a/ci/Jenkinsfile.ios b/ci/Jenkinsfile.ios index 72e9417884..4ee70c950c 100644 --- a/ci/Jenkinsfile.ios +++ b/ci/Jenkinsfile.ios @@ -79,6 +79,7 @@ pipeline { /* e2e builds get tested in SauceLabs */ if (cmn.getBuildType() == 'e2e') { env.SAUCE_URL = mobile.ios.uploadToSauceLabs() + env.PKG_URL = cmn.uploadArtifact(api) } else { env.PKG_URL = mobile.ios.uploadToDiawi() } @@ -87,7 +88,7 @@ pipeline { } stage('Notify') { steps { - script { cmn.gitHubNotifyPRSuccess() } + script { cmn.notifyPRSuccess() } } } stage('Cleanup') { @@ -97,6 +98,6 @@ pipeline { } } post { - failure { script { load('ci/common.groovy').gitHubNotifyPRFail() } } + failure { script { load('ci/common.groovy').notifyPRFailure() } } } } diff --git a/ci/Jenkinsfile.linux b/ci/Jenkinsfile.linux index e879334a0e..145b434113 100644 --- a/ci/Jenkinsfile.linux +++ b/ci/Jenkinsfile.linux @@ -100,7 +100,7 @@ pipeline { } stage('Notify') { steps { - script { cmn.gitHubNotifyPRSuccess() } + script { cmn.notifyPRSuccess() } } } stage('Cleanup') { @@ -110,6 +110,6 @@ pipeline { } } post { - failure { script { load('ci/common.groovy').gitHubNotifyPRFail() } } + failure { script { load('ci/common.groovy').notifyPRFailure() } } } } diff --git a/ci/Jenkinsfile.macos b/ci/Jenkinsfile.macos index 49f6c6239c..82cda43169 100644 --- a/ci/Jenkinsfile.macos +++ b/ci/Jenkinsfile.macos @@ -81,7 +81,7 @@ pipeline { } stage('Notify') { steps { - script { cmn.gitHubNotifyPRSuccess() } + script { cmn.notifyPRSuccess() } } } stage('Cleanup') { @@ -91,6 +91,6 @@ pipeline { } } post { - failure { script { load('ci/common.groovy').gitHubNotifyPRFail() } } + failure { script { load('ci/common.groovy').notifyPRFailure() } } } } diff --git a/ci/Jenkinsfile.windows b/ci/Jenkinsfile.windows index cade88a870..95d841ccce 100644 --- a/ci/Jenkinsfile.windows +++ b/ci/Jenkinsfile.windows @@ -103,7 +103,7 @@ pipeline { } stage('Notify') { steps { - script { cmn.gitHubNotifyPRSuccess() } + script { cmn.notifyPRSuccess() } } } stage('Cleanup') { @@ -113,6 +113,6 @@ pipeline { } } post { - failure { script { load('ci/common.groovy').gitHubNotifyPRFail() } } + failure { script { load('ci/common.groovy').notifyPRFailure() } } } } diff --git a/ci/common.groovy b/ci/common.groovy index 7e48b4fab2..1deb2b8e06 100644 --- a/ci/common.groovy +++ b/ci/common.groovy @@ -37,7 +37,7 @@ def buildBranch(name = null, buildType = null) { [name: 'CHANGE_ID', value: env.CHANGE_ID, $class: 'StringParameterValue'], ]) /* BlueOcean seems to not show child-build links */ - print "Build: ${b.getAbsoluteUrl()} (${b.result})" + println "Build: ${b.getAbsoluteUrl()} (${b.result})" if (b.result != 'SUCCESS') { error("Build Failed") } @@ -61,7 +61,7 @@ def installJSDeps(platform) { sh "scripts/run-environment-check.sh ${platform}" sh "scripts/prepare-for-platform.sh ${platform}" while (!installed && attempt <= maxAttempts) { - println("#${attempt} attempt to install npm deps") + println "#${attempt} attempt to install npm deps" sh 'yarn install --frozen-lockfile' installed = fileExists('node_modules/web3/index.js') attemp = attempt + 1 @@ -84,7 +84,7 @@ def buildNumber() { returnStdout: true, script: "./scripts/gen_build_no.sh" ).trim() - println("Build Number: ${number}") + println "Build Number: ${number}" return number } @@ -147,14 +147,54 @@ def buildDuration() { return '~' + duration.take(duration.lastIndexOf(' and counting')) } -def gitHubNotify(message) { - def githubIssuesUrl = 'https://api.github.com/repos/status-im/status-react/issues' +def changeId() { /* CHANGE_ID can be provided via the build parameters or from parent */ def changeId = env.CHANGE_ID changeId = params.CHANGE_ID ? params.CHANGE_ID : changeId changeId = getParentRunEnv('CHANGE_ID') ? getParentRunEnv('CHANGE_ID') : changeId - /* CHANGE_ID exists only when run as a PR build */ - if (!changeId) { + return changeId +} + +def ghcmgrBuildObj(success) { + /* assemble build object valid for ghcmgr */ + return [ + id: env.BUILD_DISPLAY_NAME, + commit: GIT_COMMIT.take(8), + success: success ? success : true, + platform: env.BUILD_PLATFORM + (getBuildType() == 'e2e' ? '-e2e' : ''), + duration: buildDuration(), + url: currentBuild.absoluteUrl, + pkg_url: env.PKG_URL, + ] +} + +def ghcmgrPostBuild(success) { + /** + * This is our own service for avoiding comment spam. + * https://github.com/status-im/github-comment-manager + **/ + def ghcmgrurl = 'https://ghcmgr.status.im' + def changeId = changeId() + def body = ghcmgrBuildObj(success) + def json = new JsonBuilder(body).toPrettyString() + withCredentials([usernamePassword( + credentialsId: 'ghcmgr-auth', + usernameVariable: 'GHCMGR_USER', + passwordVariable: 'GHCMGR_PASS' + )]) { + sh """ + curl --silent --verbose -XPOST --data '${json}' \ + -u '${GHCMGR_USER}:${GHCMGR_PASS}' \ + -H "content-type: application/json" \ + '${ghcmgrurl}/builds/${changeId}' + """ + } +} + +def gitHubNotify(message) { + def githubIssuesUrl = 'https://api.github.com/repos/status-im/status-react/issues' + def changeId = changeId() + if (!changeId) { /* CHANGE_ID exists only when run as a PR build */ println('This build is not related to a PR, CHANGE_ID missing.') println('GitHub notification impossible, skipping...') return @@ -193,7 +233,7 @@ def gitHubNotifyFull(urls) { } -def gitHubNotifyPRFail() { +def gitHubNotifyPRFailure() { def d = ":small_orange_diamond:" def msg = "#### :x: " msg += "[${env.JOB_NAME}${currentBuild.displayName}](${currentBuild.absoluteUrl}) ${d} " @@ -214,6 +254,24 @@ def gitHubNotifyPRSuccess() { gitHubNotify(msg) } +def notifyPRFailure() { + try { + ghcmgrPostBuild(false) + } catch (ex) { /* fallback to posting directly to GitHub */ + println "Failed to use GHCMGR: ${ex}" + gitHubNotifyPRFailure() + } +} + +def notifyPRSuccess() { + try { + ghcmgrPostBuild(true) + } catch (ex) { /* fallback to posting directly to GitHub */ + println "Failed to use GHCMGR: ${ex}" + gitHubNotifyPRSuccess() + } +} + def getEnv(build, envvar) { return build.getBuildVariables().get(envvar) } @@ -253,7 +311,7 @@ def updateLatestNightlies(urls) { /* it might not exist */ sh 'mkdir -p pkg' def latestJson = new JsonBuilder(latest).toPrettyString() - println("latest.json:\n${latestJson}") + println "latest.json:\n${latestJson}" new File(latestFile).write(latestJson) return uploadArtifact(latestFile) }