Skip to content

Commit ca22222

Browse files
marko-bekhtaDavideD
authored andcommitted
Simplify the release process
1 parent bfc5ef7 commit ca22222

File tree

3 files changed

+17
-249
lines changed

3 files changed

+17
-249
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', 'jenkins.in.relation.to', '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: 6 additions & 246 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,6 @@ final Directory documentationDir = project(":documentation").layout.buildDirecto
1818
// Relative path on the static website where the documentation is located
1919
final String docWebsiteRelativePath = "reactive/documentation/${projectVersion.family}"
2020

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

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

10035
// copy documentation outputs into target/documentation:
10136
// * this is used in building the dist bundles
@@ -116,188 +51,13 @@ def updateDocumentationTask = tasks.register( 'updateDocumentation' ) {
11651
}
11752
}
11853

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

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

0 commit comments

Comments
 (0)