@@ -6,18 +6,34 @@ def sovLibrary = library(identifier: 'sovrin-aws-codebuild@v1.0.1', retriever: m
66 github(credentialsId : ' sovbot-github' , repoOwner : ' sovrin-foundation' , repository : ' aws-codebuild-pipeline-plugin' )
77)). com. sovrin. pipeline
88
9+ def getParam (name ) {
10+ return (params. " $name " ?: env. " $name " )
11+ }
12+
13+ def getApprove (name ) {
14+ def approval
15+ try {
16+ input(message : ' Do you want to publish this package?' )
17+ approval = true
18+ echo " $name approval granted"
19+ }
20+ catch (Exception err) {
21+ approval = false
22+ echo " $name approval denied"
23+ }
24+ return approval
25+ }
26+
927logger = sovLibrary.Logger . new(this )
1028notifier = sovLibrary.Notifier . new(this )
29+ utils = sovLibrary.Utils . new(this )
1130logger. setGlobalLevel(' TRACE' )
1231
13- gitHubUserCredId = env. GITHUB_BOT_USER ?: ' sovbot-github'
14- sovrinPackagingRepo = env. SOVRIN_PACKAGING_REPO ?: ' https://github.com/sovrin-foundation/sovrin-packaging'
15- sovrinPackagingBranch = env. SOVRIN_PACKAGING_BRANCH ?: ' master'
16-
17- def downloadPackagingUtils () {
18- git branch : sovrinPackagingBranch, credentialsId : gitHubUserCredId, url : sovrinPackagingRepo
19- sh " pip3 install -U plumbum deb-pkg-tools"
20- }
32+ String gitHubUserCredId = getParam(' GITHUB_BOT_USER' ) ?: ' sovbot-github'
33+ String sovrinPackagingRepo = getParam(' env.SOVRIN_PACKAGING_REPO' ) ?: ' https://github.com/sovrin-foundation/sovrin-packaging'
34+ String sovrinPackagingBranch = getParam(' SOVRIN_PACKAGING_BRANCH' ) ?: ' master'
35+ String repoName = getParam(' SOVRIN_CORE_REPO_NAME' ) ?: ' core'
36+ String repoComponent = getParam(' SOVRIN_CORE_REPO_CHANNEL' ) ?: env. BRANCH_NAME ?: ' master'
2137
2238def nodeLabels = [
2339 codeBuild : env. LIBSOVTOKEN_CODEBUILD_NODE_LABEL ?: ' codebuild' ,
@@ -30,35 +46,71 @@ pipelineWrapper({
3046 // this IP is outdated, should use the one from env
3147// env.SOVRIN_REPO_HOST = '192.168.11.115'
3248
49+ Boolean isRC = false
50+ Boolean isRelease = false
51+ Boolean isDev = (env. BRANCH_NAME == ' master' )
52+ List pkgsList = []
53+ String debsDir = ' debs'
54+ String pkgUtilsDir = ' sovrin-packaging'
55+
56+ Closure _upload = {
57+ logger. info(" Uploading debian packages to '${ repoName} /${ repoComponent} ' sovrin repo: $pkgsList " )
58+ String u_id = utils. shStdout(' id -u' )
59+ docker. build(
60+ " $projectName :debs-upload" ,
61+ " --build-arg=u_id=$u_id -f devops/docker/cd/debs_upload.dockerfile devops/docker/cd"
62+ ). inside {
63+ withCredentials([file(credentialsId : ' SovrinRepoSSHKey' , variable : ' sovrin_key' )]) {
64+ sh """
65+ ./$pkgUtilsDir /upload_debs.py $debsDir $repoName $repoComponent --host $env . SOVRIN_REPO_HOST --ssh-key $sovrin_key
66+ """
67+ }
68+ }
69+ }
70+
71+ Closure _notify = {
72+ notifier. email {
73+ to = ' $DEFAULT_RECIPIENTS ' + (this . env. LIBSOVTOKEN_DEF_RECIPIENTS ?: ' ' )
74+ subject = " [$projectName ] new packages ${ pkgsList.join(' ')} published to '${ repoName} /${ repoComponent} ' repo"
75+ body = """
76+ |New debian packages ${ pkgsList.join(' ')} were built and published to '${ repoName} /${ repoComponent} ' repo
77+ |
78+ |Build:
79+ | Project: \$ PROJECT_NAME
80+ | Url: ${ this.env.BUILD_URL}
81+ | Number: ${ this.env.BUILD_NUMBER}
82+ |
83+ |Check console output at ${ this.env.BUILD_URL} console to view the details.
84+ """ . stripMargin()
85+ }
86+ }
87+
3388 nodeWrapper(nodeLabels. codeBuild) {
3489 def osname = ' xenial'
3590 List projects = [' sovtoken' , ' sovtokenfees' ]
36- List pkgsList = []
3791 String indyNodeVersion
38- Boolean isRC = false
39- Boolean isRelease = false
40- Boolean isDev = (env. BRANCH_NAME == ' master' )
41-
42- stage(' Checkout sources from SCM' ) {
43- checkout scm
44- }
4592
4693 def sovrinRepo = sovLibrary.SovrinRepo . new(this )
47- def utils = sovLibrary.Utils . new(this )
4894 def buildCtx = sovLibrary.AwsCodeBuildHelper.BuildCtx . new(' plugin' ,
4995 [' devops' , ' sovtoken/sovtoken/__metadata__.py' , ' sovtokenfees/sovtokenfees/__metadata__.py' ])
5096 def awsCBHelper = sovLibrary.AwsCodeBuildHelper . new(this , buildCtx)
5197
52- stage(' Get indy-node version' ) {
98+ stage(' Checkout sources from SCM' ) {
99+ checkout scm
100+ }
101+
102+ stage(' Set release params' ) {
53103 indyNodeVersion = utils. shStdout("""
54104 sed -n "s/.*indy-node==\\ ([^\\ "\\ ']\\ +\\ ).*/\\ 1/p" sovtoken/setup.py
55105 """ )
56106 if (! indyNodeVersion) {
57107 throw new Exception (' indy-node version is not found' )
58108 }
59- isRC = !! ((env. BRANCH_NAME == ' stable' ) && indyNodeVersion. find(/ [^0-9\. ]/ ))
60- isRelease = ((env. BRANCH_NAME == ' stable' ) && ! isRC)
61- logger. info(" Detected indy-node version: '$indyNodeVersion ', isRC: $isRC , isRelease: $isRelease " )
109+ logger. info(" Detected indy-node version: '$indyNodeVersion '" )
110+
111+ isRC = (env. BRANCH_NAME == ' stable' )
112+ isRelease = !! (isRC && ! indyNodeVersion. find(/ [^0-9\. ]/ ))
113+ logger. info(" Release parameters: isRC: $isRC , isRelease: $isRelease " )
62114 }
63115
64116 Map builds = [
@@ -102,20 +154,21 @@ pipelineWrapper({
102154 logger. info(" Current source version: $srcVersion " )
103155 }
104156
105- // stage('Get last revision') {
106- // lastRevision = evernymRepo.getLastRevision {
107- // delegate.packageName = packageName
108- // packageSrcVersion = srcVersion
109- // repoDistr = 'agency-dev'
110- // }
111- //
112- // if (lastRevision) {
113- // logger.info("Found last revision number: $lastRevision")
114- // } else {
115- // logger.info("No previous revision was found")
116- // }
117- // }
157+ /*
158+ stage('Get last revision') {
159+ lastRevision = evernymRepo.getLastRevision {
160+ delegate.packageName = packageName
161+ packageSrcVersion = srcVersion
162+ repoDistr = 'agency-dev'
163+ }
118164
165+ if (lastRevision) {
166+ logger.info("Found last revision number: $lastRevision")
167+ } else {
168+ logger.info("No previous revision was found")
169+ }
170+ }
171+ */
119172
120173 stage(' Set release parameters' ) {
121174 def releaseVersion = isRelease ? ' ' : (isRC ? ' rc' : isDev ? ' dev' : ' ' ) + " $BUILD_NUMBER "
@@ -158,14 +211,14 @@ pipelineWrapper({
158211
159212 onArtifacts = {
160213 this . stage(" $projLabel : Archive logs" ) {
161- utils. archiveArtifacts(" logs/*.log*" ) {
214+ this . utils. archiveArtifacts(" logs/*.log*" ) {
162215 truncate = true
163216 allowEmptyArchive = true
164217 }
165218
166219 String pkgBaseName = " ${ packageName} _${ debPVersion} "
167220
168- this . stash includes : utils. shStdout(" ls ${ pkgBaseName} _*.deb" ), name : pkgBaseName
221+ this . stash includes : this . utils. shStdout(" ls ${ pkgBaseName} _*.deb" ), name : pkgBaseName
169222 pkgsList + = pkgBaseName
170223 }
171224 }
@@ -177,48 +230,69 @@ pipelineWrapper({
177230 stage(" Build artifacts" ) {
178231 builds. failFast = false
179232 utils. parallel builds
180- }
181-
182- stage(' Release artifacts' ) {
183- String repoName = env. SOVRIN_CORE_REPO_NAME
184- String repoComponent = env. BRANCH_NAME
185- String debsDir = ' debs'
186-
187- if (isRC) {
188- repoComponent = ' rc'
189- }
190- logger. info(" Debian repo component is set to: '$repoComponent '" )
191233
192234 dir(debsDir) {
193235 pkgsList. each {
194236 unstash name : it
195237 }
196238 }
197- logger. info(" Uploading debian packages to '${ repoName} /${ repoComponent} ' sovrin repo: $pkgsList " )
239+ sh " ls -la $debsDir "
240+ }
198241
199- dir(" sovrin-packaging" ) {
200- downloadPackagingUtils()
242+ stage(" Get packaging utils" ) {
243+ dir(pkgUtilsDir) {
244+ git branch : sovrinPackagingBranch, credentialsId : gitHubUserCredId, url : sovrinPackagingRepo
201245 }
246+ }
202247
203- withCredentials([file(credentialsId : ' SovrinRepoSSHKey' , variable : ' sovrin_key' )]) {
204- sh " ./sovrin-packaging/upload_debs.py $debsDir $repoName $repoComponent --host $env . SOVRIN_REPO_HOST --ssh-key $sovrin_key --force-backup"
248+ if (isRC) {
249+ repoComponent = ' rc'
250+ }
251+
252+ stage(" Publish to $repoComponent " ) {
253+ _upload()
254+ if (isRelease) {
255+ stash includes : " $pkgUtilsDir /**/*" , name : pkgUtilsDir
256+ stash includes : " $debsDir /**/*" , name : debsDir
257+ }
258+ }
259+ }
260+
261+ stage(" Notify about $repoComponent " ) {
262+ _notify()
263+ }
264+
265+ if (isRelease) {
266+ Boolean approval = false
267+ repoComponent = ' stable'
268+
269+ stage(" QA approval" ) {
270+ approval = getApprove(" QA" )
271+ }
272+
273+ if (! approval) {
274+ return
275+ }
276+
277+ nodeWrapper(' ubuntu' ) {
278+ stage(' Checkout sources from SCM' ) {
279+ checkout scm
205280 }
206281
207- notifier. email {
208- to = ' $DEFAULT_RECIPIENTS ' + (this . env. LIBSOVTOKEN_DEF_RECIPIENTS ?: ' ' )
209- subject = " [$projectName ] new packages ${ pkgsList.join(' ')} published to '${ repoName} /${ repoComponent} ' repo"
210- body = """
211- |New debian packages ${ pkgsList.join(' ')} were built and published to '${ repoName} /${ repoComponent} ' repo
212- |
213- |Build:
214- | Project: \$ PROJECT_NAME
215- | Url: ${ this.env.BUILD_URL}
216- | Number: ${ this.env.BUILD_NUMBER}
217- |
218- |Check console output at ${ this.env.BUILD_URL} console to view the details.
219- """ . stripMargin()
282+ // Note. it is assumed here that packages are already in a backup
283+ // directory and their upload would be actually skipped since '--force-backup'
284+ // is not used
285+ stage(" Publish to $repoComponent " ) {
286+ unstash pkgUtilsDir
287+ unstash debsDir
288+
289+ _upload()
220290 }
221291 }
292+
293+ stage(" Notify about $repoComponent " ) {
294+ _notify()
295+ }
222296 }
223297}, { err ->
224298 if (err) {
0 commit comments