build regular linux binary with xgo for uploading to GitHub

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-04-12 12:50:14 +02:00 committed by Jakub
parent a904d9325e
commit 2af27dc6b3
8 changed files with 145 additions and 39 deletions

View File

@ -3,8 +3,9 @@
RELEASE_TAG := $(shell cat VERSION) RELEASE_TAG := $(shell cat VERSION)
RELEASE_BRANCH := "develop" RELEASE_BRANCH := "develop"
RELEASE_DIRECTORY := /tmp/release-$(RELEASE_TAG) RELEASE_DIR := /tmp/release-$(RELEASE_TAG)
PRE_RELEASE := "1" PRE_RELEASE := "1"
RELEASE_TYPE := $(shell if [ $(PRE_RELEASE) = "0" ] ; then echo release; else echo pre-release ; fi)
help: ##@other Show this help help: ##@other Show this help
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST) @perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
@ -55,6 +56,9 @@ DOCKER_IMAGE_CUSTOM_TAG ?= $(RELEASE_TAG)
DOCKER_TEST_WORKDIR = /go/src/github.com/status-im/status-go/ DOCKER_TEST_WORKDIR = /go/src/github.com/status-im/status-go/
DOCKER_TEST_IMAGE = golang:1.10 DOCKER_TEST_IMAGE = golang:1.10
XGO_NAME ?= status-go
XGO_TARGETS ?= linux/amd64,windows/amd64,darwin/amd64
# This is a code for automatic help generator. # This is a code for automatic help generator.
# It supports ANSI colors and categories. # It supports ANSI colors and categories.
# To add new item into help output, simply add comments # To add new item into help output, simply add comments
@ -122,10 +126,13 @@ statusgo-ios: ##@cross-compile Build status-go for iOS
@gomobile bind -target=ios -ldflags="-s -w" $(BUILD_FLAGS) -o build/bin/Statusgo.framework github.com/status-im/status-go/mobile @gomobile bind -target=ios -ldflags="-s -w" $(BUILD_FLAGS) -o build/bin/Statusgo.framework github.com/status-im/status-go/mobile
@echo "iOS framework cross compilation done in build/bin/Statusgo.framework" @echo "iOS framework cross compilation done in build/bin/Statusgo.framework"
statusgo-linux: xgo ##@cross-compile Build status-go for Linux statusgo-xgo: xgo-install ##@cross-compile Build status-go for xgo targets
./_assets/patches/patcher -b . -p geth-xgo $(GOPATH)/bin/xgo -v \
$(GOPATH)/bin/xgo --image $(XGOIMAGE) --go=$(XGO_GO) -out statusgo --dest=$(GOBIN) --targets=linux/amd64 -v -tags '$(BUILD_TAGS)' $(BUILD_FLAGS) ./cmd/statusd -out=$(XGO_NAME) \
./_assets/patches/patcher -b . -p geth-xgo -r -dest=$(GOBIN) \
-targets=$(XGO_TARGETS) \
-tags '$(BUILD_TAGS)' \
$(BUILD_FLAGS) ./cmd/statusd
@echo "Linux cross compilation done." @echo "Linux cross compilation done."
statusgo-library: ##@cross-compile Build status-go as static library for current platform statusgo-library: ##@cross-compile Build status-go as static library for current platform
@ -201,28 +208,37 @@ generate: ##@other Regenerate assets and other auto-generated stuff
$(shell cd ./services/shhext/chat && exec protoc --go_out=. ./*.proto) $(shell cd ./services/shhext/chat && exec protoc --go_out=. ./*.proto)
prepare-release: clean-release prepare-release: clean-release
mkdir -p $(RELEASE_DIRECTORY) mkdir -p $(RELEASE_DIR)
mv build/bin/statusgo.aar $(RELEASE_DIRECTORY)/status-go-android.aar mv build/bin/statusgo.aar $(RELEASE_DIR)/status-go-android.aar
zip -r build/bin/Statusgo.framework.zip build/bin/Statusgo.framework zip -r build/bin/Statusgo.framework.zip build/bin/Statusgo.framework
mv build/bin/Statusgo.framework.zip $(RELEASE_DIRECTORY)/status-go-ios.zip mv build/bin/Statusgo.framework.zip $(RELEASE_DIR)/status-go-ios.zip
zip -r $(RELEASE_DIRECTORY)/status-go-desktop.zip . -x *.git* zip -r $(RELEASE_DIR)/status-go-desktop.zip . -x *.git*
${MAKE} clean ${MAKE} clean
clean-release: clean-release:
rm -rf $(RELEASE_DIRECTORY) rm -rf $(RELEASE_DIR)
release: release:
@read -p "Are you sure you want to create a new GitHub $(shell if [ $(PRE_RELEASE) = "0" ] ; then echo release; else echo pre-release ; fi) against $(RELEASE_BRANCH) branch? (y/n): " REPLY; \ @read -p "Are you sure you want to create a new GitHub $(RELEASE_TYPE} against $(RELEASE_BRANCH) branch? (y/n): " REPLY; \
if [ $$REPLY = "y" ]; then \ if [ $$REPLY = "y" ]; then \
latest_tag=$$(git describe --tags `git rev-list --tags --max-count=1`); \ latest_tag=$$(git describe --tags `git rev-list --tags --max-count=1`); \
comparison="$$latest_tag..HEAD"; \ comparison="$$latest_tag..HEAD"; \
if [ -z "$$latest_tag" ]; then comparison=""; fi; \ if [ -z "$$latest_tag" ]; then comparison=""; fi; \
changelog=$$(git log $$comparison --oneline --no-merges --format="* %h %s"); \ changelog=$$(git log $$comparison --oneline --no-merges --format="* %h %s"); \
github-release $(shell if [ $(PRE_RELEASE) != "0" ] ; then echo "-prerelease" ; fi) "status-im/status-go" "v$(RELEASE_TAG)" "$(RELEASE_BRANCH)" "$(changelog)" "$(RELEASE_DIRECTORY)/*" ; \ github-release \
$(shell if [ $(PRE_RELEASE) != "0" ] ; then echo "-prerelease" ; fi) \
"status-im/status-go" \
"v$(RELEASE_TAG)" \
"$(RELEASE_BRANCH)" \
"$(changelog)" \
"$(RELEASE_DIR)/*" ; \
else \ else \
echo "Aborting." && exit 1; \ echo "Aborting." && exit 1; \
fi fi
xgo-install:
go get -u github.com/karalabe/xgo
gomobile-install: gomobile-install:
go get -u golang.org/x/mobile/cmd/gomobile go get -u golang.org/x/mobile/cmd/gomobile

View File

@ -31,7 +31,7 @@ pipeline {
GOPATH = "${env.WORKSPACE}" GOPATH = "${env.WORKSPACE}"
PATH = "${env.PATH}:${env.GOPATH}/bin" PATH = "${env.PATH}:${env.GOPATH}/bin"
/* This will override the var in Makefile */ /* This will override the var in Makefile */
RELEASE_DIRECTORY = "${env.WORKSPACE}/pkg" RELEASE_DIR = "${env.WORKSPACE}/pkg"
} }
stages { stages {
@ -64,16 +64,19 @@ pipeline {
stage('Docker') { steps { script { stage('Docker') { steps { script {
dock = lib.buildBranch('status-go/platforms/docker') dock = lib.buildBranch('status-go/platforms/docker')
} } } } } }
stage('XGO') { steps { script {
xgo = lib.buildBranch('status-go/platforms/xgo')
} } }
} // parallel } // parallel
} // stage(Build) } // stage(Build)
stage('Archive') { stage('Archive') {
steps { script { steps { script {
sh("rm -fr ${env.RELEASE_DIRECTORY}/*") sh("rm -fr ${env.RELEASE_DIR}/*")
lib.copyArts('status-go/platforms/ios', ios.number) [ios, android, linux, xgo].each { platformBuild ->
lib.copyArts('status-go/platforms/android', android.number) lib.copyArts(platformBuild)
lib.copyArts('status-go/platforms/linux', linux.number) }
dir(env.RELEASE_DIRECTORY) { dir(env.RELEASE_DIR) {
/* generate sha256 checksums for upload */ /* generate sha256 checksums for upload */
sh 'sha256sum * | tee checksum.sha256' sh 'sha256sum * | tee checksum.sha256'
archiveArtifacts('*') archiveArtifacts('*')
@ -82,12 +85,13 @@ pipeline {
} // stage(Archive) } // stage(Archive)
stage('Release') { when { expression { params.RELEASE == true } } stage('Release') { when { expression { params.RELEASE == true } }
steps { steps { script {
/* rename build files to not include versions */ /* rename build files to not include versions */
dir(env.RELEASE_DIRECTORY) { dir(env.RELEASE_DIR) {
sh 'mv status-go-ios-*.zip status-go-ios.zip' def pkgs = findFiles(glob: 'status-go-*')
sh 'mv status-go-android-*.aar status-go-android.aar' pkgs.each { pkg ->
sh 'mv status-go-desktop-*.zip status-go-desktop.zip' sh "mv ${pkg.path} ${pkg.path.replace("-"+lib.suffix(), "")}"
}
} }
/* perform the release */ /* perform the release */
dir(env.STATUS_PATH) { dir(env.STATUS_PATH) {
@ -97,14 +101,12 @@ pipeline {
usernameVariable: 'GITHUB_USER', usernameVariable: 'GITHUB_USER',
passwordVariable: 'GITHUB_TOKEN' passwordVariable: 'GITHUB_TOKEN'
]]) { ]]) {
sh """ env.RELEASE_BRANCH = lib.gitBranch()
yes | make release \ env.RELEASE_DIR = env.RELEASE_DIR
RELEASE_BRANCH=${lib.gitBranch()} \ sh 'yes | make release'
RELEASE_DIRECTORY=${env.RELEASE_DIRECTORY}
"""
}
} }
} }
} }
} // stage(Release) } // stage(Release)
stage('Cleanup') { steps { dir(env.STATUS_PATH) { stage('Cleanup') { steps { dir(env.STATUS_PATH) {

View File

@ -28,7 +28,7 @@ pipeline {
environment { environment {
BUILD_PLATFORM = 'android' BUILD_PLATFORM = 'android'
STATUS_PATH = 'src/github.com/status-im/status-go' STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci" CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}" GOPATH = "${env.WORKSPACE}"
PATH = "${env.PATH}:${env.GOPATH}/bin" PATH = "${env.PATH}:${env.GOPATH}/bin"

View File

@ -27,7 +27,7 @@ pipeline {
} }
environment { environment {
STATUS_PATH = 'src/github.com/status-im/status-go' STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci" CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}" GOPATH = "${env.WORKSPACE}"
PATH = "${env.PATH}:${env.GOPATH}/bin" PATH = "${env.PATH}:${env.GOPATH}/bin"

View File

@ -28,7 +28,7 @@ pipeline {
environment { environment {
BUILD_PLATFORM = 'ios' BUILD_PLATFORM = 'ios'
STATUS_PATH = 'src/github.com/status-im/status-go' STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci" CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}" GOPATH = "${env.WORKSPACE}"
PATH = "${env.PATH}:${env.GOPATH}/bin" PATH = "${env.PATH}:${env.GOPATH}/bin"

View File

@ -28,7 +28,7 @@ pipeline {
environment { environment {
BUILD_PLATFORM = 'linux' BUILD_PLATFORM = 'linux'
STATUS_PATH = 'src/github.com/status-im/status-go' STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci" CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}" GOPATH = "${env.WORKSPACE}"
PATH = "${env.PATH}:${env.GOPATH}/bin" PATH = "${env.PATH}:${env.GOPATH}/bin"

View File

@ -0,0 +1,79 @@
pipeline {
agent { label 'linux' }
parameters {
string(
name: 'BRANCH',
defaultValue: 'publis-status-go-bin',
description: 'Name of branch to build.'
)
booleanParam(
name: 'RELEASE',
defaultValue: false,
description: 'Enable to create build for release.',
)
}
options {
timestamps()
disableConcurrentBuilds()
/* Go requires a certain directory structure */
checkoutToSubdirectory('src/github.com/status-im/status-go')
/* manage how many builds we keep */
buildDiscarder(logRotator(
numToKeepStr: '30',
daysToKeepStr: '30',
))
}
environment {
BUILD_PLATFORM = 'xgo'
STATUS_PATH = "${env.WORKSPACE}/src/github.com/status-im/status-go"
CI_DIR = "${env.STATUS_PATH}/_assets/ci"
GOPATH = "${env.WORKSPACE}"
PATH = "${env.PATH}:${env.GOPATH}/bin"
GOCACHE = "off"
}
stages {
stage('Prep') {
steps { script { dir(env.STATUS_PATH) {
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()}")
/* prepare dependencies */
sh 'make xgo-install'
} } }
}
stage('Build') {
steps { script { dir(env.STATUS_PATH) {
sh 'make statusgo-xgo'
/* append timestamp and commit to names */
def results = findFiles(glob: 'build/bin/status-go-*')
results.each { file ->
def newName = file.path.replace("amd64", "amd64-${lib.suffix()}")
sh "mv ${file.path} ${newName}"
}
} } }
}
stage('Archive') {
steps { dir(env.STATUS_PATH) {
archiveArtifacts('build/bin/status-go-*')
} }
}
stage('Upload') { steps { dir(env.STATUS_PATH) { script {
def binaries = findFiles(glob: 'build/bin/status-go-*')
binaries.each { binary -> lib.uploadArtifact(binary.path) }
} } } }
}
post {
success { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(true) } }
failure { script { load("${CI_DIR}/ghcmgr.groovy").postBuild(false) } }
} // post
}

View File

@ -1,13 +1,19 @@
def getVersion() { def getVersion() {
return readFile("${env.WORKSPACE}/${env.STATUS_PATH}/VERSION").trim() return readFile("${env.STATUS_PATH}/VERSION").trim()
} }
def gitCommit() { def gitCommit() {
return GIT_COMMIT.take(6) 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 timestamp() {
def now = new Date(currentBuild.timeInMillis) def now = new Date(parentOrCurrentBuild().timeInMillis)
return now.format('yyMMdd-HHmmss', TimeZone.getTimeZone('UTC')) return now.format('yyMMdd-HHmmss', TimeZone.getTimeZone('UTC'))
} }
@ -74,14 +80,17 @@ def buildBranch(name = null, buildType = null) {
return resp return resp
} }
def copyArts(projectName, buildNo) { 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( copyArtifacts(
projectName: projectName, projectName: build.fullProjectName,
target: 'pkg', target: 'pkg',
flatten: true, flatten: true,
selector: specific("${buildNo}") selector: specific("${build.number}")
) )
} }
return this return this