Skip to content

Commit

Permalink
Check for commit hash before appending another in build.gradle caclul…
Browse files Browse the repository at this point in the history
…ateVersion (#7537)

Signed-off-by: Matilda Clerke <[email protected]>
  • Loading branch information
Matilda-Clerke authored Aug 29, 2024
1 parent 8ae0db4 commit a8bbcd5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -997,12 +997,16 @@ def buildTime() {
@Memoized
def calculateVersion() {
// Regex pattern for basic calendar versioning, with provision to omit patch rev
def calVerPattern = ~/\d+\.\d+(\.\d+)?(-.*)?/
def calVerPattern = ~/\d+\.\d+(\.\d+)?(-\w+)?$/
def calVerWithCommitPattern = ~/\d+\.\d+(\.\d+)?(-\w+)?-[0-9a-fA-F]{7,8}$/
def gitDetails = getGitCommitDetails() // Adjust length as needed
if (project.hasProperty('version') && (project.version =~ calVerPattern)) {
if (project.hasProperty('version') && project.version =~ calVerWithCommitPattern) {
println("Utilising supplied version as it appears to already contain commit hash: ${project.version}")
return project.version
} else if (project.hasProperty('version') && project.version =~ calVerPattern) {
println("Generating project version using supplied version: ${project.version}-${gitDetails.hash}")
return "${project.version}-${gitDetails.hash}"
} else {
} else {
// If no version is supplied or it doesn't match the semantic versioning, calculate from git
println("Generating project version using date (${gitDetails.date}-develop-${gitDetails.hash}), as supplied version is not semver: ${project.version}")
return "${gitDetails.date}-develop-${gitDetails.hash}"
Expand Down

0 comments on commit a8bbcd5

Please sign in to comment.