From 53d28026acfee3086c4f191305bb73803e3826f8 Mon Sep 17 00:00:00 2001 From: Boulay Mathias Date: Tue, 20 Jun 2023 11:38:06 +0200 Subject: [PATCH] Fix[build]: Fallback for versions on shallow repositories (#4285) --- .github/workflows/android.yml | 1 + app_pojavlauncher/build.gradle | 39 +++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 5e7dc37e3..30c5e4d11 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -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 diff --git a/app_pojavlauncher/build.gradle b/app_pojavlauncher/build.gradle index 4bc5ca66b..d621c5f08 100644 --- a/app_pojavlauncher/build.gradle +++ b/app_pojavlauncher/build.gradle @@ -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 {