Skip to content

Commit

Permalink
Detect overridden build name and don't append git tag
Browse files Browse the repository at this point in the history
Use Elvis operator to check for nulls instead of ifs
  • Loading branch information
evgfilim1 committed Jan 30, 2024
1 parent 525c15b commit 4287e06
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,41 @@ if (localPropertiesFile.exists()) {
}
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName') ?: '1.0'
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') ?: '1'

def keystoreAvailable = System.getenv("KEYSTORE_PASSWORD") != null
&& System.getenv("KEY_PASSWORD") != null

static Boolean isGitRepository() {
def isGitRepository = {
try {
def proc = "git rev-parse --is-inside-work-tree".execute()
proc.waitFor()
return proc.exitValue() == 0
} catch (ignored) {
return false
}
}
}()

static String getGitSuffix() {
if (!isGitRepository()) {
def isFlutterVersionOverridden = {
if (!isGitRepository) {
return false
}
try {
def proc = "git describe --tags --abbrev=0".execute()
proc.waitFor()
def tag = proc.text.trim().replaceFirst(/^v/, "")
return tag != flutterVersionName
} catch (ignored) {
return false
}
}()

def gitSuffix = {
if (!isGitRepository) {
return ""
}
if (isFlutterVersionOverridden) {
return ""
}
def proc = "git describe --tags --always --dirty".execute()
Expand All @@ -52,7 +62,7 @@ static String getGitSuffix() {
result += match[3]
}
return result
}
}()

android {
namespace 'me.evgfilim1.mafia_companion'
Expand All @@ -78,7 +88,8 @@ android {
minSdkVersion ([flutter.minSdkVersion, 19].max())
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName + getGitSuffix()
versionName flutterVersionName + gitSuffix
//println("Version name: $versionName")
}

signingConfigs {
Expand Down

0 comments on commit 4287e06

Please sign in to comment.