From a93ab80536d589f194a0efa311094c1ec0533138 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Tue, 29 Jun 2021 18:52:09 +0200
Subject: [PATCH] Improve CI/CD, fix release, skip jobs

---
 .gitlab-ci.yml            | 27 +++++++++++++++++++++------
 android/gradle.properties |  4 ++--
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 61b8c8f..b3d9a5d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -63,9 +63,19 @@ android:build-release:
     - echo keyAlias=$ANDROID_KEY_ALIAS >> android/key.properties
     - echo keyPassword=$ANDROID_KEY_PASSWORD >> android/key.properties
     # build flutter app
-    - flutter packages get
-    - flutter clean
-    - flutter build apk --release
+    - VERSION_FILE="$(find . -name 'gradle.properties' | head -n1)"
+    - VERSION_NAME="$(grep '^app.versionName=' "${VERSION_FILE}" | cut -d'=' -f2)"
+    - VERSION_CODE="$(grep '^app.versionCode=' "${VERSION_FILE}" | cut -d'=' -f2)"
+    - TAG_NAME="Release_${VERSION_NAME}_${VERSION_CODE}"
+    - echo "${TAG_NAME}"
+    - >
+      if [ $(git tag -l "${TAG_NAME}") ]; then
+        echo "Tag ${TAG_NAME} already exists. Skipping build release."
+      else
+        flutter packages get
+        flutter clean
+        flutter build apk --release
+      fi
     # prepare artifact
     - find . -name "*.apk" # where is my apk?
   artifacts:
@@ -94,8 +104,13 @@ application:release:
     - VERSION_CODE="$(grep '^app.versionCode=' "${VERSION_FILE}" | cut -d'=' -f2)"
     - TAG_NAME="Release_${VERSION_NAME}_${VERSION_CODE}"
     - echo "${TAG_NAME}"
-    - git tag -a "${TAG_NAME}" -m "Release ${VERSION_NAME} (${VERSION_CODE})"
-    - git push origin "${TAG_NAME}"
+    - >
+      if [ $(git tag -l "${TAG_NAME}") ]; then
+        echo "Tag ${TAG_NAME} already exists. Skipping release and tag creation."
+      else
+        git tag -a "${TAG_NAME}" -m "Release ${VERSION_NAME} (${VERSION_CODE})"
+        git push origin "${TAG_NAME}"
+      fi
 
 android:deploy:
   stage: deploy
@@ -104,4 +119,4 @@ android:deploy:
   dependencies:
     - application:release
   script:
-    - wget ${REPOSITORY_UPDATE_WEBHOOK}?token=${REPOSITORY_TOKEN}
+    - curl "${REPOSITORY_UPDATE_WEBHOOK}?token=${REPOSITORY_TOKEN}"
diff --git a/android/gradle.properties b/android/gradle.properties
index e644338..d965699 100644
--- a/android/gradle.properties
+++ b/android/gradle.properties
@@ -1,5 +1,5 @@
 org.gradle.jvmargs=-Xmx1536M
 android.useAndroidX=true
 android.enableJetifier=true
-app.versionName=0.0.28
-app.versionCode=28
+app.versionName=0.0.29
+app.versionCode=29
-- 
GitLab