forked from apache/geronimo-yoko
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild-release.gradle
More file actions
688 lines (561 loc) · 23.5 KB
/
build-release.gradle
File metadata and controls
688 lines (561 loc) · 23.5 KB
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
/*
* Copyright 2026 IBM Corporation and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Release configuration for Yoko project
*
* This file provides Gradle tasks for creating GitHub releases with binaries.
* Usage:
* ./gradlew assembleRelease - Build all release artifacts
* ./gradlew generateReleaseNotes - Generate release notes from CHANGELOG
* ./gradlew createGitHubRelease - Create GitHub release (requires GH_TOKEN)
* ./gradlew release - Complete release process
*/
// Define release artifacts
def releaseProjects = [
':yoko-osgi',
':yoko-util',
':yoko-spec-corba',
':yoko-rmi-spec',
':yoko-rmi-impl',
':yoko-core'
]
// Task to verify release prerequisites
task verifyReleasePrerequisites {
group = 'release'
description = 'Verifies all prerequisites for creating a release'
doLast {
def errors = []
def warnings = []
// Check CHANGELOG.md exists and has version
def changelogFile = file('CHANGELOG.md')
if (!changelogFile.exists()) {
errors.add("CHANGELOG.md not found")
} else {
def changelog = changelogFile.text
if (!(changelog =~ /## \[v?\d+\.\d+\.\d+/)) {
errors.add("No version found in CHANGELOG.md")
}
}
// Check for git-cliff
try {
exec {
commandLine 'git-cliff', '--version'
standardOutput = new ByteArrayOutputStream()
}
} catch (Exception e) {
warnings.add("git-cliff not found. Install from: https://git-cliff.org/docs/installation (optional for manual releases)")
}
// Check for clean git state
try {
def gitStatus = 'git status --porcelain'.execute().text.trim()
if (gitStatus) {
errors.add("Git working directory is not clean. Commit or stash changes first.")
}
} catch (Exception e) {
errors.add("Unable to check git status: ${e.message}")
}
// Check for GitHub CLI
try {
exec {
commandLine 'gh', '--version'
standardOutput = new ByteArrayOutputStream()
}
} catch (Exception e) {
errors.add("GitHub CLI (gh) not found. Install from: https://cli.github.com/")
}
// Check for GH_TOKEN or gh auth
def hasToken = System.getenv('GH_TOKEN') != null
def hasAuth = false
try {
def authStatus = 'gh auth status'.execute()
authStatus.waitFor()
hasAuth = authStatus.exitValue() == 0
} catch (Exception e) {
// Ignore
}
if (!hasToken && !hasAuth) {
errors.add("GitHub authentication not configured. Run 'gh auth login' or set GH_TOKEN environment variable")
}
if (warnings) {
println "⚠️ Warnings:"
warnings.each { println " - ${it}" }
}
if (errors) {
throw new GradleException("Release prerequisites not met:\n - " + errors.join('\n - '))
}
println "✅ All release prerequisites verified"
}
}
// Task to assemble all release artifacts
task assembleRelease {
group = 'release'
description = 'Assembles all release artifacts (JARs)'
dependsOn verifyReleasePrerequisites
dependsOn releaseProjects.collect { "${it}:jar" }
dependsOn releaseProjects.collect { "${it}:sourcesJar" }
dependsOn releaseProjects.collect { "${it}:javadocJar" }
doLast {
def releaseDir = file("${buildDir}/release")
releaseDir.mkdirs()
// Copy all JARs to release directory
releaseProjects.each { projectPath ->
def proj = project(projectPath)
copy {
from proj.tasks.jar.archiveFile
from proj.tasks.sourcesJar.archiveFile
from proj.tasks.javadocJar.archiveFile
into releaseDir
}
}
// Create checksums
fileTree(releaseDir).matching { include '*.jar' }.each { file ->
ant.checksum(file: file, algorithm: 'SHA-256', fileext: '.sha256')
ant.checksum(file: file, algorithm: 'SHA-512', fileext: '.sha512')
}
println "Release artifacts assembled in: ${releaseDir}"
println "Total artifacts: ${fileTree(releaseDir).matching { include '*.jar' }.files.size()}"
}
}
// Task to update CHANGELOG using git-cliff
task updateChangelog {
group = 'release'
description = 'Updates CHANGELOG.md using git-cliff'
def changelogFile = file('CHANGELOG.md')
def cliffConfig = file('cliff.toml')
inputs.file cliffConfig
outputs.file changelogFile
doLast {
// Check if git-cliff is available
try {
exec {
commandLine 'git-cliff', '--version'
standardOutput = new ByteArrayOutputStream()
}
} catch (Exception e) {
throw new GradleException("git-cliff not found. Install from: https://git-cliff.org/docs/installation")
}
println "Updating CHANGELOG.md using git-cliff for v${version}..."
// Run git-cliff to update only unreleased changes, preserving existing entries
// Use --unreleased to only add new changes since the last tag
exec {
commandLine 'git-cliff', '--config', cliffConfig.absolutePath, '--tag', "v${version}", '--unreleased', '--prepend', changelogFile.absolutePath
}
println "✅ CHANGELOG.md updated successfully"
}
}
// Task to interactively bump the semantic version
task bumpVersion {
group = 'release'
description = 'Interactively bump the semantic version (major, minor, or patch)'
doLast {
def propsFile = file('gradle.properties')
if (!propsFile.exists()) {
throw new GradleException("gradle.properties not found")
}
// Read current version from gradle.properties
def props = new Properties()
propsFile.withInputStream { props.load(it) }
def currentVersion = props.getProperty('version')
if (!currentVersion) {
throw new GradleException("No version property found in gradle.properties")
}
// Parse semantic version
def versionPattern = /^(\d+)\.(\d+)\.(\d+)$/
def matcher = currentVersion =~ versionPattern
if (!matcher.matches()) {
throw new GradleException("Version '${currentVersion}' does not match semantic versioning format (major.minor.patch)")
}
def major = matcher.group(1).toInteger()
def minor = matcher.group(2).toInteger()
def patch = matcher.group(3).toInteger()
println """
╔════════════════════════════════════════════════════════════════╗
║ Version Bump Utility ║
╚════════════════════════════════════════════════════════════════╝
Current version: ${currentVersion}
Select version component to bump:
1) Major version (${major}.${minor}.${patch} → ${major + 1}.0.0)
2) Minor version (${major}.${minor}.${patch} → ${major}.${minor + 1}.0)
3) Patch version (${major}.${minor}.${patch} → ${major}.${minor}.${patch + 1})
4) Cancel
Enter choice [1-4]: """
// Use standard input instead of System.console() for better compatibility
def reader = new BufferedReader(new InputStreamReader(System.in))
def choice = reader.readLine()?.trim()
if (!choice) {
throw new GradleException("No input received. Please run this task in an interactive terminal.")
}
def newVersion
switch (choice) {
case '1':
newVersion = "${major + 1}.0.0"
break
case '2':
newVersion = "${major}.${minor + 1}.0"
break
case '3':
newVersion = "${major}.${minor}.${patch + 1}"
break
case '4':
println "\nVersion bump cancelled."
return
default:
throw new GradleException("Invalid choice: ${choice}")
}
println "\nUpdating version from ${currentVersion} to ${newVersion}..."
// Update gradle.properties
def content = propsFile.text
def updatedContent = content.replaceAll(
/(?m)^version=.*$/,
"version=${newVersion}"
)
propsFile.text = updatedContent
println """
✅ Version updated successfully!
Old version: ${currentVersion}
New version: ${newVersion}
Next steps:
1. Review the change: git diff gradle.properties
2. Commit the change: git add gradle.properties && git commit -m "chore: bump version to ${newVersion}"
3. Update CHANGELOG: ./gradlew updateChangelog
"""
}
}
// Task to create release branch and prepare release
task prepareReleaseBranch {
group = 'release'
description = 'Creates a release branch, updates CHANGELOG, and pushes to origin'
doLast {
def versionTag = "v${version}"
def releaseBranch = "release/${version}"
println "Preparing release branch: ${releaseBranch}"
println "Version tag: ${versionTag}"
// Check for clean git state
def gitStatus = 'git status --porcelain'.execute().text.trim()
if (gitStatus) {
throw new GradleException("Git working directory is not clean. Commit or stash changes first.")
}
// Create release branch
println "Creating release branch..."
exec {
commandLine 'git', 'checkout', '-b', releaseBranch
}
// Push release branch to origin
println "Pushing release branch to origin..."
exec {
commandLine 'git', 'push', '-u', 'origin', releaseBranch
}
// Update CHANGELOG using git-cliff, preserving existing entries
println "Updating CHANGELOG.md..."
exec {
commandLine 'git-cliff', '--config', 'cliff.toml', '--tag', versionTag, '--unreleased', '--prepend', 'CHANGELOG.md'
}
// Commit CHANGELOG if changed
def changelogDiff = 'git diff CHANGELOG.md'.execute().text.trim()
if (changelogDiff) {
println "Committing CHANGELOG changes..."
exec {
commandLine 'git', 'add', 'CHANGELOG.md'
}
exec {
commandLine 'git', 'commit', '-m', "chore: update CHANGELOG for ${version}"
}
exec {
commandLine 'git', 'push', 'origin', releaseBranch
}
} else {
println "CHANGELOG.md unchanged"
}
println """
╔════════════════════════════════════════════════════════════════╗
║ Release Branch Prepared Successfully ║
╚════════════════════════════════════════════════════════════════╝
Branch: ${releaseBranch}
Version: ${releaseVersion}
Tag: ${versionTag}
Next steps:
1. Review the CHANGELOG.md changes
2. Run: ./gradlew finalizeRelease -PreleaseVersion=${releaseVersion}
3. Or manually:
- Create annotated tag: git tag -a ${versionTag} -m "Release ${version}"
- Push tag: git push origin ${versionTag}
- Merge to main: git checkout main && git merge --ff-only ${releaseBranch}
- Push main: git push origin main
- Delete branch: git push origin --delete ${releaseBranch}
"""
}
}
// Task to finalize release (tag, merge, cleanup)
task finalizeRelease {
group = 'release'
description = 'Creates annotated tag, merges release branch to main, and cleans up'
doLast {
// Get version from parameter
def releaseVersion = "${version}"
def versionTag = "v${releaseVersion}"
def releaseBranch = "release/${releaseVersion}"
println "Finalizing release: ${releaseVersion}"
// Verify we're on the release branch
def currentBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
if (currentBranch != releaseBranch) {
throw new GradleException("Must be on ${releaseBranch} branch. Current branch: ${currentBranch}")
}
// Create annotated tag
println "Creating annotated tag: ${versionTag}"
exec {
commandLine 'git', 'tag', '-a', versionTag, '-m', "Release ${releaseVersion}"
}
// Push tag
println "Pushing tag to origin..."
exec {
commandLine 'git', 'push', 'origin', versionTag
}
// Checkout main
println "Checking out main branch..."
exec {
commandLine 'git', 'checkout', 'main'
}
// Pull latest main
println "Pulling latest main..."
exec {
commandLine 'git', 'pull', 'origin', 'main'
}
// Fast-forward merge release branch
println "Merging ${releaseBranch} to main (fast-forward only)..."
exec {
commandLine 'git', 'merge', '--ff-only', releaseBranch
}
// Push main
println "Pushing main to origin..."
exec {
commandLine 'git', 'push', 'origin', 'main'
}
// Delete remote release branch
println "Deleting remote release branch..."
exec {
commandLine 'git', 'push', 'origin', '--delete', releaseBranch
}
// Delete local release branch
println "Deleting local release branch..."
exec {
commandLine 'git', 'branch', '-d', releaseBranch
}
println """
╔════════════════════════════════════════════════════════════════╗
║ Release Finalized Successfully ║
╚════════════════════════════════════════════════════════════════╝
Version: ${releaseVersion}
Tag: ${versionTag}
Branch: ${releaseBranch} (deleted)
The release branch has been merged to main and cleaned up.
Next steps:
1. Verify the release at: https://github.com/OpenLiberty/yoko/releases/tag/${versionTag}
2. Or create the GitHub release manually using: ./gradlew createGitHubRelease
"""
}
}
// Task to generate release notes from CHANGELOG
task generateReleaseNotes {
group = 'release'
description = 'Generates release notes from CHANGELOG.md'
dependsOn assembleRelease
def changelogFile = file('CHANGELOG.md')
def releaseNotesFile = file("${buildDir}/release/RELEASE_NOTES.md")
inputs.file changelogFile
outputs.file releaseNotesFile
doLast {
if (!changelogFile.exists()) {
throw new GradleException("CHANGELOG.md not found")
}
def changelog = changelogFile.text
def versionPattern = /## \[v?(\d+\.\d+\.\d+[^\]]*)\]/
def matcher = changelog =~ versionPattern
if (!matcher.find()) {
throw new GradleException("No version found in CHANGELOG.md")
}
def latestVersion = matcher.group(1)
def startIdx = matcher.start()
// Find next version or end of file
def nextMatcher = changelog.substring(startIdx + 1) =~ versionPattern
def endIdx = nextMatcher.find() ?
startIdx + 1 + nextMatcher.start() :
changelog.length()
def releaseNotes = changelog.substring(startIdx, endIdx).trim()
releaseNotesFile.parentFile.mkdirs()
releaseNotesFile.text = """# Yoko ${latestVersion}
${releaseNotes}
## 📦 Artifacts
This release includes the following artifacts:
${releaseProjects.collect { projectPath ->
def proj = project(projectPath)
"- `${proj.name}-${version}.jar` - Main library\n" +
"- `${proj.name}-${version}-sources.jar` - Source code\n" +
"- `${proj.name}-${version}-javadoc.jar` - API documentation"
}.join('\n')}
## 🔐 Checksums
SHA-256 and SHA-512 checksums are provided for all artifacts.
## 📚 Documentation
For more information, see the [Yoko documentation](https://openliberty.github.io/yoko/).
"""
println "Release notes generated: ${releaseNotesFile}"
println "Version: ${latestVersion}"
}
}
// Task to create distribution archive
task createDistribution(type: Zip) {
group = 'release'
description = 'Creates a distribution archive with all artifacts'
dependsOn generateReleaseNotes
archiveBaseName = 'yoko'
archiveVersion = version
archiveClassifier = 'dist'
destinationDirectory = file("${buildDir}/distributions")
from("${buildDir}/release") {
include '*.jar'
include '*.sha256'
include '*.sha512'
include 'RELEASE_NOTES.md'
}
from(rootDir) {
include 'LICENSE'
include 'NOTICE'
include 'README.md'
include 'CHANGELOG.md'
}
doLast {
println "Distribution created: ${archiveFile.get()}"
}
}
// Task to create GitHub release using GitHub CLI
task createGitHubRelease {
group = 'release'
description = 'Creates a GitHub release with artifacts (requires gh CLI and GH_TOKEN)'
dependsOn createDistribution
doLast {
// Check if gh CLI is available
try {
exec {
commandLine 'gh', '--version'
standardOutput = new ByteArrayOutputStream()
}
} catch (Exception e) {
throw new GradleException("GitHub CLI (gh) not found. Install from: https://cli.github.com/")
}
def releaseNotesFile = file("${buildDir}/release/RELEASE_NOTES.md")
def releaseDir = file("${buildDir}/release")
// Get the actual distribution file created by createDistribution task
def distTask = tasks.getByName('createDistribution')
def distFile = distTask.archiveFile.get().asFile
// Extract version from CHANGELOG
def changelog = file('CHANGELOG.md').text
def versionMatcher = changelog =~ /## \[v?(\d+\.\d+\.\d+[^\]]*)\]/
if (!versionMatcher.find()) {
throw new GradleException("No version found in CHANGELOG.md")
}
def releaseVersion = "v${versionMatcher.group(1)}"
// Check if tag already exists
try {
def checkTag = "git rev-parse --verify ${releaseVersion}".execute()
checkTag.waitFor()
if (checkTag.exitValue() == 0) {
throw new GradleException("Git tag ${releaseVersion} already exists. Roll it back manually to re-release or bump the version using 'gradle bumpVersion'")
}
} catch (IOException e) {
// Tag doesn't exist, which is good
}
// Check if GitHub release already exists
try {
def checkRelease = "gh release view ${releaseVersion}".execute()
def output = new ByteArrayOutputStream()
checkRelease.consumeProcessOutput(output, output)
checkRelease.waitFor()
if (checkRelease.exitValue() == 0) {
throw new GradleException("GitHub release ${releaseVersion} already exists. Remove it, or bump the version in gradle.properties")
}
} catch (IOException e) {
// Release doesn't exist, which is good
}
println "Creating GitHub release: ${releaseVersion}"
// Create release
def createCmd = [
'gh', 'release', 'create', releaseVersion,
'--title', "Yoko ${releaseVersion}",
'--notes-file', releaseNotesFile.absolutePath
]
// Add all JAR files
fileTree(releaseDir).matching {
include '*.jar'
include '*.sha256'
include '*.sha512'
}.each { file ->
createCmd.add(file.absolutePath)
}
// Add distribution archive
createCmd.add(distFile.absolutePath)
exec {
commandLine createCmd
}
println "✅ GitHub release created successfully: ${releaseVersion}"
println "View at: https://github.com/OpenLiberty/yoko/releases/tag/${releaseVersion}"
}
}
// Main release task
task release {
group = 'release'
description = 'Complete release process: build, test, and create GitHub release'
dependsOn 'createGitHubRelease'
doFirst {
println """
╔════════════════════════════════════════════════════════════════╗
║ Starting Release Process ║
╚════════════════════════════════════════════════════════════════╝
Note: To update CHANGELOG.md before release, run:
./gradlew updateChangelog
"""
}
doLast {
println """
╔════════════════════════════════════════════════════════════════╗
║ 🎉 Release Complete! 🎉 ║
╚════════════════════════════════════════════════════════════════╝
Release artifacts have been built and published to GitHub.
Next steps:
1. Verify the release at: https://github.com/OpenLiberty/yoko/releases
2. Update documentation if needed
3. Announce the release
"""
}
}
// Add sources and javadoc JAR tasks to release projects
configure(releaseProjects.collect { project(it) }) {
afterEvaluate {
task sourcesJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
dependsOn javadoc
}
artifacts {
archives sourcesJar
archives javadocJar
}
}
}