From a8bbcd5d8b85141051cb6fba4f01ac35e0caddaf Mon Sep 17 00:00:00 2001 From: Matilda-Clerke Date: Thu, 29 Aug 2024 12:23:44 +1000 Subject: [PATCH] Check for commit hash before appending another in build.gradle caclulateVersion (#7537) Signed-off-by: Matilda Clerke --- build.gradle | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 690c0fb39f5..6211183a7a5 100644 --- a/build.gradle +++ b/build.gradle @@ -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}"