Skip to content

Commit b578da3

Browse files
marko-bekhtaDavideD
authored andcommitted
Simplify the release process
1 parent 69d5278 commit b578da3

File tree

3 files changed

+19
-248
lines changed

3 files changed

+19
-248
lines changed

ci/release/Jenkinsfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pipeline {
178178
configFile(fileId: 'release.config.ssh', targetLocation: "${env.HOME}/.ssh/config"),
179179
configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts")
180180
]) {
181-
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {
181+
sshagent(['ed25519.Hibernate-CI.github.com']) {
182182
// set release version
183183
// update changelog from JIRA
184184
// tags the version
@@ -211,7 +211,7 @@ pipeline {
211211
string(credentialsId: 'release.gpg.passphrase', variable: 'JRELEASER_GPG_PASSPHRASE'),
212212
string(credentialsId: 'Hibernate-CI.github.com', variable: 'JRELEASER_GITHUB_TOKEN')
213213
]) {
214-
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {
214+
sshagent(['ed25519.Hibernate-CI.github.com', 'jenkins.in.relation.to']) {
215215
// performs documentation upload and Sonatype release
216216
// push to github
217217
withEnv([
@@ -237,7 +237,7 @@ pipeline {
237237
withCredentials([
238238
gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default')
239239
]) {
240-
sshagent( ['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net'] ) {
240+
sshagent( ['ed25519.Hibernate-CI.github.com'] ) {
241241
dir( '.release/hibernate.org' ) {
242242
checkout scmGit(
243243
branches: [[name: '*/production']],

publish.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,11 @@ publishing {
8888
}
8989
}
9090
}
91+
92+
def releasePrepareTask = tasks.register("releasePrepare") {
93+
description "Prepares all the artifacts and documentation for a JReleaser release."
94+
group "Release"
95+
96+
// Create all the published artifacts (i.e. jars) and move them to the staging directory (for JReleaser):
97+
dependsOn publishAllPublicationsToStagingRepository
98+
}

release/build.gradle

Lines changed: 8 additions & 245 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,8 @@ description = 'Release module'
1919
// The folder containing the rendered documentation
2020
final Directory documentationDir = project(":documentation").layout.buildDirectory.get()
2121

22-
def releaseChecksTask = tasks.register( "releaseChecks" ) {
23-
description 'Checks and preparation for release'
24-
group 'Release'
25-
26-
doFirst {
27-
logger.lifecycle("Checking that the working tree is clean...")
28-
String uncommittedFiles = executeGitCommand('status', '--porcelain')
29-
if (!uncommittedFiles.isEmpty()) {
30-
throw new GradleException(
31-
"Cannot release because there are uncommitted or untracked files in the working tree.\n" +
32-
"Commit or stash your changes first.\n" +
33-
"Uncommitted files:\n " +
34-
uncommittedFiles
35-
)
36-
}
37-
38-
String gitBranchLocal = project.hasProperty( 'gitBranch' ) && !project.property( 'gitBranch' ).isEmpty()
39-
? project.property( 'gitBranch' )
40-
: executeGitCommand( 'branch', '--show-current' ).trim()
41-
42-
String gitRemoteLocal
43-
if ( project.hasProperty( 'gitRemote' ) && !project.property( 'gitRemote' ).isEmpty() ) {
44-
gitRemoteLocal = project.property( 'gitRemote' )
45-
}
46-
else {
47-
final String remotes = executeGitCommand( 'remote', 'show' ).trim()
48-
final List<String> tokens = remotes.tokenize()
49-
if ( tokens.size() != 1 ) {
50-
throw new GradleException( "Could not determine `gitRemote` property for `releaseChecks` tasks." )
51-
}
52-
gitRemoteLocal = tokens.get( 0 )
53-
}
54-
55-
project.ext {
56-
gitBranch = gitBranchLocal
57-
gitRemote = gitRemoteLocal
58-
}
59-
60-
logger.lifecycle( "Switching to branch '${project.gitBranch}'..." )
61-
executeGitCommand( 'checkout', project.gitBranch )
62-
63-
logger.lifecycle( "Checking that all commits are pushed..." )
64-
String diffWithUpstream = executeGitCommand( 'diff', '@{u}' )
65-
if ( !diffWithUpstream.isEmpty() ) {
66-
throw new GradleException(
67-
"Cannot perform `ciRelease` tasks because there are un-pushed local commits .\n" +
68-
"Push your commits first."
69-
)
70-
}
71-
}
72-
}
22+
// Relative path on the static website where the documentation is located
23+
final String docWebsiteRelativePath = "reactive/documentation/${projectVersion.family}"
7324

7425
/**
7526
* Assembles all documentation into the {buildDir}/documentation directory.
@@ -81,22 +32,9 @@ def assembleDocumentationTask = tasks.register( 'assembleDocumentation' ) {
8132
}
8233
assemble.dependsOn assembleDocumentationTask
8334

84-
def changeToReleaseVersionTask = tasks.register( 'changeToReleaseVersion' ) {
85-
description 'Updates `gradle/version.properties` file to the specified release-version'
86-
group 'Release'
87-
88-
dependsOn releaseChecksTask
89-
90-
doFirst {
91-
logger.lifecycle( "Updating version-file to release-version : `${project.releaseVersion}`" )
92-
updateVersionFile( "${project.releaseVersion}" )
93-
}
94-
}
95-
9635
def updateDocumentationTask = tasks.register( 'updateDocumentation' ) {
9736
description "Update the documentation on the cloned static website"
9837
dependsOn assembleDocumentationTask
99-
mustRunAfter changeToReleaseVersion
10038

10139
// copy documentation outputs into target/documentation:
10240
// * this is used in building the dist bundles
@@ -117,188 +55,13 @@ def updateDocumentationTask = tasks.register( 'updateDocumentation' ) {
11755
}
11856
}
11957

120-
def gitPreparationForReleaseTask = tasks.register( 'gitPreparationForRelease' ) {
121-
dependsOn releaseChecksTask, changeToReleaseVersionTask
122-
finalizedBy updateDocumentationTask
123-
124-
doLast {
125-
logger.lifecycle( "Performing pre-steps Git commit : `${project.releaseVersion}`" )
126-
executeGitCommand( 'add', '.' )
127-
executeGitCommand( 'commit', '-m', "Update project version to : `${project.releaseVersion}`" )
128-
}
129-
}
130-
131-
def changeToDevelopmentVersionTask = tasks.register( 'changeToDevelopmentVersion' ) {
132-
description 'Updates `gradle/version.properties` file to the specified development-version'
133-
group 'Release'
134-
135-
dependsOn releaseChecksTask
136-
137-
doFirst {
138-
logger.lifecycle( "Updating version-file to development-version : `${project.developmentVersion}`" )
139-
updateVersionFile( "${project.developmentVersion}" )
140-
}
141-
}
142-
143-
def releasePreparePostGitTask = tasks.register( 'gitTasksAfterRelease' ) {
144-
dependsOn changeToDevelopmentVersionTask
145-
146-
doLast {
147-
if ( project.createTag ) {
148-
logger.lifecycle( "Tagging release : `${project.releaseTag}`..." )
149-
executeGitCommand( 'tag', '-a', project.releaseTag, '-m', "Release $project.projectVersion" )
150-
}
151-
152-
logger.lifecycle( "Performing post-steps Git commit : `${project.releaseVersion}`" )
153-
executeGitCommand( 'add', '.' )
154-
executeGitCommand( 'commit', '-m', "Update project version to : `${project.developmentVersion}`" )
155-
}
156-
}
157-
158-
void updateVersionFile(var version) {
159-
logger.lifecycle( "Updating `gradle/version.properties` version to `${version}`" )
160-
project.versionFile.text = "projectVersion=${version}"
161-
project.version = version
162-
}
163-
164-
def publishReleaseArtifactsTask = tasks.register( 'publishReleaseArtifacts' ) {
165-
dependsOn updateDocumentationTask
166-
167-
mustRunAfter gitPreparationForReleaseTask
168-
}
169-
170-
def releasePerformPostGitTask = tasks.register( 'gitTasksAfterReleasePerform' ) {
171-
172-
doLast {
173-
if ( project.createTag ) {
174-
logger.lifecycle( "Pushing branch and tag to remote `${project.gitRemote}`..." )
175-
executeGitCommand( 'push', '--atomic', project.gitRemote, project.gitBranch, project.releaseTag )
176-
}
177-
else {
178-
logger.lifecycle( "Pushing branch to remote `${project.gitRemote}`..." )
179-
executeGitCommand( 'push', project.gitRemote, project.gitBranch )
180-
}
181-
}
182-
}
183-
18458
def releasePrepareTask = tasks.register( "releasePrepare" ) {
185-
description "On a local checkout, performs all the changes required for the release, website updates included"
186-
group "Release"
187-
188-
dependsOn gitPreparationForReleaseTask
189-
190-
finalizedBy releasePreparePostGitTask
191-
}
192-
193-
def releasePerformTask = tasks.register( 'releasePerform' ) {
194-
group 'Release'
195-
description 'Performs a release on local check-out, including updating changelog and '
196-
197-
dependsOn publishReleaseArtifactsTask
198-
199-
finalizedBy releasePerformPostGitTask
200-
}
201-
202-
/*
203-
* Release everything
204-
*/
205-
def releaseTask = tasks.register( 'release' ) {
206-
description 'Performs a release on local check-out'
207-
group 'Release'
208-
209-
dependsOn releasePrepareTask
210-
dependsOn releasePerformTask
211-
}
212-
213-
def ciReleaseTask = tasks.register( 'ciRelease' ) {
214-
description "Triggers the release on CI: creates commits to change the version (release, then development), creates a tag, pushes everything. Then CI will take over and perform the release."
59+
description "Prepares all the artifacts and documentation for a JReleaser release."
21560
group "Release"
21661

217-
dependsOn releaseTask
218-
}
219-
220-
static String executeGitCommand(Object ... subcommand){
221-
List<Object> command = ['git']
222-
Collections.addAll( command, subcommand )
223-
def proc = command.execute()
224-
def code = proc.waitFor()
225-
def stdout = inputStreamToString( proc.getInputStream() )
226-
def stderr = inputStreamToString( proc.getErrorStream() )
227-
if ( code != 0 ) {
228-
throw new GradleException( "An error occurred while executing " + command + "\n\nstdout:\n" + stdout + "\n\nstderr:\n" + stderr )
229-
}
230-
return stdout
231-
}
232-
233-
static String inputStreamToString(InputStream inputStream) {
234-
inputStream.withCloseable { ins ->
235-
new BufferedInputStream(ins).withCloseable { bis ->
236-
new ByteArrayOutputStream().withCloseable { buf ->
237-
int result = bis.read()
238-
while (result != -1) {
239-
buf.write((byte) result)
240-
result = bis.read()
241-
}
242-
return buf.toString(StandardCharsets.UTF_8.name())
243-
}
244-
}
245-
}
246-
}
247-
248-
gradle.getTaskGraph().whenReady { tg->
249-
if ( ( tg.hasTask( project.tasks.releasePrepare ) || tg.hasTask( project.tasks.releasePerform ) )
250-
&& ! project.getGradle().getStartParameter().isDryRun() ) {
251-
String releaseVersionLocal
252-
String developmentVersionLocal
253-
254-
def console = tg.hasTask( project.tasks.release ) && !tg.hasTask( project.tasks.ciRelease )
255-
? System.console()
256-
: null
257-
258-
if (project.hasProperty('releaseVersion')) {
259-
releaseVersionLocal = project.property('releaseVersion')
260-
}
261-
else {
262-
if (console) {
263-
// prompt for `releaseVersion`
264-
releaseVersionLocal = console.readLine('> Enter the release version: ')
265-
}
266-
else {
267-
throw new GradleException(
268-
"`release`-related tasks require the following properties: 'releaseVersion', 'developmentVersion'"
269-
)
270-
}
271-
}
272-
273-
if (project.hasProperty('developmentVersion')) {
274-
developmentVersionLocal = project.property('developmentVersion')
275-
}
276-
else {
277-
if (console) {
278-
// prompt for `developmentVersion`
279-
developmentVersionLocal = console.readLine('> Enter the next development version: ')
280-
}
281-
else {
282-
throw new GradleException(
283-
"`release`-related tasks require the following properties: 'releaseVersion', 'developmentVersion'"
284-
)
285-
}
286-
}
287-
288-
assert releaseVersionLocal != null && developmentVersionLocal != null
289-
290-
// set up information for the release-related tasks
291-
project.ext {
292-
releaseVersion = releaseVersionLocal
293-
developmentVersion = developmentVersionLocal
294-
createTag = !project.hasProperty('noTag')
295-
releaseTag = project.createTag ? determineReleaseTag(releaseVersionLocal) : ''
296-
}
297-
}
298-
}
299-
300-
static String determineReleaseTag(String releaseVersion) {
301-
return releaseVersion.endsWith( '.Final' )
302-
? releaseVersion.replace( ".Final", "" )
303-
: releaseVersion
62+
// Render the Documentation/Javadocs and move them to the staging directory (for JReleaser):
63+
dependsOn updateDocumentationTask
64+
// Create all the published artifacts (i.e. jars) and move them to the staging directory (for JReleaser):
65+
// this one is defined in the publish.gradle
66+
// dependsOn project.getTasksByName(publishAllPublicationsToStagingRepository, false)
30467
}

0 commit comments

Comments
 (0)