Fix[build]: Fallback for versions on shallow repositories (#4285)

This commit is contained in:
Boulay Mathias 2023-06-20 11:38:06 +02:00 committed by GitHub
parent e74e2e1205
commit 53d28026ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 5 deletions

View File

@ -16,6 +16,7 @@ jobs:
env:
GPLAY_KEYSTORE_PASSWORD: ${{ secrets.GPLAY_KEYSTORE_PASSWORD }}
steps:
- name: Checkout
- uses: actions/checkout@v3
- name: Set up JDK 8

View File

@ -16,28 +16,57 @@ def getVersionName = {
// Get the last version tag, as well as the short head of the last commit
ByteArrayOutputStream TAG = new ByteArrayOutputStream()
ByteArrayOutputStream BRANCH = new ByteArrayOutputStream()
// Used by the fallback for github actions
ByteArrayOutputStream TAG_PART_COMMIT = new ByteArrayOutputStream()
String TAG_STRING
exec {
try {
commandLine 'git', 'describe', '--tags'
ignoreExitValue true
standardOutput = TAG
} catch (Exception e) {
e.printStackTrace();
}
}
if (TAG.toString() == "") {
exec {
// Fallback for action builds
try {
commandLine 'git', 'describe', '--always', '--tags'
ignoreExitValue true
standardOutput = TAG_PART_COMMIT
} catch (Exception e) {
}
}
}
if(TAG.toString() != ""){
TAG_STRING = TAG.toString()
}else {
if(TAG_PART_COMMIT.toString().trim() == ""){
//Fallback no repo
return ("LOCAL-" + "${getDate()}")
}else {
// Used by github actions
TAG_STRING = 'dahlia-' + "${getDate()}" + "-" + TAG_PART_COMMIT.toString().trim()
}
}
exec {
try {
commandLine 'git', 'branch', '--show-current'
ignoreExitValue true
standardOutput = BRANCH
} catch (Exception e) {
e.printStackTrace();
}
}
if (TAG.toString() == "") {
return ("LOCAL-" + "${getDate()}")
}
return TAG.toString().trim().replace("-g", "-") + "-" + BRANCH.toString().trim()
return TAG_STRING.trim().replace("-g", "-") + "-" + BRANCH.toString().trim()
}
configurations {