From 53057f4e1886b3cda58ebea514bc47f43711aa06 Mon Sep 17 00:00:00 2001
From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
Date: Sun, 5 Feb 2023 23:35:49 +0000
Subject: [PATCH] Update push-docker.yml (#38)

---
 .github/workflows/push-docker.yml | 25 +++++++++++++++++++++----
 build.gradle                      |  2 +-
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/push-docker.yml b/.github/workflows/push-docker.yml
index 11715792..93225818 100644
--- a/.github/workflows/push-docker.yml
+++ b/.github/workflows/push-docker.yml
@@ -4,6 +4,7 @@ on:
   push:
     branches: 
       - master
+      - testGit
       - main
 jobs:
   push:
@@ -37,20 +38,36 @@ jobs:
       with:
         username: ${{ secrets.DOCKER_HUB_USERNAME }}
         password: ${{ secrets.DOCKER_HUB_API }} 
-        
+   
+    - name: Check if tag exists
+      id: checkIdExists
+      continue-on-error: true
+      run: |
+        response=$(curl -s https://hub.docker.com/v2/repositories/frooodle/s-pdf/tags/?name=${{ steps.versionNumber.outputs.versionNumber }})
+        result=$(echo $response | jq ".results")
+        if [ "$result" == "[]" ]; then
+          echo "Tag ${{ steps.versionNumber.outputs.versionNumber }} doesnt exist. Continuing with build and push."
+        else
+          echo "Tag ${{ steps.versionNumber.outputs.versionNumber }} already exists. Skipping build and push."
+          exit 1;
+        fi
+
+   
+   
     - name: Setup buildx
+      if: steps.checkIdExists.outcome != 'failure'
       run: |
         docker buildx create --name mybuilder
         docker buildx use mybuilder
         
-    - name: Build and push versioned amd64 and v8
-      if: github.ref == 'refs/heads/main' 
+    - name: Build and push versioned amd64 and v8 
+      if: github.ref == 'refs/heads/main' && steps.checkIdExists.outcome != 'failure'
       run: | 
         docker buildx build --platform="linux/amd64,linux/arm64/v8" --push --tag "frooodle/s-pdf:${{ steps.versionNumber.outputs.versionNumber }}" .
 
    
     - name: Build and push latest amd64 and v8
-      if: github.ref == 'refs/heads/master' 
+      if: github.ref == 'refs/heads/master' && steps.checkIdExists.outcome != 'failure'
       run: | 
         docker buildx build --platform="linux/amd64,linux/arm64/v8" --push --tag "frooodle/s-pdf:latest" .
         
diff --git a/build.gradle b/build.gradle
index c514b8a8..b6251022 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ plugins {
 }
 
 group = 'stirling.software'
-version = '0.3.1'
+version = '0.3.2'
 sourceCompatibility = '17'
 
 repositories {