From bd81a32dbcf595f7691059149181461e569ca366 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Tue, 29 Jun 2021 10:20:08 +0200
Subject: [PATCH] Skip tag creation if tag already exists

---
 .gitlab-ci.yml | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 61b8c8f..51134c3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -94,8 +94,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
-- 
GitLab