fix(actions): streamline DMG creation process in macOS notarization workflow by implementing direct hdiutil approach and improving fallback mechanisms for package creation

This commit is contained in:
Ozgur 2025-04-17 14:09:53 +02:00
parent 8046bc9105
commit 8193d167c5
No known key found for this signature in database
GPG Key ID: 66CDF27505A35546

View File

@ -205,104 +205,52 @@ jobs:
# Ensure app is in the expected location after notarization
APP_PATH="${{ env.APP_PATH }}"
# Create directories for installer and DMG
mkdir -p "./PackagedReleases"
BUILD_DIR="./PackagedReleases/LuckyWorldInstall"
rm -rf "$BUILD_DIR" 2>/dev/null || true
mkdir -p "$BUILD_DIR"
# Direct DMG creation approach for CI
echo "Creating DMG directly with hdiutil for CI environment..."
# Copy app and installation script to build directory
echo "Copying app and installation script..."
cp -R "$APP_PATH" "$BUILD_DIR/"
cp "./scripts/install_luckyworld.sh" "$BUILD_DIR/"
chmod +x "$BUILD_DIR/install_luckyworld.sh"
# Setup directories
mkdir -p "./PackagedReleases/Install"
rm -rf "./PackagedReleases/Install/*" 2>/dev/null || true
# Create a simple README file
cat > "$BUILD_DIR/README.txt" << EOF
LuckyWorld Installation
======================
# Copy the app and installer to package directory
cp -R "$APP_PATH" "./PackagedReleases/Install/"
cp "./scripts/install_luckyworld.sh" "./PackagedReleases/Install/"
chmod +x "./PackagedReleases/Install/install_luckyworld.sh"
# Create a simple README
cat > "./PackagedReleases/Install/README.txt" << EOF
LuckyWorld Installer
===================
1. Double-click "install_luckyworld.sh" to install the application
2. Follow the on-screen instructions
1. Double-click 'install_luckyworld.sh' to install
2. Follow on-screen instructions
For support, visit: https://luckyrobots.io
For help: https://luckyrobots.io
EOF
# Set the desired DMG path
# Create DMG using direct hdiutil approach (native macOS command)
CUSTOM_DMG_PATH="./PackagedReleases/LuckyWorld-Installer.dmg"
rm -f "$CUSTOM_DMG_PATH" 2>/dev/null || true
# Try first with create-dmg if it's available
if command -v create-dmg &> /dev/null; then
echo "Using create-dmg to create DMG file..."
# First attempt: Using create-dmg with no-finder (CI-friendly approach)
set +e # Don't exit on error
create-dmg \
--volname "LuckyWorld Installer" \
--window-pos 200 120 \
--window-size 800 500 \
--icon-size 128 \
--icon "LuckyWorld.app" 200 250 \
--icon "install_luckyworld.sh" 400 250 \
--icon "README.txt" 600 250 \
--hide-extension "LuckyWorld.app" \
--hide-extension "install_luckyworld.sh" \
--app-drop-link 400 120 \
--no-internet-enable \
--skip-jenkins \
--no-finder \
"$CUSTOM_DMG_PATH" \
"$BUILD_DIR"
CREATE_DMG_STATUS=$?
set -e # Re-enable exit on error
if [ $CREATE_DMG_STATUS -ne 0 ]; then
echo "create-dmg failed, trying with hdiutil as fallback..."
else
echo "create-dmg succeeded!"
fi
else
echo "create-dmg not found, using hdiutil instead."
CREATE_DMG_STATUS=1
hdiutil create -volname "LuckyWorld Installer" -srcfolder "./PackagedReleases/Install" -ov -format UDZO "$CUSTOM_DMG_PATH"
if [ $? -ne 0 ]; then
echo "❌ DMG creation failed! Creating a ZIP file as fallback..."
( cd "./PackagedReleases" && zip -r "LuckyWorld-Installer.zip" "Install" )
CUSTOM_DMG_PATH="./PackagedReleases/LuckyWorld-Installer.zip"
fi
# Fallback to hdiutil if create-dmg failed or is not available
if [ ! -f "$CUSTOM_DMG_PATH" ] || [ $CREATE_DMG_STATUS -ne 0 ]; then
echo "Creating DMG with hdiutil (direct macOS command)..."
# Remove old DMG if exists
rm -f "$CUSTOM_DMG_PATH" 2>/dev/null || true
# Create DMG with hdiutil
hdiutil create \
-volname "LuckyWorld Installer" \
-srcfolder "$BUILD_DIR" \
-ov \
-format UDZO \
"$CUSTOM_DMG_PATH"
if [ $? -ne 0 ]; then
echo "❌ hdiutil DMG creation failed. Providing ZIP as fallback..."
# As a last resort, create a ZIP file
echo "Creating ZIP archive as fallback..."
(cd "./PackagedReleases" && zip -r "LuckyWorld-Installer.zip" "LuckyWorldInstall")
CUSTOM_DMG_PATH="./PackagedReleases/LuckyWorld-Installer.zip"
fi
fi
# Check if any package was created
if [ -f "$CUSTOM_DMG_PATH" ]; then
echo "✅ Package created successfully: $CUSTOM_DMG_PATH"
echo "Size: $(du -h "$CUSTOM_DMG_PATH" | cut -f1)"
echo "CUSTOM_DMG_PATH=$CUSTOM_DMG_PATH" >> $GITHUB_ENV
else
echo "❌ Failed to create any package file"
echo "❌ Failed to create installation package"
exit 1
fi
# Export the path for later steps
echo "CUSTOM_DMG_PATH=$CUSTOM_DMG_PATH" >> $GITHUB_ENV
# Clean up build directory
rm -rf "$BUILD_DIR"
# Clean up temporary directory
rm -rf "./PackagedReleases/Install"
shell: bash
# Upload the custom DMG with installer script