Created
September 28, 2018 08:22
-
-
Save jonas-grgt/cb7009f3d76343c6fca23aec820c8c28 to your computer and use it in GitHub Desktop.
Gradle script - Semantic version bumping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Version { | |
Integer major; | |
Integer minor; | |
Integer patch; | |
Version(major, minor, patch) { | |
this.major = major | |
this.minor = minor | |
this.patch = patch | |
} | |
public static Version valueOf(String version) { | |
def matcher = version =~ /(?<major>\d{1,2})\.(?<minor>\d{1,2})\.(?<patch>\d{1,2})/ | |
matcher.matches() | |
def major = matcher.group('major').toInteger() | |
def minor = matcher.group('minor').toInteger() | |
def patch = matcher.group('patch').toInteger() | |
return new Version(major, minor, patch) | |
} | |
public void bumpMinor() { | |
this.minor++ | |
} | |
@Override | |
public String toString() { | |
return "${major}.${minor}.$patch" | |
} | |
} | |
task bumpMinor<<{ | |
def projectVersion = Version.valueOf(version) | |
projectVersion.bumpMinor() | |
String versionToReplace=buildFile.getText() | |
.replaceFirst("version='$version'","version='"+projectVersion.toString()+"'") | |
buildFile.setText(versionToReplace) | |
} | |
task bumpPatch<<{ | |
def projectVersion = Version.valueOf(version) | |
projectVersion.bumpMinor() | |
String versionToReplace=buildFile.getText() | |
.replaceFirst("version='$version'","version='"+projectVersion.toString()+"'") | |
buildFile.setText(versionToReplace) | |
} | |
task bumpMajor<<{ | |
def projectVersion = Version.valueOf(version) | |
projectVersion.bumpMinor() | |
String versionToReplace=buildFile.getText() | |
.replaceFirst("version='$version'","version='"+projectVersion.toString()+"'") | |
buildFile.setText(versionToReplace) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment