SDL: ci: retry package creation multiple times

From a50e0319d5c41a434d0f2d776a309d54745c3c3d Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Thu, 16 May 2024 20:56:00 +0200
Subject: [PATCH] ci: retry package creation multiple times

DMG creation on macOS occasionally fails, so try multiple times
https://gitlab.kitware.com/cmake/cmake/-/issues/25671
---
 .github/workflows/main.yml | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 00c84e90fc50c..46cc370a8bcee 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -139,7 +139,22 @@ jobs:
     - name: Package (CPack)
       if: ${{ always() && steps.build.outcome == 'success' }}
       run: |
-        cmake --build build/ --config Release --target package
+        # DMG creation on macOS occasionally fails, so try multiple times
+        # https://gitlab.kitware.com/cmake/cmake/-/issues/25671
+        success=0
+        max_tries=10
+        for i in $(seq $max_tries); do
+         cmake --build build/ --config Release --target package && success=1
+         if test $success = 1; then
+          break
+         fi
+         echo "Package creation failed. Sleep 1 second and try again."
+         sleep 1
+        done
+        if test $success = 0; then
+         echo "Package creation failed after $max_tries attempts."
+         exit 1
+        fi
     - name: Verify CMake configuration files
       run: |
         ${{ matrix.platform.source_cmd }}