2018-11-08 10:13:40 +00:00
|
|
|
import groovy.json.JsonBuilder
|
|
|
|
|
2018-08-21 15:17:25 +00:00
|
|
|
def version() {
|
|
|
|
return readFile("${env.WORKSPACE}/VERSION").trim()
|
|
|
|
}
|
|
|
|
|
2018-08-29 07:43:21 +00:00
|
|
|
def getBuildType() {
|
|
|
|
def jobName = env.JOB_NAME
|
2018-12-11 14:27:21 +00:00
|
|
|
if (jobName.contains('e2e')) {
|
|
|
|
return 'e2e'
|
|
|
|
}
|
2018-08-29 07:43:21 +00:00
|
|
|
if (jobName.startsWith('status-react/pull requests')) {
|
|
|
|
return 'pr'
|
|
|
|
}
|
|
|
|
if (jobName.startsWith('status-react/nightly')) {
|
|
|
|
return 'nightly'
|
|
|
|
}
|
|
|
|
if (jobName.startsWith('status-react/release')) {
|
|
|
|
return 'release'
|
|
|
|
}
|
|
|
|
return params.BUILD_TYPE
|
|
|
|
}
|
2018-09-25 17:01:48 +00:00
|
|
|
|
2018-10-02 20:40:36 +00:00
|
|
|
def buildBranch(name = null, buildType = null) {
|
|
|
|
/* default to current build type */
|
|
|
|
buildType = buildType ? buildType : getBuildType()
|
2018-08-28 19:01:30 +00:00
|
|
|
/* need to drop origin/ to match definitions of child jobs */
|
|
|
|
def branchName = env.GIT_BRANCH.replace('origin/', '')
|
2018-08-21 15:17:25 +00:00
|
|
|
/* always pass the BRANCH and BUILD_TYPE params with current branch */
|
2018-08-29 20:29:09 +00:00
|
|
|
def b = build(
|
2018-08-21 15:17:25 +00:00
|
|
|
job: name,
|
2018-08-29 20:29:09 +00:00
|
|
|
/* this allows us to analize the job even after failure */
|
|
|
|
propagate: false,
|
2018-08-21 15:17:25 +00:00
|
|
|
parameters: [
|
2018-12-11 14:27:21 +00:00
|
|
|
[name: 'BRANCH', value: branchName, $class: 'StringParameterValue'],
|
|
|
|
[name: 'BUILD_TYPE', value: buildType, $class: 'StringParameterValue'],
|
|
|
|
[name: 'CHANGE_ID', value: env.CHANGE_ID, $class: 'StringParameterValue'],
|
2018-08-21 15:17:25 +00:00
|
|
|
])
|
2018-08-29 20:29:09 +00:00
|
|
|
/* BlueOcean seems to not show child-build links */
|
2018-08-30 02:23:26 +00:00
|
|
|
print "Build: ${b.getAbsoluteUrl()} (${b.result})"
|
|
|
|
if (b.result != 'SUCCESS') {
|
|
|
|
error("Build Failed")
|
|
|
|
}
|
2018-08-29 20:29:09 +00:00
|
|
|
return b
|
2018-08-21 15:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def copyArts(projectName, buildNo) {
|
|
|
|
copyArtifacts(
|
|
|
|
projectName: projectName,
|
|
|
|
target: 'pkg',
|
|
|
|
flatten: true,
|
|
|
|
selector: specific("${buildNo}")
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-08-14 18:09:52 +00:00
|
|
|
def installJSDeps(platform) {
|
|
|
|
def attempt = 1
|
|
|
|
def maxAttempts = 10
|
|
|
|
def installed = false
|
|
|
|
/* prepare environment for specific platform build */
|
2018-11-30 14:32:30 +00:00
|
|
|
sh "scripts/run-environment-check.sh ${platform}"
|
2018-08-14 18:09:52 +00:00
|
|
|
sh "scripts/prepare-for-platform.sh ${platform}"
|
|
|
|
while (!installed && attempt <= maxAttempts) {
|
2018-11-02 12:16:29 +00:00
|
|
|
println("#${attempt} attempt to install npm deps")
|
2018-11-28 18:02:20 +00:00
|
|
|
sh 'yarn install --frozen-lockfile'
|
2018-08-14 18:09:52 +00:00
|
|
|
installed = fileExists('node_modules/web3/index.js')
|
|
|
|
attemp = attempt + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def doGitRebase() {
|
2018-12-11 14:27:21 +00:00
|
|
|
sh 'git status'
|
|
|
|
sh 'git fetch --force origin develop:develop'
|
2018-08-14 18:09:52 +00:00
|
|
|
try {
|
2018-12-11 14:27:21 +00:00
|
|
|
sh 'git rebase develop'
|
2018-08-14 18:09:52 +00:00
|
|
|
} catch (e) {
|
|
|
|
sh 'git rebase --abort'
|
|
|
|
throw e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 12:16:29 +00:00
|
|
|
def buildNumber() {
|
|
|
|
def number = sh(
|
|
|
|
returnStdout: true,
|
|
|
|
script: "./scripts/gen_build_no.sh"
|
|
|
|
).trim()
|
|
|
|
println("Build Number: ${number}")
|
|
|
|
return number
|
2018-08-14 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 12:56:19 +00:00
|
|
|
def getDirPath(path) {
|
|
|
|
return path.tokenize('/')[0..-2].join('/')
|
|
|
|
}
|
|
|
|
|
|
|
|
def getFilename(path) {
|
|
|
|
return path.tokenize('/')[-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
def uploadArtifact(path) {
|
|
|
|
/* defaults for upload */
|
2018-08-14 18:09:52 +00:00
|
|
|
def domain = 'ams3.digitaloceanspaces.com'
|
2018-08-23 12:56:19 +00:00
|
|
|
def bucket = 'status-im'
|
2018-10-02 20:40:36 +00:00
|
|
|
/* There's so many PR builds we need a separate bucket */
|
|
|
|
if (getBuildType() == 'pr') {
|
|
|
|
bucket = 'status-im-prs'
|
|
|
|
}
|
2018-10-12 13:15:30 +00:00
|
|
|
/* WARNING: s3cmd can't guess APK MIME content-type */
|
|
|
|
def customOpts = ''
|
|
|
|
if (path.endsWith('apk')) {
|
|
|
|
customOpts += "--mime-type='application/vnd.android.package-archive'"
|
|
|
|
}
|
|
|
|
/* We also need credentials for the upload */
|
2018-08-14 18:09:52 +00:00
|
|
|
withCredentials([usernamePassword(
|
|
|
|
credentialsId: 'digital-ocean-access-keys',
|
|
|
|
usernameVariable: 'DO_ACCESS_KEY',
|
|
|
|
passwordVariable: 'DO_SECRET_KEY'
|
|
|
|
)]) {
|
|
|
|
sh """
|
|
|
|
s3cmd \\
|
|
|
|
--acl-public \\
|
2018-10-12 13:15:30 +00:00
|
|
|
${customOpts} \\
|
2018-08-14 18:09:52 +00:00
|
|
|
--host='${domain}' \\
|
|
|
|
--host-bucket='%(bucket)s.${domain}' \\
|
|
|
|
--access_key=${DO_ACCESS_KEY} \\
|
|
|
|
--secret_key=${DO_SECRET_KEY} \\
|
2018-08-23 12:56:19 +00:00
|
|
|
put ${path} s3://${bucket}/
|
2018-08-14 18:09:52 +00:00
|
|
|
"""
|
|
|
|
}
|
2018-08-23 12:56:19 +00:00
|
|
|
return "https://${bucket}.${domain}/${getFilename(path)}"
|
|
|
|
}
|
|
|
|
|
|
|
|
def timestamp() {
|
|
|
|
def now = new Date(currentBuild.timeInMillis)
|
2018-08-30 12:05:41 +00:00
|
|
|
return now.format('yyMMdd-HHmmss', TimeZone.getTimeZone('UTC'))
|
2018-08-23 12:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def gitCommit() {
|
|
|
|
return GIT_COMMIT.take(6)
|
|
|
|
}
|
|
|
|
|
|
|
|
def pkgFilename(type, ext) {
|
2018-08-30 12:05:41 +00:00
|
|
|
return "StatusIm-${timestamp()}-${gitCommit()}-${type}.${ext}"
|
2018-08-14 18:09:52 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 14:27:21 +00:00
|
|
|
def buildDuration() {
|
|
|
|
def duration = currentBuild.durationString
|
|
|
|
return '~' + duration.take(duration.lastIndexOf(' and counting'))
|
|
|
|
}
|
2018-08-29 07:43:21 +00:00
|
|
|
|
2018-12-11 14:27:21 +00:00
|
|
|
def gitHubNotify(message) {
|
2018-11-13 18:35:17 +00:00
|
|
|
def githubIssuesUrl = 'https://api.github.com/repos/status-im/status-react/issues'
|
2018-12-13 09:49:16 +00:00
|
|
|
/* 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) {
|
|
|
|
println('This build is not related to a PR, CHANGE_ID missing.')
|
|
|
|
println('GitHub notification impossible, skipping...')
|
|
|
|
return
|
|
|
|
}
|
2018-12-11 14:27:21 +00:00
|
|
|
def msgObj = [body: message]
|
|
|
|
def msgJson = new JsonBuilder(msgObj).toPrettyString()
|
|
|
|
withCredentials([usernamePassword(
|
|
|
|
credentialsId: 'status-im-auto',
|
|
|
|
usernameVariable: 'GH_USER',
|
|
|
|
passwordVariable: 'GH_PASS'
|
|
|
|
)]) {
|
2018-11-13 18:35:17 +00:00
|
|
|
sh """
|
|
|
|
curl --silent \
|
2018-12-11 14:27:21 +00:00
|
|
|
-u '${GH_USER}:${GH_PASS}' \
|
2018-11-13 18:35:17 +00:00
|
|
|
--data '${msgJson}' \
|
2018-12-11 14:27:21 +00:00
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
"${githubIssuesUrl}/${changeId}/comments"
|
2018-11-13 18:35:17 +00:00
|
|
|
""".trim()
|
2018-08-29 07:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 14:27:21 +00:00
|
|
|
def gitHubNotifyFull(urls) {
|
|
|
|
def msg = "#### :white_check_mark: "
|
|
|
|
msg += "[${env.JOB_NAME}${currentBuild.displayName}](${currentBuild.absoluteUrl}) "
|
|
|
|
msg += "CI BUILD SUCCESSFUL in ${buildDuration()} (${GIT_COMMIT.take(8)})\n"
|
|
|
|
msg += '| | | | | |\n'
|
|
|
|
msg += '|-|-|-|-|-|\n'
|
|
|
|
msg += "| [Android](${urls.Apk}) ([e2e](${urls.Apke2e})) "
|
|
|
|
msg += "| [iOS](${urls.iOS}) ([e2e](${urls.iOSe2e})) |"
|
|
|
|
if (urls.Mac != null) {
|
|
|
|
msg += " [MacOS](${urls.Mac}) | [AppImage](${urls.App}) | [Windows](${urls.Win}) |"
|
|
|
|
} else {
|
|
|
|
msg += " ~~MacOS~~ | ~~AppImage~~ | ~~Windows~~~ |"
|
|
|
|
}
|
|
|
|
gitHubNotify(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def gitHubNotifyPRFail() {
|
|
|
|
def d = ":small_orange_diamond:"
|
|
|
|
def msg = "#### :x: "
|
|
|
|
msg += "[${env.JOB_NAME}${currentBuild.displayName}](${currentBuild.absoluteUrl}) ${d} "
|
|
|
|
msg += "${buildDuration()} ${d} ${GIT_COMMIT.take(8)} ${d} "
|
|
|
|
msg += "[:page_facing_up: build log](${currentBuild.absoluteUrl}/consoleText)"
|
|
|
|
//msg += "Failed in stage: ${env.STAGE_NAME}\n"
|
|
|
|
//msg += "```${currentBuild.rawBuild.getLog(5)}```"
|
|
|
|
gitHubNotify(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
def gitHubNotifyPRSuccess() {
|
|
|
|
def d = ":small_blue_diamond:"
|
|
|
|
def msg = "#### :heavy_check_mark: "
|
|
|
|
def type = getBuildType() == 'e2e' ? ' e2e' : ''
|
|
|
|
msg += "[${env.JOB_NAME}${currentBuild.displayName}](${currentBuild.absoluteUrl}) ${d} "
|
|
|
|
msg += "${buildDuration()} ${d} ${GIT_COMMIT.take(8)} ${d} "
|
|
|
|
msg += "[:package: ${env.BUILD_PLATFORM}${type} package](${env.PKG_URL})"
|
|
|
|
gitHubNotify(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
def getEnv(build, envvar) {
|
|
|
|
return build.getBuildVariables().get(envvar)
|
|
|
|
}
|
|
|
|
|
|
|
|
def pkgUrl(build) {
|
|
|
|
return getEnv(build, 'PKG_URL')
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:40:36 +00:00
|
|
|
def pkgFind(glob) {
|
2018-11-19 17:37:04 +00:00
|
|
|
def fullGlob = "pkg/*${glob}"
|
|
|
|
def found = findFiles(glob: fullGlob)
|
|
|
|
if (found.size() == 0) {
|
|
|
|
sh 'ls -l pkg/'
|
|
|
|
error("File not found via glob: ${fullGlob} ${found.size()}")
|
|
|
|
}
|
|
|
|
return found[0].path
|
2018-10-02 20:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def setBuildDesc(Map links) {
|
|
|
|
def desc = 'Links: \n'
|
|
|
|
links.each { type, url ->
|
|
|
|
if (url != null) {
|
|
|
|
desc += "<a href=\"${url}\">${type}</a> \n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentBuild.description = desc
|
|
|
|
}
|
|
|
|
|
2018-12-11 14:27:21 +00:00
|
|
|
def updateLatestNightlies(urls) {
|
|
|
|
/* latest.json has slightly different key names */
|
|
|
|
def latest = [
|
|
|
|
APK: urls.Apk, IOS: urls.iOS,
|
|
|
|
APP: urls.App, MAC: urls.Mac,
|
|
|
|
WIN: urls.Win, SHA: urls.SHA
|
|
|
|
]
|
2018-11-08 10:13:40 +00:00
|
|
|
def latestFile = pwd() + '/' + 'pkg/latest.json'
|
|
|
|
/* it might not exist */
|
|
|
|
sh 'mkdir -p pkg'
|
2018-12-11 14:27:21 +00:00
|
|
|
def latestJson = new JsonBuilder(latest).toPrettyString()
|
2018-11-08 10:13:40 +00:00
|
|
|
println("latest.json:\n${latestJson}")
|
|
|
|
new File(latestFile).write(latestJson)
|
|
|
|
return uploadArtifact(latestFile)
|
|
|
|
}
|
|
|
|
|
2018-08-30 10:46:37 +00:00
|
|
|
def getParentRunEnv(name) {
|
|
|
|
def c = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)
|
|
|
|
if (c == null) { return null }
|
|
|
|
return c.getUpstreamRun().getEnvironment()[name]
|
|
|
|
}
|
|
|
|
|
2018-09-25 17:01:48 +00:00
|
|
|
def runLint() {
|
|
|
|
sh 'lein cljfmt check'
|
|
|
|
}
|
|
|
|
|
|
|
|
def runTests() {
|
|
|
|
sh 'lein test-cljs'
|
|
|
|
}
|
|
|
|
|
2018-12-13 09:49:16 +00:00
|
|
|
def clean() {
|
|
|
|
sh 'make clean'
|
|
|
|
}
|
|
|
|
|
2018-08-14 18:09:52 +00:00
|
|
|
return this
|