Add more checks to prevent build failures in gradle branch suffix

- Add function `getGitWorkingBranch` that returns the current working branch, and "" if it could not be determined (either because git is not installed or because the directory is not a git repo).
- Make sure normalizedWorkingBranch is not empty (leading to an invalid app id terminating with `.`)
- Make normalizedWorkingBranch lowercase
- Add comments
This commit is contained in:
Stypox 2020-03-02 20:50:35 +01:00
parent 3434ff4d45
commit 92f4010e8e
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 23 additions and 3 deletions

View File

@ -3,6 +3,24 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
static String getGitWorkingBranch() {
try {
def gitProcess = "git rev-parse --abbrev-ref HEAD".execute()
gitProcess.waitFor()
if (gitProcess.exitValue() == 0) {
return gitProcess.text.trim()
} else {
// not a git repository
return ""
}
} catch (IOException ignored) {
// git was not found
return ""
}
}
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
@ -31,12 +49,14 @@ android {
debuggable true
// suffix the app id and the app name with git branch name
def workingBranch = "git rev-parse --abbrev-ref HEAD".execute().text.trim()
if (workingBranch.isEmpty() || workingBranch == "master" || workingBranch == "dev") {
def workingBranch = getGitWorkingBranch()
def normalizedWorkingBranch = workingBranch.replaceAll("[^A-Za-z]+", "").toLowerCase()
if (normalizedWorkingBranch.isEmpty() || workingBranch == "master" || workingBranch == "dev") {
// default values when branch name could not be determined or is master or dev
applicationIdSuffix ".debug"
resValue "string", "app_name", "NewPipe Debug"
} else {
applicationIdSuffix ".debug." + workingBranch.replaceAll("[^A-Za-z]+", "")
applicationIdSuffix ".debug." + normalizedWorkingBranch
resValue "string", "app_name", "NewPipe " + workingBranch
}
}