Skip to content

Commit b88e1dd

Browse files
committed
Simplify the release process
1 parent 71febfd commit b88e1dd

File tree

4 files changed

+20
-252
lines changed

4 files changed

+20
-252
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']],

documentation/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ def renderReferenceDocumentationTask = tasks.register( "renderReferenceDocumenta
182182
"html-meta-version-family": versionFamily.get(),
183183
)
184184

185+
// See https://docs.asciidoctor.org/gradle-plugin/latest/common-task-configuration/#choosing-an-execution-mode-for-asciidoctorj
186+
executionMode = org.ysb33r.grolifant.api.core.jvm.ExecutionMode.JAVA_EXEC
187+
185188
dependsOn( tasks.named( "unpackTheme" ) )
186189
}
187190

publish.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,11 @@ publishing {
9797
}
9898
}
9999
}
100+
101+
def releasePrepareTask = tasks.register("releasePrepare") {
102+
description "Prepares all the artifacts and documentation for a JReleaser release."
103+
group "Release"
104+
105+
// Create all the published artifacts (i.e. jars) and move them to the staging directory (for JReleaser):
106+
dependsOn publishAllPublicationsToStagingRepository
107+
}

release/build.gradle

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

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

87-
def changeToReleaseVersionTask = tasks.register( 'changeToReleaseVersion' ) {
88-
description 'Updates `gradle/version.properties` file to the specified release-version'
89-
group 'Release'
90-
91-
dependsOn releaseChecksTask
92-
93-
doFirst {
94-
logger.lifecycle( "Updating version-file to release-version : `${project.releaseVersion}`" )
95-
updateVersionFile( "${project.releaseVersion}" )
96-
}
97-
}
98-
9932
def updateDocumentationTask = tasks.register( 'updateDocumentation' ) {
10033
description "Update the documentation on the cloned static website"
10134
dependsOn assembleDocumentationTask
102-
mustRunAfter changeToReleaseVersion
10335

10436
// copy documentation outputs into target/documentation:
10537
// * this is used in building the dist bundles
@@ -120,188 +52,13 @@ def updateDocumentationTask = tasks.register( 'updateDocumentation' ) {
12052
}
12153
}
12254

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

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

0 commit comments

Comments
 (0)