fix: Enhance artifact copying logic to skip missing directories without failing the build

This commit is contained in:
Janez T
2025-10-22 20:20:27 +02:00
parent 0955d0feab
commit 07f45005c5

View File

@@ -566,60 +566,69 @@ jobs:
local dest_name="$3" local dest_name="$3"
local platform="$4" local platform="$4"
# Check if directory exists first; don't fail the whole step if missing.
if [ ! -d "$search_dir" ]; then
echo "⚠️ Skipping $platform: Directory $search_dir not found (build may have been skipped)"
return 0
fi
# Find the file matching the pattern # Find the file matching the pattern
local src_file=$(find "$search_dir" -type f -name "$pattern" 2>/dev/null | head -1) local src_file=$(find "$search_dir" -type f -name "$pattern" 2>/dev/null | head -1)
if [ -n "$src_file" ] && [ -f "$src_file" ]; then if [ -n "$src_file" ] && [ -f "$src_file" ]; then
echo "✅ Copying $platform: $src_file" echo "✅ Copying $platform: $src_file -> $dest_name"
cp "$src_file" "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/$dest_name" || true cp "$src_file" "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/$dest_name" || {
echo "⚠️ Failed to copy $src_file"
return 1
}
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then
# Copy the same dest filename into the 'latest' folder for simplicity
cp "$src_file" "r2-upload/unstable/latest/$dest_name" || true cp "$src_file" "r2-upload/unstable/latest/$dest_name" || true
fi fi
return 0
else else
echo "⚠️ Skipping $platform: No file matching '$pattern' found in $search_dir" echo "⚠️ Skipping $platform: No file matching '$pattern' found in $search_dir"
return 1
fi fi
# Always succeed (so missing optional artifacts don't fail the whole job)
return 0
} }
# Copy Android APK (search for any .apk file) # Copy Android APK (search for any .apk file in artifacts/android-apk)
copy_artifact \ if [ -d "artifacts/android-apk" ]; then
"artifacts/android-apk" \ copy_artifact \
"*.apk" \ "artifacts/android-apk" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.apk" \ "*.apk" \
"Android APK" "meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.apk" \
"Android APK"
else
echo "⚠️ Skipping Android APK: Directory artifacts/android-apk not found"
fi
# Copy Android App Bundle (search for any .aab file) # Copy Android App Bundle (search for any .aab file)
copy_artifact \ if [ -d "artifacts/android-appbundle" ]; then
"artifacts/android-appbundle" \ copy_artifact \
"*.aab" \ "artifacts/android-appbundle" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.aab" \ "*.aab" \
"Android App Bundle" "meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.aab" \
"Android App Bundle"
else
echo "⚠️ Skipping Android App Bundle: Directory artifacts/android-appbundle not found"
fi
# Copy macOS DMG (search for any .dmg file) # Copy macOS DMG (search for any .dmg file)
copy_artifact \ if [ -d "artifacts/macos-dmg" ]; then
"artifacts/macos-dmg" \ copy_artifact \
"*.dmg" \ "artifacts/macos-dmg" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.dmg" \ "*.dmg" \
"macOS DMG" "meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.dmg" \
"macOS DMG"
else
echo "⚠️ Skipping macOS DMG: Directory artifacts/macos-dmg not found"
fi
# Copy Windows ZIP (search for any .zip file) # Copy Windows ZIP (search for any .zip file)
copy_artifact \ if [ -d "artifacts/windows-executable" ]; then
"artifacts/windows-executable" \ copy_artifact \
"*.zip" \ "artifacts/windows-executable" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}-windows.zip" \ "*.zip" \
"Windows ZIP" "meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}-windows.zip" \
"Windows ZIP"
# Note: Each copy_artifact returns 0 even if missing, so partial builds succeed else
echo "⚠️ Skipping Windows ZIP: Directory artifacts/windows-executable not found"
fi
# Copy commits data # Copy commits data
if [ -f commits.json ]; then if [ -f commits.json ]; then