Last active
August 2, 2016 18:36
-
-
Save nblair/53f44e08104354dd078e6104d7dae4a8 to your computer and use it in GitHub Desktop.
Gradle task to include in CI job for pull requests that confirms the contribution sufficiently increments the Gradle version field
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
buildscript { | |
dependencies { | |
classpath "com.github.zafarkhaja:java-semver:0.9.0" | |
} | |
} | |
plugins { | |
id "org.ajoberstar.grgit" version "1.4.2" | |
} | |
/** | |
* Task executed by Jenkins on Pull Requests to confirm the contribution has appropriately | |
* incremented the gradle 'version' field above. | |
*/ | |
task confirmProjectVersionIncremented() { | |
doLast { | |
def grgit = org.ajoberstar.grgit.Grgit.open(project.rootDir) | |
def describe = grgit.describe() | |
def lastVersion = com.github.zafarkhaja.semver.Version.valueOf(describe) | |
if(!''.equals(lastVersion.getPreReleaseVersion())) { | |
// git describe produced something like '0.20.7-1-gfbe61fd' | |
// split on '-' and recreate last as the first token | |
lastVersion = com.github.zafarkhaja.semver.Version.valueOf(describe.split('-')[0]) | |
} | |
// read 'version' field from build.gradle | |
def currentVersion = com.github.zafarkhaja.semver.Version.valueOf(getVersion()); | |
if ( currentVersion.greaterThan(lastVersion) ) { | |
// success, the project version is greater than the last one available via git describe | |
println "Version test successful: proposed version is " + currentVersion + " greater than last.released.version " + lastVersion | |
} else { | |
throw new GradleException("version field in build.gradle with current value " + currentVersion + " must be incremented past " + lastVersion) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment