-
Notifications
You must be signed in to change notification settings - Fork 54
/
release.gradle
542 lines (473 loc) · 20.3 KB
/
release.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.amazonaws:aws-java-sdk:1.7.8.1'
}
}
import com.amazonaws.*
import com.amazonaws.auth.AWSCredentials
import com.amazonaws.auth.AWSCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model.*
import java.text.SimpleDateFormat
def getSdkBasedPackageNames() {
def packageNames = []
packageNames << "sdk"
packageNames.addAll(getMaridBasedPackageNames())
return packageNames
}
def getLampBasedPackageNames() {
return ["lamp"]
}
def getMaridBasedPackageNames() {
return ["marid",
"nagios",
"nagiosMarid",
"nagiosxi",
"icinga",
"icingaMarid",
"redmine",
"netcool",
"zabbix",
"zabbixMarid",
"zenoss",
"zendesk",
"icinga2",
"icinga2Marid",
"xmpp",
"solarwinds",
"solarwindsmspncentral",
"solarwindswebhelpdesk",
"webex",
"dynatraceappmon",
"jira",
"jiraServiceDesk",
"op5",
"bmcRemedy",
"bmcRemedyMarid",
"librenms",
"prtg",
"zenossMarid",
"bmcFootPrintsV12",
"bmcFootPrintsV12Marid",
"bmcFootPrintsV11",
"bmcFootPrintsV11Marid",
"cherwell"
]
}
def generateDownloadsProperties() {
copy {
from getDownloadsTemplate()
filter {
it.replace('[[sdk]]', project.ext.versions.getProperty('sdk'))
.replace('[[lamp]]', project.ext.versions.getProperty('lamp'))
.replace('[[marid]]', project.ext.versions.getProperty('marid'))
.replace('[[nagios]]', project.ext.versions.getProperty('nagios'))
.replace('[[nagiosIncoming]]', project.ext.versions.getProperty('nagiosIncoming'))
.replace('[[nagiosMarid]]', project.ext.versions.getProperty('nagiosMarid'))
.replace('[[nagiosxi]]', project.ext.versions.getProperty('nagiosxi'))
.replace('[[nagiosxiIncoming]]', project.ext.versions.getProperty('nagiosxiIncoming'))
.replace('[[nagiosxiMarid]]', project.ext.versions.getProperty('nagiosxiMarid'))
.replace('[[icinga]]', project.ext.versions.getProperty('icinga'))
.replace('[[icingaIncoming]]', project.ext.versions.getProperty('icingaIncoming'))
.replace('[[icingaMarid]]', project.ext.versions.getProperty('icingaMarid'))
.replace('[[icinga2]]', project.ext.versions.getProperty('icinga2'))
.replace('[[icinga2Incoming]]', project.ext.versions.getProperty('icinga2Incoming'))
.replace('[[icinga2Marid]]', project.ext.versions.getProperty('icinga2Marid'))
.replace('[[redmine]]', project.ext.versions.getProperty('redmine'))
.replace('[[netcool]]', project.ext.versions.getProperty('netcool'))
.replace('[[zabbix]]', project.ext.versions.getProperty('zabbix'))
.replace('[[zabbixIncoming]]', project.ext.versions.getProperty('zabbixIncoming'))
.replace('[[zabbixMarid]]', project.ext.versions.getProperty('zabbixMarid'))
.replace('[[zenossIncoming]]', project.ext.versions.getProperty('zenossIncoming'))
.replace('[[zenossMarid]]', project.ext.versions.getProperty('zenossMarid'))
.replace('[[zenoss]]', project.ext.versions.getProperty('zenoss'))
.replace('[[zendesk]]', project.ext.versions.getProperty('zendesk'))
.replace('[[solarwinds]]', project.ext.versions.getProperty('solarwinds'))
.replace('[[solarwindsmspncentral]]', project.ext.versions.getProperty('solarwindsmspncentral'))
.replace('[[solarwindswebhelpdesk]]', project.ext.versions.getProperty('solarwindswebhelpdesk'))
.replace('[[oem]]', project.ext.versions.getProperty('oem'))
.replace('[[vcenter]]', project.ext.versions.getProperty('vcenter'))
.replace('[[xmpp]]', project.ext.versions.getProperty('xmpp'))
.replace('[[trackit]]', project.ext.versions.getProperty('trackit'))
.replace('[[webex]]', project.ext.versions.getProperty('webex'))
.replace('[[jira]]', project.ext.versions.getProperty('jira'))
.replace('[[jiraServiceDesk]]', project.ext.versions.getProperty('jiraServiceDesk'))
.replace('[[prtg]]', project.ext.versions.getProperty('prtg'))
.replace('[[dynatraceappmon]]', project.ext.versions.getProperty('dynatraceappmon'))
.replace('[[op5]]', project.ext.versions.getProperty('op5'))
.replace('[[bmcRemedy]]', project.ext.versions.getProperty('bmcRemedy'))
.replace('[[bmcRemedyIncoming]]', project.ext.versions.getProperty('bmcRemedyIncoming'))
.replace('[[bmcRemedyMarid]]', project.ext.versions.getProperty('bmcRemedyMarid'))
.replace('[[vcsa]]', project.ext.versions.getProperty('vcsa'))
.replace('[[librenms]]', project.ext.versions.getProperty('librenms'))
.replace('[[opsview]]', project.ext.versions.getProperty('opsview'))
.replace('[[bmcFootPrintsV12Incoming]]', project.ext.versions.getProperty('bmcFootPrintsV12Incoming'))
.replace('[[bmcFootPrintsV12Marid]]', project.ext.versions.getProperty('bmcFootPrintsV12Marid'))
.replace('[[bmcFootPrintsV12]]', project.ext.versions.getProperty('bmcFootPrintsV12'))
.replace('[[bmcFootPrintsV11]]', project.ext.versions.getProperty('bmcFootPrintsV11'))
.replace('[[bmcFootPrintsV11Incoming]]', project.ext.versions.getProperty('bmcFootPrintsV11Incoming'))
.replace('[[bmcFootPrintsV11Marid]]', project.ext.versions.getProperty('bmcFootPrintsV11Marid'))
.replace('[[cherwell]]', project.ext.versions.getProperty('cherwell'))
.replace('[[activeDirectory]]', project.ext.versions.getProperty('activeDirectory'))
.replace('[[opsviewv6]]', project.ext.versions.getProperty('opsviewv6'))
}
into "${buildDir}/distributions"
rename "downloads.template.properties", "downloads.properties"
}
}
task generateDownloadsProperties << {
generateDownloadsProperties()
}
def getUploadOptions() {
def options
if(project.hasProperty('options')) {
options = project.options;
} else {
options = "${projectDir}/uploadOptions.properties";
}
Properties properties = new Properties();
properties.load(new FileInputStream(options))
return properties
}
def getAWSClient() {
def props = getUploadOptions()
def amazonAccessKey = props.getProperty('amazonAccessKey')
def amazonSecretKey = props.getProperty('amazonSecretKey')
def amazonConnectionTimeout = Integer.valueOf(props.getProperty('amazonConnectionTimeout'))
def amazonMaxConnections = Integer.valueOf(props.getProperty('amazonMaxConnections'))
def amazonMaxErrorRetry = Integer.valueOf(props.getProperty('amazonMaxErrorRetry'))
AWSCredentialsProvider provider;
if (amazonAccessKey != null && amazonSecretKey != null) {
provider = new StaticCredentialsProvider( new BasicAWSCredentials(amazonAccessKey, amazonSecretKey));
} else {
provider = new DefaultAWSCredentialsProviderChain();
}
ClientConfiguration clientConfiguration = new ClientConfiguration()
clientConfiguration.setConnectionTimeout(amazonConnectionTimeout);
clientConfiguration.setMaxConnections(amazonMaxConnections);
clientConfiguration.setMaxErrorRetry(amazonMaxErrorRetry);
AmazonS3 client = new AmazonS3Client(provider, clientConfiguration)
client.setEndpoint("s3-us-west-2.amazonaws.com")
return client
}
def createDownloadBucketIfNonExist() {
def props = getUploadOptions()
def downloadsBucket = props.getProperty('amazonDownloadsBucket')
createBucketIfNonExist(downloadsBucket)
}
def createBucketIfNonExist(String bucketName) {
def client = getAWSClient()
if (!client.doesBucketExist(bucketName)) {
println "[RELEASE] Bucket $bucketName not exist. Creating new One!"
//This will not run for prod account , prod buckets need to created from another place , jenkins is not secure to have a create bucket access key
client.createBucket(bucketName)
}
}
def uploadJavaDocToS3() {
def client = getAWSClient()
def props = getUploadOptions()
def javadocBucket = props.getProperty('amazonDownloadsBucket')
def folderName = "java-sdk-doc/"
println '[Release] Deleting existing JavaDoc'
ObjectListing objects = client.listObjects(new ListObjectsRequest().withBucketName(javadocBucket).withPrefix(folderName));
List<S3ObjectSummary> objectSummaries = objects.getObjectSummaries();
for (S3ObjectSummary next : objectSummaries) {
client.deleteObject(new DeleteObjectRequest(next.getBucketName(), next.getKey()));
}
println '[Release] Deleting existing JavaDoc - Finished'
println '[Release] Started to upload JavaDoc'
client.setBucketWebsiteConfiguration(javadocBucket, new BucketWebsiteConfiguration("index.html"))
FileTree javadoc = fileTree(dir: "${project(':sdk').buildDir}/docs/all")
javadoc.each { File file ->
println("Uploading " + file.getAbsolutePath() + " to bucket [${javadocBucket}/${folderName}] with path ${directoryPath}")
def directoryPath = ''
if (project.hasProperty('testMode')) {
println('It is going to be test release')
directoryPath += 'test/'
}
fileName = file.getCanonicalPath().replace("${project(':sdk').buildDir}/docs/all/", folderName)
PutObjectRequest request = new PutObjectRequest(javadocBucket, directoryPath + fileName, file)
request.setCannedAcl(CannedAccessControlList.PublicRead)
client.putObject(request)
}
println '[Release] Started to upload JavaDoc - Finished'
}
def uploadMaridPackagesToS3() {
def client = getAWSClient()
def props = getUploadOptions()
def downloadsBucket = props.getProperty('amazonDownloadsBucket')
FileTree packages = fileTree(dir: "${project(':marid').buildDir}/distributions")
packages.include '*.zip'
packages.include '*.deb'
packages.include '*.rpm'
println '[Release] Started to upload client packages'
packages.each { File file ->
def directoryPath = ''
if (project.hasProperty('testMode')) {
println('It is going to be test release')
directoryPath += 'test/'
}
directoryPath += 'repo/'
println("Uploading " + file.getAbsolutePath() + " to " + "bucket [${downloadsBucket}] with path ${directoryPath}")
PutObjectRequest request = new PutObjectRequest(downloadsBucket, directoryPath + "${file.getName()}", file)
request.setCannedAcl(CannedAccessControlList.PublicRead)
client.putObject(request)
}
println '[Release] Started to upload client packages - Finished'
}
def uploadSdkPackageToS3() {
def client = getAWSClient()
def props = getUploadOptions()
def downloadsBucket = props.getProperty('amazonDownloadsBucket')
println '[Release] Started to upload opsgenie-java-sdk'
FileTree sdk = fileTree(dir: "${buildDir}/distributions")
sdk.include 'opsgenie-java-sdk**'
sdk.each { File file ->
def directoryPath = ''
if (project.hasProperty('testMode')) {
println('It is going to be test release')
directoryPath += 'test/'
}
directoryPath += 'repo/'
println("Uploading " + file.getAbsolutePath() + " to " + "bucket [${downloadsBucket}] with path ${directoryPath}")
PutObjectRequest request = new PutObjectRequest(downloadsBucket, directoryPath + "${directoryPath}${file.getName()}", file)
request.setCannedAcl(CannedAccessControlList.PublicRead)
client.putObject(request)
}
println '[Release] Started to upload opsgenie-java-sdk - Finished'
}
def uploadIntegrationsToS3() {
def client = getAWSClient()
def props = getUploadOptions()
def downloadsBucket = props.getProperty('amazonDownloadsBucket')
FileTree integrations = fileTree(dir: "${buildDir}/distributions")
integrations.include '*.zip'
integrations.include '*.deb'
integrations.include '*.rpm'
integrations.exclude 'opsgenie-java-sdk**'
println '[Release] Started to upload integration packages'
integrations.each { File file ->
def directoryPath = ''
if (project.hasProperty('testMode')) {
println('It is going to be test release')
directoryPath += 'test/'
}
directoryPath += 'repo/'
println("Uploading " + file.getAbsolutePath() + " to " + "bucket [${downloadsBucket}] with path ${directoryPath}" )
PutObjectRequest request = new PutObjectRequest(downloadsBucket, directoryPath + "${file.getName()}", file)
request.setCannedAcl(CannedAccessControlList.PublicRead)
client.putObject(request)
}
println '[Release] Started to upload integration packages - Finished'
}
def uploadDownloadsPropertiesToS3() {
def client = getAWSClient()
def props = getUploadOptions()
def downloadsBucket = props.getProperty('amazonDownloadsBucket')
def file = file("${buildDir}/distributions/downloads.properties")
println '[Release] Started to upload download.properties'
logger.info("Uploading " + file.getAbsolutePath())
def directoryPath = ''
if (project.hasProperty('testMode')) {
println('It is going to be test release')
directoryPath += 'test/'
}
PutObjectRequest request = new PutObjectRequest(downloadsBucket, directoryPath + "${file.getName()}", file)
request.setCannedAcl(CannedAccessControlList.PublicRead)
client.putObject(request)
println '[Release] Started to upload download.properties - finished'
}
def getIncreasedBugfix(String version) {
String[] versions = version.split('\\.')
int bugfix = Integer.valueOf(versions[2]) + 1
return versions[0] + "." + versions[1] + "." + bugfix
}
def getIncreasedMinor(String version) {
String[] versions = version.split("\\.")
int minor = Integer.valueOf(versions[1]) + 1
return versions[0] + "." + minor + ".0"
}
def getIncreasedMajor(String version) {
String[] versions = version.split("\\.")
int major = Integer.valueOf(versions[0]) + 1
return major + ".0.0"
}
def increaseVersion(String type) {
def args
if(!project.hasProperty('args')) {
println "You must add integrations e.g -Pargs=redmine,nagios"
}
args = project.args.split(',')
Set versionNames = []
Properties versions = project.ext.versions
if (args.contains("all")) {
versionNames.addAll(versions.stringPropertyNames())
} else {
if (args.contains("sdk")) {
versionNames.addAll(getSdkBasedPackageNames())
}
if(args.contains("marid")) {
versionNames.addAll(getMaridBasedPackageNames())
}
if(args.contains("lamp")) {
versionNames.addAll(getLampBasedPackageNames())
}
versionNames.addAll(args)
}
increaseVersions(type, versionNames);
}
def increaseVersions(String type, Set versionNames) {
Properties versions = project.ext.versions
versions.store(new FileOutputStream("${projectDir}/version.old.properties"), "")
for (String integration : versionNames) {
String oldVersion = versions.getProperty(integration)
if(oldVersion == null) {
throw new TaskExecutionException(tasks.release, new Exception(integration +" does not exist! "))
}
String newVersion = oldVersion;
if(type.equals("bugfix")) {
newVersion = getIncreasedBugfix(oldVersion)
} else if (type.equals("minor")) {
newVersion = getIncreasedMinor(oldVersion)
} else if(type.equals("major")) {
newVersion = getIncreasedMajor(oldVersion)
}
versions.setProperty(integration, newVersion)
}
println "${type} versions increased for ${versionNames}!"
versions.store(new FileOutputStream("${projectDir}/version.properties"), "")
}
task newMinor << {
increaseVersion('minor')
}
task newMajor << {
increaseVersion('major')
}
def updateGit(def args) {
def date = new Date()
def sdf = new SimpleDateFormat("yyyy.MM.dd-HH.mm.ss.SSSS")
exec {
commandLine './updateGit.sh', projectDir, "${project(":sdk").projectDir}/..",
"Version test bump for ${args}", "OpsGenieClient-v2-${sdf.format(date)}-1"
}
}
def resetGit(def args) {
exec {
commandLine './resetGit.sh'
}
}
def versionUpdate(def type) {
if(type.equals("minor") || type.equals("major") || type.equals("bugfix")) {
increaseVersion(type)
return true
} else {
println "=======[VERSION UPDATE SKIPPED]========"
return false
}
}
//DUMMY TASK ONLY TO REMOVE SNAPSHOT from version
task removeSnapshot << {
}
def getDownloadsTemplate() {
def downloadsFile
if(project.hasProperty("downloads")) {
downloadsFile = project.downloads
} else {
downloadsFile = "${project.projectDir}/downloads.template.properties"
}
return downloadsFile
}
def isReleaseForAll() {
def args = project.args.toString().split('\\,')
return args.contains('all')
}
def isReleaseForSdk() {
def args = project.args.toString().split('\\,')
return args.contains('sdk')
}
def isReleaseForMarid(){
def args = project.args.toString().split('\\,')
return args.contains('marid')
}
def generateReleaseTasks() {
Set tasks = ['removeSnapshot', 'clean']
if(!project.hasProperty('args')) {
throw new IllegalArgumentException("Please give integrations as args to release! E.g. gradle release -Pargs=nagios,redmine")
}
boolean testMode = project.hasProperty('testMode');
Set args = project.args.toString().split('\\,')
if(isReleaseForAll()) {
tasks << 'packageAll'
tasks << 'packageSdk'
if (!testMode) {
tasks << 'uploadArchives'
}
}else{
if(isReleaseForSdk()){
args.addAll(getSdkBasedPackageNames())
if (!testMode) {
tasks << 'uploadArchives'
}
}
if(isReleaseForMarid()){
args.addAll(getMaridBasedPackageNames())
}
if(isReleaseForLamp()) {
args.addAll(getLampBasedPackageNames())
}
for(String integration : args) {
String taskName = "package${Character.toUpperCase(integration.charAt(0))}${integration.substring(1)}"
tasks << taskName
}
}
return tasks
}
def isReleaseForLamp() {
def args = project.args.toString().split('\\,')
return args.contains('lamp')
}
def createPropertiesToUploadToNexus() {
copy {
from project.options
into buildDir
}
}
task release(type: GradleBuild ) {
def isVersionUpdated = false;
boolean testMode = project.hasProperty('testMode');
if (testMode) {
print "TEST_MODE IS ACTIVATED!"
}
doFirst {
if (project.hasProperty("type")) {
isVersionUpdated = versionUpdate(project.type);
}
tasks = generateReleaseTasks();
createPropertiesToUploadToNexus();
}
doLast {
generateDownloadsProperties()
createDownloadBucketIfNonExist()
uploadIntegrationsToS3()
if (isReleaseForAll() || isReleaseForSdk()) {
uploadSdkPackageToS3()
//uploadJavaDocToS3()
uploadMaridPackagesToS3()
} else if (isReleaseForMarid()) {
uploadMaridPackagesToS3()
}
uploadDownloadsPropertiesToS3()
if (isVersionUpdated && !testMode) {
updateGit(project.args)
} else if (testMode) {
resetGit()
}
}
}