ci: refactor to use status-jenkins-lib

This should fix issues with re-running builds while skipping some initial stages.

Also removes two libraries we made use of before.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2021-05-06 17:14:58 +02:00 committed by Jakub
parent 244686e3a8
commit 91620b9982
8 changed files with 100 additions and 308 deletions

View File

@ -1,3 +1,5 @@
library 'status-jenkins-lib@v1.2.16'
pipeline {
agent { label 'linux' }
@ -27,56 +29,36 @@ pipeline {
environment {
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
/* This will override the var in Makefile */
RELEASE_DIR = "${env.WORKSPACE}/out"
RELEASE_DIR = "${env.WORKSPACE}/pkg"
}
stages {
stage('Prep') {
steps { script {
lib = load("${env.STATUS_PATH}/_assets/ci/lib.groovy")
version = lib.getVersion()
println("Version: ${version}")
println("Git Branch: ${lib.gitBranch()}")
println("Git Commit: ${lib.gitCommit()}")
} }
} // stage(Prep)
stage('Setup') { steps { dir(env.STATUS_PATH) {
/* install release tools */
sh 'make release-install modvendor-install'
} } } // stage(Setup)
stage('Vendoring check') { steps { dir(env.STATUS_PATH) {
/* fail build if vendoring hasn't been done */
sh 'GO111MODULE=on make vendor && git diff --exit-code --no-color --stat vendor/'
} } } // stage(Vendoring check)
stage('Build') {
parallel {
stage('iOS') { steps { script {
ios = lib.buildBranch('status-go/platforms/ios')
ios = jenkins.Build('status-go/platforms/ios')
} } }
stage('Android') { steps { script {
android = lib.buildBranch('status-go/platforms/android')
android = jenkins.Build('status-go/platforms/android')
} } }
stage('Linux') { steps { script {
linux = lib.buildBranch('status-go/platforms/linux')
linux = jenkins.Build('status-go/platforms/linux')
} } }
stage('Docker') { steps { script {
dock = lib.buildBranch('status-go/platforms/docker')
dock = jenkins.Build('status-go/platforms/docker')
} } }
} // parallel
} // stage(Build)
stage('Archive') {
steps { script {
sh("rm -fr ${env.RELEASE_DIR}/*")
sh "rm -fr ${env.RELEASE_DIR}"
sh "mkdir ${env.RELEASE_DIR}"
[ios, android, linux].each { platformBuild ->
lib.copyArts(platformBuild)
jenkins.copyArts(platformBuild)
}
dir(env.RELEASE_DIR) {
/* generate sha256 checksums for upload */
@ -86,9 +68,10 @@ pipeline {
} }
} // stage(Archive)
stage('Release') { when { expression { params.RELEASE == true } }
stage('Release') {
when { expression { params.RELEASE == true } }
steps { script {
def suffix = "-"+lib.suffix()
def suffix = "-"+utils.suffix()
/* rename build files to not include versions */
dir(env.RELEASE_DIR) {
findFiles(glob: 'status-go-*').each { pkg ->
@ -103,7 +86,7 @@ pipeline {
usernameVariable: 'GITHUB_USER',
passwordVariable: 'GITHUB_TOKEN'
]]) {
env.RELEASE_BRANCH = lib.gitBranch()
env.RELEASE_BRANCH = utils.branchName()
env.RELEASE_DIR = env.RELEASE_DIR
sh 'yes | make release'
}

View File

@ -1,3 +1,5 @@
library 'status-jenkins-lib@v1.2.17'
pipeline {
agent { label 'linux' }
@ -28,14 +30,15 @@ pipeline {
environment {
/* fix for gomobile complaining about missing packages */
CGO_ENABLED = "1"
GO111MODULE = "off"
CGO_ENABLED = "1"
GO111MODULE = "off"
/* Other stuff */
BUILD_PLATFORM = 'android'
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
TARGET = 'android'
GOPATH = "${env.WORKSPACE}"
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
ARTIFACT = "${env.WORKSPACE}/status-go-android-${utils.timestamp()}-${utils.gitCommit()}.aar"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
/* Android SDK */
ANDROID_HOME = '/usr/lib/android-sdk'
ANDROID_SDK_ROOT = '/usr/lib/android-sdk'
/* gomobile requires a specific NDK version */
@ -44,18 +47,11 @@ pipeline {
}
stages {
stage('Prep') { steps { script {
lib = load("${CI_DIR}/lib.groovy")
/* clarify what we're building */
println("Version: ${lib.getVersion()}")
println("Git Branch: ${lib.gitBranch()}")
println("Git Commit: ${lib.gitCommit()}")
/* save and create a dir for artifacts */
dest = "${env.WORKSPACE}/out"
sh "mkdir -p ${dest}"
/* for easier reuse */
artifact = "status-go-android-${lib.suffix()}.aar"
} } }
stage('Prep') { steps { dir(env.STATUS_PATH) { script {
println("Version: ${utils.getVersion()}")
println("Git Branch: ${utils.branchName()}")
println("Git Commit: ${utils.gitCommit()}")
} } } }
stage('Setup') { steps { dir(env.STATUS_PATH) {
sh 'make setup-build modvendor-install'
@ -63,28 +59,26 @@ pipeline {
stage('Vendoring check') { steps { dir(env.STATUS_PATH) {
/* fail build if vendoring hasn't been done */
sh 'GO111MODULE=on make vendor && git diff --exit-code --no-color --stat vendor/'
} } } // stage(Vendoring check)
sh 'GO111MODULE=on make vendor'
sh 'git diff --exit-code --no-color --stat vendor/'
} } }
stage('Compile') { steps { dir(env.STATUS_PATH) {
sh 'make statusgo-android'
sh "cp build/bin/statusgo.aar ${dest}/${artifact}"
sh "cp build/bin/statusgo.aar ${env.ARTIFACT}"
} } }
stage('Archive') { steps {
archiveArtifacts("out/${artifact}")
archiveArtifacts(env.ARTIFACT.minus("${env.WORKSPACE}/"))
} }
stage('Upload') { steps { script {
env.PKG_URL = lib.uploadArtifact("out/${artifact}")
env.PKG_URL = s3.uploadArtifact(env.ARTIFACT)
} } }
} // stages
post {
success { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(true) } }
failure { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(false) } }
always { dir(env.STATUS_PATH) {
sh 'make clean'
sh "rm -fr ${dest}"
} }
success { script { github.notifyPR(true) } }
failure { script { github.notifyPR(false) } }
always { dir(env.STATUS_PATH) { sh 'make clean' } }
} // post
} // pipeline

View File

@ -1,3 +1,5 @@
library 'status-jenkins-lib@v1.2.17'
pipeline {
agent { label 'linux' }
@ -27,9 +29,9 @@ pipeline {
}
environment {
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci"
TARGET = "docker"
GOPATH = "${env.WORKSPACE}"
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
/* docker image settings */
IMAGE_NAME = "statusteam/status-go"
@ -37,20 +39,15 @@ pipeline {
}
stages {
stage('Prep') { steps { script {
lib = load("${env.STATUS_PATH}/_assets/ci/lib.groovy")
/* clarify what we're building */
println("Version: ${lib.getVersion()}")
println("Git Branch: ${lib.gitBranch()}")
println("Git Commit: ${lib.gitCommit()}")
/* save and create a dir for artifacts */
dest = "${env.WORKSPACE}/pkg"
sh "mkdir -p ${dest}"
} } }
stage('Prep') { steps { dir(env.STATUS_PATH) { script {
println("Version: ${utils.getVersion()}")
println("Git Branch: ${utils.branchName()}")
println("Git Commit: ${utils.gitCommit()}")
} } } }
stage('Build') { steps { dir(env.STATUS_PATH) { script {
sh 'make docker-image'
image = docker.image("${env.IMAGE_NAME}:${lib.getVersion()}")
image = docker.image("${env.IMAGE_NAME}:v${utils.getVersion()}")
} } } }
stage('Push') { steps { dir(env.STATUS_PATH) { script {
@ -68,8 +65,8 @@ pipeline {
} } } }
} // stages
post {
success { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(true) } }
failure { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(false) } }
success { script { github.notifyPR(true) } }
failure { script { github.notifyPR(false) } }
always { dir(env.STATUS_PATH) {
sh 'make clean-docker-images'
} }

View File

@ -1,3 +1,5 @@
library 'status-jenkins-lib@v1.2.17'
pipeline {
agent { label 'macos' }
@ -28,29 +30,22 @@ pipeline {
environment {
/* fix for gomobile complaining about missing packages */
CGO_ENABLED = "1"
GO111MODULE = "off"
CGO_ENABLED = "1"
GO111MODULE = "off"
/* Other stuff */
BUILD_PLATFORM = 'ios'
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
TARGET = 'ios'
GOPATH = "${env.WORKSPACE}"
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
ARTIFACT = "${env.WORKSPACE}/status-go-ios-${utils.timestamp()}-${utils.gitCommit()}.zip"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
}
stages {
stage('Prep') { steps { script {
lib = load("${CI_DIR}/lib.groovy")
/* clarify what we're building */
println("Version: ${lib.getVersion()}")
println("Git Branch: ${lib.gitBranch()}")
println("Git Commit: ${lib.gitCommit()}")
/* save and create a dir for artifacts */
dest = "${env.WORKSPACE}/out"
sh "mkdir -p ${dest}"
/* for easier reuse */
artifact = "status-go-ios-${lib.suffix()}.zip"
} } }
stage('Prep') { steps { dir(env.STATUS_PATH) { script {
println("Version: ${utils.getVersion()}")
println("Git Branch: ${utils.branchName()}")
println("Git Commit: ${utils.gitCommit()}")
} } } }
stage('Setup') { steps { dir(env.STATUS_PATH) {
sh 'unset TMPDIR && make setup-build'
@ -61,24 +56,21 @@ pipeline {
sh 'go get golang.org/x/tools/go/packages'
dir('build/bin') {
sh 'zip -r status-go-ios.zip Statusgo.framework'
sh "cp status-go-ios.zip ${dest}/${artifact}"
sh "cp status-go-ios.zip ${env.ARTIFACT}"
}
} } }
stage('Archive') { steps {
archiveArtifacts("out/${artifact}")
archiveArtifacts(env.ARTIFACT.minus("${env.WORKSPACE}/"))
} }
stage('Upload') { steps { script {
env.PKG_URL = lib.uploadArtifact("out/${artifact}")
env.PKG_URL = s3.uploadArtifact(env.ARTIFACT)
} } }
} // stages
post {
success { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(true) } }
failure { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(false) } }
always { dir(env.STATUS_PATH) {
sh 'make clean'
sh "rm -fr ${dest}"
} }
success { script { github.notifyPR(true) } }
failure { script { github.notifyPR(false) } }
always { dir(env.STATUS_PATH) { sh 'make clean' } }
} // post
} // pipeline

View File

@ -1,3 +1,5 @@
library 'status-jenkins-lib@v1.2.17'
pipeline {
agent { label 'linux' }
@ -27,26 +29,19 @@ pipeline {
}
environment {
BUILD_PLATFORM = 'linux'
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
TARGET = 'linux'
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
GOPATH = "${env.WORKSPACE}"
ARTIFACT = "${env.WORKSPACE}/status-go-desktop-${utils.timestamp()}-${utils.gitCommit()}.zip"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
}
stages {
stage('Prep') { steps { script {
lib = load("${env.STATUS_PATH}/_assets/ci/lib.groovy")
/* clarify what we're building */
println("Version: ${lib.getVersion()}")
println("Git Branch: ${lib.gitBranch()}")
println("Git Commit: ${lib.gitCommit()}")
/* save and create a dir for artifacts */
dest = "${env.WORKSPACE}/out"
sh "mkdir -p ${dest}"
/* for easier reuse */
artifact = "status-go-desktop-${lib.suffix()}.zip"
} } }
stage('Prep') { steps { dir(env.STATUS_PATH) { script {
println("Version: ${utils.getVersion()}")
println("Git Branch: ${utils.branchName()}")
println("Git Commit: ${utils.gitCommit()}")
} } } }
stage('Setup') { steps { dir(env.STATUS_PATH) {
sh 'make setup-build'
@ -58,23 +53,20 @@ pipeline {
} } }
stage('Compress') { steps { dir(env.STATUS_PATH) {
sh "zip -q -r ${dest}/${artifact} . -x *.git"
sh "zip -q -r ${env.ARTIFACT} . -x *.git"
} } }
stage('Archive') { steps {
archiveArtifacts("out/${artifact}")
archiveArtifacts(env.ARTIFACT.minus("${env.WORKSPACE}/"))
} }
stage('Upload') { steps { script {
env.PKG_URL = lib.uploadArtifact("out/${artifact}")
env.PKG_URL = s3.uploadArtifact(env.ARTIFACT)
} } }
} // stages
post {
success { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(true) } }
failure { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(false) } }
always { dir(env.STATUS_PATH) {
sh 'make clean'
sh "rm -fr ${dest}"
} }
success { script { github.notifyPR(true) } }
failure { script { github.notifyPR(false) } }
always { dir(env.STATUS_PATH) { sh 'make clean' } }
} // post
} // pipeline

View File

@ -1,3 +1,5 @@
library 'status-jenkins-lib@v1.2.17'
pipeline {
agent { label 'linux' }
@ -22,21 +24,18 @@ pipeline {
}
environment {
BUILD_PLATFORM = 'linux'
STATUS_PATH = 'src/github.com/status-im/status-go'
CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
TARGET = 'linux'
STATUS_PATH = 'src/github.com/status-im/status-go'
GOPATH = "${env.WORKSPACE}"
PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin"
}
stages {
stage('Prep') { steps { script {
lib = load("${env.STATUS_PATH}/_assets/ci/lib.groovy")
/* clarify what we're building */
println("Version: ${lib.getVersion()}")
println("Git Branch: ${lib.gitBranch()}")
println("Git Commit: ${lib.gitCommit()}")
} } }
stage('Prep') { steps { dir(env.STATUS_PATH) { script {
println("Version: ${utils.getVersion()}")
println("Git Branch: ${utils.branchName()}")
println("Git Commit: ${utils.gitCommit()}")
} } } }
stage('Setup') { steps { dir(env.STATUS_PATH) {
sh 'GO111MODULE=off make setup-build modvendor-install'
@ -45,7 +44,7 @@ pipeline {
stage('Vendoring check') { steps { dir(env.STATUS_PATH) {
/* fail build if vendoring hasn't been done */
sh 'GO111MODULE=on make vendor && git diff --exit-code --no-color --stat vendor/'
} } } // stage(Vendoring check)
} } }
stage('Lint') { steps { dir(env.STATUS_PATH) {
sh 'make lint'

View File

@ -1,73 +0,0 @@
import groovy.json.JsonBuilder
def getRepoName() {
if (env.GIT_URL =~ /https?:\/\/[^\/]\/(.+)(\.git)?/) {
return m.group(1)
}
return env.GIT_URL.split('/').last().minus('.git')
}
/* if job was started by a parent we can access it's env */
def getParentRunEnv(name) {
def c = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)
if (c == null) { return null }
return c.getUpstreamRun().getEnvironment()[name]
}
/* returns duration of build in rounded up minutes */
def buildDuration() {
def duration = currentBuild.durationString
return '~' + duration.take(duration.lastIndexOf(' and counting'))
}
/* CHANGE_ID can be provided via the build parameters or from parent */
def changeId() {
def changeId = env.CHANGE_ID
changeId = params.CHANGE_ID ? params.CHANGE_ID : changeId
changeId = getParentRunEnv('CHANGE_ID') ? getParentRunEnv('CHANGE_ID') : changeId
if (!changeId) {
println('This build is not related to a PR, CHANGE_ID missing.')
println('GitHub notification impossible, skipping...')
return null
}
return changeId
}
/* assemble build object valid for ghcmgr */
def buildObj(success) {
return [
id: env.BUILD_DISPLAY_NAME,
commit: GIT_COMMIT.take(8),
success: success != null ? success : true,
platform: env.BUILD_PLATFORM,
duration: buildDuration(),
url: currentBuild.absoluteUrl,
pkg_url: env.PKG_URL,
]
}
/**
* This is our own service for avoiding comment spam.
* https://github.com/status-im/github-comment-manager
**/
def postBuild(success) {
def changeId = changeId()
if (changeId == null) { return } /* not in a PR build */
def ghcmgrUrl = 'https://ghcmgr.status.im'
def body = buildObj(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/${getRepoName()}/${changeId}'
"""
}
}
return this

View File

@ -1,92 +0,0 @@
def getVersion() {
return readFile("${env.STATUS_PATH}/VERSION").trim()
}
def gitCommit() {
return GIT_COMMIT.take(6)
}
def parentOrCurrentBuild() {
def c = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)
if (c == null) { return currentBuild }
return c.getUpstreamRun()
}
def timestamp() {
def now = new Date(parentOrCurrentBuild().timeInMillis)
return now.format('yyMMdd-HHmmss', TimeZone.getTimeZone('UTC'))
}
def suffix() {
if (params.RELEASE == true) {
return getVersion()
} else {
return "${timestamp()}-${gitCommit()}"
}
}
def gitBranch() {
return env.GIT_BRANCH.replace('origin/', '')
}
def getFilename(path) {
return path.tokenize('/')[-1]
}
def uploadArtifact(path) {
/* defaults for upload */
def domain = 'ams3.digitaloceanspaces.com'
def bucket = 'status-go'
withCredentials([usernamePassword(
credentialsId: 'digital-ocean-access-keys',
usernameVariable: 'DO_ACCESS_KEY',
passwordVariable: 'DO_SECRET_KEY'
)]) {
sh """
s3cmd \\
--acl-public \\
--host='${domain}' \\
--host-bucket='%(bucket)s.${domain}' \\
--access_key=${DO_ACCESS_KEY} \\
--secret_key=${DO_SECRET_KEY} \\
put ${path} s3://${bucket}/
"""
}
return "https://${bucket}.${domain}/${getFilename(path)}"
}
def buildBranch(name = null, buildType = null) {
/* need to drop origin/ to match definitions of child jobs */
def branchName = env.GIT_BRANCH.replace('origin/', '')
/* always pass the BRANCH and BUILD_TYPE params with current branch */
def resp = build(
job: name,
/* this allows us to analize the job even after failure */
propagate: false,
parameters: [
[name: 'BRANCH', value: branchName, $class: 'StringParameterValue'],
[name: 'RELEASE', value: params.RELEASE, $class: 'BooleanParameterValue'],
]
)
/* BlueOcean seems to not show child-build links */
println "Build: ${resp.getAbsoluteUrl()} (${resp.result})"
if (resp.result != 'SUCCESS') {
error("Build Failed")
}
return resp
}
def copyArts(build) {
/**
* The build argument is of class RunWrapper.
* https://javadoc.jenkins.io/plugin/workflow-support/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.html
**/
copyArtifacts(
projectName: build.fullProjectName,
target: 'out',
flatten: true,
selector: specific("${build.number}")
)
}
return this