forked from hamcrest/JavaHamcrest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Derive version from git (hamcrest#419)
Instead of hard-coding the version into build.gradle, this change derives the version from git tags. If the HEAD commit has a tag in the format "`vM.N`", the version number `M.N` is used directly. Otherwise, a snapshot version is assumed, and the version becomes `M.(N+1)-SNAPSHOT`.
- Loading branch information
1 parent
01c776c
commit b943810
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
ext.getGitVersion = { -> | ||
def stdout = new ByteArrayOutputStream() | ||
exec { | ||
commandLine "git", "describe", "--tags" | ||
standardOutput = stdout | ||
} | ||
return stdout.toString().trim().replaceAll("v", "") | ||
} | ||
|
||
ext.getMavenVersion = { -> | ||
def gitVersion = getGitVersion() | ||
if (!gitVersion.contains("-")) { | ||
// We're directly on a tagged commit | ||
return gitVersion | ||
} | ||
|
||
def match = gitVersion =~ /^(\d+)\.(\d+)-.*$/ | ||
// Make sure we're only using the major.minor version. | ||
assert match : "Unexpected version from git: ${gitVersion}" | ||
|
||
// We're not directly on a tagged commit, so increment the minor version and call it a snapshot | ||
def (_, major, minor) = match[0] | ||
def mvnMinor = minor.toInteger() + 1 | ||
return "${major}.${mvnMinor}-SNAPSHOT" | ||
} |