From b0986c87cf2300d3ea89d1549d366e736512a116 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Tue, 29 Jun 2021 10:41:59 +0200
Subject: [PATCH] Skip build release if version already built

---
 .gitlab-ci.yml | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 51134c3..6837222 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:
-- 
GitLab