Add gradle task to automate the CI release
This commit is contained in:
parent
c44150d0d6
commit
cfeee5059b
|
@ -7,8 +7,20 @@
|
|||
|
||||
apply plugin: 'base'
|
||||
|
||||
File versionFile = file( "${rootProject.projectDir}/gradle/version.properties" )
|
||||
|
||||
if ( project.hasProperty( 'releaseVersion' ) ) {
|
||||
if ( !project.hasProperty( 'developmentVersion' ) ) {
|
||||
throw new GradleException(
|
||||
"When the releaseVersion parameter is specified, the parameter developmentVersion is required as well."
|
||||
)
|
||||
}
|
||||
versionFile.text = "hibernateVersion=${project.property( 'releaseVersion' )}"
|
||||
}
|
||||
|
||||
ext {
|
||||
ormVersion = new HibernateVersion( '5.5.0-SNAPSHOT', project )
|
||||
ormVersionFile = versionFile
|
||||
ormVersion = HibernateVersion.fromFile( versionFile, project )
|
||||
baselineJavaVersion = '1.8'
|
||||
jpaVersion = new JpaVersion('2.2')
|
||||
}
|
||||
|
@ -54,6 +66,22 @@ class HibernateVersion {
|
|||
this.osgiVersion = isSnapshot ? family + '.' + hibernateVersionComponents[2] + '.SNAPSHOT' : fullName
|
||||
}
|
||||
|
||||
static HibernateVersion fromFile(File file, Project project){
|
||||
def fullName = readVersionProperties(file)
|
||||
return new HibernateVersion(fullName, project)
|
||||
}
|
||||
|
||||
private static String readVersionProperties(File file) {
|
||||
if ( !file.exists() ) {
|
||||
throw new GradleException( "Version file $file.canonicalPath does not exists" )
|
||||
}
|
||||
Properties versionProperties = new Properties()
|
||||
file.withInputStream {
|
||||
stream -> versionProperties.load( stream )
|
||||
}
|
||||
return versionProperties.hibernateVersion
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString() {
|
||||
return this.fullName
|
||||
|
|
|
@ -166,4 +166,5 @@ publishing {
|
|||
task ciBuild( dependsOn: [test, publish] )
|
||||
|
||||
task release( dependsOn: [test, bintrayUpload] )
|
||||
bintrayUpload.mustRunAfter test
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
hibernateVersion=5.5.0-SNAPSHOT
|
|
@ -1,3 +1,5 @@
|
|||
import groovy.json.JsonSlurper
|
||||
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
|
@ -244,3 +246,170 @@ artifacts {
|
|||
|
||||
task release( dependsOn: [uploadDocumentation, uploadBundlesSourceForge] )
|
||||
|
||||
def gitRemote = 'origin'
|
||||
if ( project.hasProperty( 'gitRemote' ) ) {
|
||||
gitRemote = project.property( 'gitRemote' )
|
||||
}
|
||||
|
||||
task updateChangeLogFile {
|
||||
group = "Release"
|
||||
description = "Updates the changelog.txt file and push the changes to github"
|
||||
doFirst{
|
||||
ChangeLogFile.update( ormVersion.fullName );
|
||||
|
||||
executeGitCommand(
|
||||
"git add .",
|
||||
"An error occurred during the execution of git add for the changelog.txt and the release version changes."
|
||||
)
|
||||
|
||||
executeGitCommand(
|
||||
"git commit -m \"${project.ormVersion.fullName}\"",
|
||||
"An error occurred during the execution of git commit for the changelog.txt and the release version changes."
|
||||
)
|
||||
|
||||
executeGitCommand(
|
||||
"git push ${gitRemote}",
|
||||
"An error occurred during the execution git push for the changelog.txt and the release version changes."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
task ciRelease() {
|
||||
group = "Release"
|
||||
description = "Performs a release: the hibernate version is set and the changelog.txt file updated, the changes are pushed to github, then the release is performed, tagged and the hibernate version is set to the development one."
|
||||
doLast {
|
||||
if ( !project.hasProperty( 'developmentVersion' ) ) {
|
||||
throw new GradleException(
|
||||
"When the releaseVersion parameter is specified, the parameter developmentVersion is required as well."
|
||||
)
|
||||
}
|
||||
if ( !project.hasProperty( 'noTag' ) ) {
|
||||
String tag = project.ormVersion.fullName
|
||||
// the release is tagged and the tag is pushed to github
|
||||
if ( tag.endsWith( ".Final" ) ) {
|
||||
tag = tag.replace( ".Final", "" )
|
||||
}
|
||||
executeGitCommand(
|
||||
"git tag ${tag}",
|
||||
"An error occurred during the execution of git tag"
|
||||
)
|
||||
executeGitCommand(
|
||||
"git push ${gitRemote} ${tag}",
|
||||
"An error occurred during the execution of git push od the tag"
|
||||
)
|
||||
|
||||
// the hibernate version is changed to the development one and the changes are pushed to github
|
||||
project.ormVersionFile.text = "hibernateVersion=${project.property( 'developmentVersion' )}"
|
||||
executeGitCommand(
|
||||
"git add .",
|
||||
"An error occurred during the execution of git add for the development version change."
|
||||
)
|
||||
|
||||
executeGitCommand(
|
||||
"git commit -m \"${project.ormVersion.fullName}\"",
|
||||
"An error occurred during the execution of git commit for the development version change."
|
||||
)
|
||||
|
||||
executeGitCommand(
|
||||
"git push ${gitRemote}",
|
||||
"An error occurred during the execution git push for the development version change."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ciRelease.dependsOn updateChangeLogFile, release
|
||||
release.mustRunAfter updateChangeLogFile
|
||||
|
||||
void executeGitCommand(String command, String errorMessage){
|
||||
def proc = command.execute()
|
||||
def errorsStringBuffer = new StringBuffer()
|
||||
proc.waitFor()
|
||||
proc.consumeProcessErrorStream( errorsStringBuffer )
|
||||
if ( errorsStringBuffer.toString( ) != "" ) {
|
||||
throw new GradleException( errorMessage + " " + b );
|
||||
}
|
||||
}
|
||||
|
||||
class ChangeLogFile {
|
||||
|
||||
// Get the Release Notes from Jira and add them to the Hibernate changelog.txt file
|
||||
static void update(String releaseVersion) {
|
||||
def text = ""
|
||||
File changelog = new File( "changelog.txt" )
|
||||
def newReleaseNoteBlock = getNewReleaseNoteBlock(releaseVersion)
|
||||
changelog.eachLine {
|
||||
line ->
|
||||
if ( line.startsWith( "Note:" ) ) {
|
||||
text += line + System.lineSeparator() + System.lineSeparator() + newReleaseNoteBlock
|
||||
}
|
||||
else {
|
||||
text += line + System.lineSeparator()
|
||||
}
|
||||
}
|
||||
changelog.text = text
|
||||
}
|
||||
|
||||
// Get the Release Notes from Jira
|
||||
static String getNewReleaseNoteBlock(String releaseVersion) {
|
||||
def restReleaseVersion;
|
||||
if ( releaseVersion.endsWith( ".Final" ) ) {
|
||||
restReleaseVersion = releaseVersion.replace( ".Final", "" )
|
||||
}
|
||||
else {
|
||||
restReleaseVersion = releaseVersion
|
||||
}
|
||||
def apiString = "https://hibernate.atlassian.net/rest/api/2/search/?jql=project=HHH%20AND%20fixVersion=${restReleaseVersion}%20order%20by%20issuetype%20ASC"
|
||||
def apiUrl = new URL( apiString )
|
||||
def releseNotes = new JsonSlurper().parse( apiUrl )
|
||||
|
||||
|
||||
def releaseDate = new Date().format( 'MMMM dd, YYYY' )
|
||||
def versionId = releseNotes.issues.get( 0 ).fields.fixVersions.get( 0 ).id
|
||||
ReleaseNote releaseNotes = new ReleaseNote( releaseVersion, releaseDate, versionId )
|
||||
|
||||
def issuetype
|
||||
releseNotes.issues.each {
|
||||
issue ->
|
||||
if ( issuetype != issue.fields.issuetype.name ) {
|
||||
issuetype = issue.fields.issuetype.name
|
||||
releaseNotes.addEmptyLine();
|
||||
releaseNotes.addLine( "** ${issue.fields.issuetype.name}" )
|
||||
}
|
||||
releaseNotes.addLine( " * [" + issue.key + "] - " + issue.fields.summary )
|
||||
}
|
||||
releaseNotes.addEmptyLine()
|
||||
return releaseNotes.notes
|
||||
}
|
||||
}
|
||||
|
||||
class ReleaseNote {
|
||||
String notes;
|
||||
String notesHeaderSeparator = "------------------------------------------------------------------------------------------------------------------------"
|
||||
|
||||
ReleaseNote(String releaseVersion, String releaseDate, String versionId) {
|
||||
notes = "Changes in ${releaseVersion} (${releaseDate})" + System.lineSeparator()
|
||||
addHeaderSeparator()
|
||||
addEmptyLine()
|
||||
addLine( "https://hibernate.atlassian.net/projects/HHH/versions/${versionId}" )
|
||||
}
|
||||
|
||||
void addLine(String text) {
|
||||
notes += text + System.lineSeparator()
|
||||
}
|
||||
|
||||
void addHeaderSeparator() {
|
||||
addLine( notesHeaderSeparator )
|
||||
}
|
||||
|
||||
void addEmptyLine() {
|
||||
notes += System.lineSeparator()
|
||||
}
|
||||
|
||||
void addEmptyLines(int numberOfLines) {
|
||||
for ( i in 1..numberOfLines ) {
|
||||
notes += System.lineSeparator()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue