Skip to content

Commit

Permalink
Use grgit to increment version number
Browse files Browse the repository at this point in the history
  • Loading branch information
donat committed Jan 16, 2024
1 parent 548ec8d commit fe96314
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -237,25 +237,38 @@ task tag {
// increment the service segment in the version number and push it to master
task incrementVersion {
doLast {
def oldVersion = file('version.txt').text.trim()
def newVersion = ""
def matcher = version =~ "^(\\d+)\\.(\\d+).(\\d+)"
if (matcher.find()) {
def serviceSegment = Integer.parseInt(matcher.group(3)) + 1
newVersion = matcher.group(1) + "." + matcher.group(2) + "." + serviceSegment
file('version.txt').text = newVersion

Pattern bundleVersionPattern = Pattern.compile('(?<=Bundle-Version: )\\d+\\.\\d+\\.\\d+(?=\\.qualifier)')
file('.').eachFileRecurse { file ->
if (file.name == 'MANIFEST.MF') {
replacePatternsInFile(file, [(bundleVersionPattern): newVersion])
def githubAccessKey = findProperty("githubAccessKey")
if (!githubAccessKey) {
throw new IllegalStateException("Cannot increment version: define GitHub access key with -PgithubAccessKey=<access_key> project property")
} else {
// update version file
def oldVersion = file('version.txt').text.trim()
def newVersion = ""
def matcher = version =~ "^(\\d+)\\.(\\d+).(\\d+)"
if (matcher.find()) {
def serviceSegment = Integer.parseInt(matcher.group(3)) + 1
newVersion = matcher.group(1) + "." + matcher.group(2) + "." + serviceSegment
file('version.txt').text = newVersion
Pattern bundleVersionPattern = Pattern.compile('(?<=Bundle-Version: )\\d+\\.\\d+\\.\\d+(?=\\.qualifier)')
file('.').eachFileRecurse { file ->
if (file.name == 'MANIFEST.MF') {
replacePatternsInFile(file, [(bundleVersionPattern): newVersion])
}
}
} else {
throw new IllegalStateException("Unparseable version: $oldVersion.")
}
} else {
throw new IllegalStateException("Unparseable version: $oldVersion.")

// set access token
System.setProperty("org.ajoberstar.grgit.auth.username", githubAccessKey)

// commit and push changes
grgit.commit {
message = "Increment version $oldVersion -> $newVersion"
all = true
}
grgit.push()
}
exec { commandLine 'git', 'commit', '-a', '-m', "Increment version from $oldVersion to $newVersion" }
exec { commandLine 'git', 'push', githubAuthenticatedHost, 'master' }
}
}

Expand Down

0 comments on commit fe96314

Please sign in to comment.