From 4bf6e5c3c3899dc89d5cf7df9f3bb43f314bae52 Mon Sep 17 00:00:00 2001
From: Pieter van Staden <pieter@bob.co.za>
Date: Mon, 5 May 2025 14:32:16 +0200
Subject: [PATCH] INFRASTRUCTURE :: Update the check to make sure the tag is
 created from the prod branch

---
 .gitlab-ci.yml | 10 ++++++++--
 composer.json  |  2 +-
 etc/module.xml |  2 +-
 package.json   |  2 +-
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6ad2e34..7862434 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -33,9 +33,15 @@ tag_deploy:
     - AWS_SECRET_ACCESS_KEY=$(eval echo -e "\$$AWS_SECRET_ACCESS_KEY_KEY")
     - export AWS_ACCESS_KEY_ID
     - export AWS_SECRET_ACCESS_KEY
+    # Fetch the prod branch
     - git fetch origin prod
-    - COMMIT_BRANCH=$(git branch -r --contains $CI_COMMIT_SHA | grep "origin/prod" || echo "")
-    - if [ -z "$COMMIT_BRANCH" ]; then echo "Tag was not created from prod branch. Skipping deployment."; exit 1; fi
+    # Check if the tagged commit is from the prod branch using merge-base
+    - if git merge-base --is-ancestor "${CI_COMMIT_SHA}" origin/prod; then
+      echo "Tag ${CI_COMMIT_TAG} is from the prod branch.";
+      else
+      echo "Tag ${CI_COMMIT_TAG} is not from the prod branch.";
+      exit 1;
+      fi
   script:
     - "TAG_ARCHIVE_URL=https://gitlab.bob.co.za/bob-public-utils/bobgo-magento-extension/-/archive/${CI_COMMIT_TAG}/bobgo-magento-extension-${CI_COMMIT_TAG}.zip"
     - curl -o bobgo-magento-extension-${CI_COMMIT_TAG}.zip "$TAG_ARCHIVE_URL"
diff --git a/composer.json b/composer.json
index be20c4f..4d5f670 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
     "name": "bobgo/bobgo-magento-extension",
     "description": "Smart shipping and order management solution in South Africa",
     "type": "magento2-module",
-    "version": "1.0.51",
+    "version": "1.0.52",
     "authors": [
         {
             "name": "Bob Go",
diff --git a/etc/module.xml b/etc/module.xml
index 3a66e65..89ebeab 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -7,7 +7,7 @@
  */
 -->
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
-    <module name="BobGroup_BobGo" setup_version="1.0.51">
+    <module name="BobGroup_BobGo" setup_version="1.0.52">
         <sequence>
             <module name="Magento_Webapi"/>
             <module name="Magento_Catalog"/>
diff --git a/package.json b/package.json
index 4b950c3..0429860 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "bobgo-magento-plugin",
   "description": "Bob Go magento plugin",
-  "version": "1.0.51",
+  "version": "1.0.52",
   "license": "GPL-2.0-or-later",
   "scripts": {
     "prepare": "husky install",
-- 
GitLab