feat: Enhance artifact downloading and uploading process in CI workflow

This commit is contained in:
Janez T
2025-10-22 17:33:48 +02:00
parent 049199fdfb
commit 581521ff2e

View File

@@ -456,18 +456,54 @@ jobs:
if: always() && (needs.build-android.result == 'success' || needs.build-ios.result == 'success' || needs.build-macos.result == 'success' || needs.build-windows.result == 'success') if: always() && (needs.build-android.result == 'success' || needs.build-ios.result == 'success' || needs.build-macos.result == 'success' || needs.build-windows.result == 'success')
steps: steps:
- name: Download all artifacts - name: Download Android APK
if: needs.build-android.result == 'success'
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
continue-on-error: true
with: with:
path: artifacts name: android-apk
path: artifacts/android-apk
- name: Download Android App Bundle
if: needs.build-android.result == 'success'
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: android-appbundle
path: artifacts/android-appbundle
- name: Download macOS DMG
if: needs.build-macos.result == 'success'
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: macos-dmg
path: artifacts/macos-dmg
- name: Download Windows Executable
if: needs.build-windows.result == 'success'
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: windows-executable
path: artifacts/windows-executable
- name: Verify downloaded artifacts - name: Verify downloaded artifacts
run: | run: |
echo "=== Verifying downloaded artifacts structure ===" echo "=== Downloaded build artifacts for R2 upload ==="
ls -lah artifacts/ || echo "No artifacts directory found!" if [ -d artifacts ]; then
echo "" echo "Directory structure:"
echo "=== All files in artifacts directory ===" ls -laR artifacts/
find artifacts -type f -ls || echo "No files found!" echo ""
echo "All files:"
find artifacts -type f -ls 2>/dev/null || echo "No files found"
echo ""
echo "=== File sizes ==="
find artifacts -type f -exec du -h {} \; 2>/dev/null || echo "No artifacts to measure"
else
echo "⚠️ No artifacts directory - all builds may have failed"
exit 1
fi
- name: Checkout code for git log - name: Checkout code for git log
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -519,49 +555,57 @@ jobs:
mkdir -p r2-upload/unstable/latest mkdir -p r2-upload/unstable/latest
fi fi
# Helper function to copy artifact # Helper function to find and copy artifact
copy_artifact() { copy_artifact() {
local src_path="$1" local search_dir="$1"
local dest_name="$2" local pattern="$2"
local platform="$3" local dest_name="$3"
local platform="$4"
if [ -f "$src_path" ]; then # Find the file matching the pattern
echo "✅ Copying $platform: $src_path" local src_file=$(find "$search_dir" -type f -name "$pattern" 2>/dev/null | head -1)
cp "$src_path" \
if [ -n "$src_file" ] && [ -f "$src_file" ]; then
echo "✅ Copying $platform: $src_file"
cp "$src_file" \
"r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/$dest_name" "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/$dest_name"
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then
local latest_name="${dest_name/${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}/latest}" local latest_name="${dest_name/${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}/latest}"
cp "$src_path" "r2-upload/unstable/latest/$latest_name" cp "$src_file" "r2-upload/unstable/latest/$latest_name"
fi fi
return 0 return 0
else else
echo "⚠️ Skipping $platform: $src_path not found" echo "⚠️ Skipping $platform: No file matching '$pattern' found in $search_dir"
return 1 return 1
fi fi
} }
# Copy Android APK # Copy Android APK (search for any .apk file)
copy_artifact \ copy_artifact \
"artifacts/android-apk/app-release.apk" \ "artifacts/android-apk" \
"*.apk" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.apk" \ "meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.apk" \
"Android APK" "Android APK"
# Copy Android App Bundle # Copy Android App Bundle (search for any .aab file)
copy_artifact \ copy_artifact \
"artifacts/android-appbundle/app-release.aab" \ "artifacts/android-appbundle" \
"*.aab" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.aab" \ "meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.aab" \
"Android App Bundle" "Android App Bundle"
# Copy macOS DMG # Copy macOS DMG (search for any .dmg file)
copy_artifact \ copy_artifact \
"artifacts/macos-dmg/MeshCore-SAR.dmg" \ "artifacts/macos-dmg" \
"*.dmg" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.dmg" \ "meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.dmg" \
"macOS DMG" "macOS DMG"
# Copy Windows ZIP # Copy Windows ZIP (search for any .zip file)
copy_artifact \ copy_artifact \
"artifacts/windows-executable/MeshCore-SAR-Windows.zip" \ "artifacts/windows-executable" \
"*.zip" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}-windows.zip" \ "meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}-windows.zip" \
"Windows ZIP" "Windows ZIP"
@@ -1082,6 +1126,7 @@ jobs:
fi fi
- name: Upload build-specific artifacts to Cloudflare R2 - name: Upload build-specific artifacts to Cloudflare R2
if: hashFiles('r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/*') != ''
uses: ryand56/r2-upload-action@latest uses: ryand56/r2-upload-action@latest
with: with:
r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-account-id: ${{ secrets.R2_ACCOUNT_ID }}
@@ -1092,7 +1137,7 @@ jobs:
destination-dir: unstable/${{ steps.metadata.outputs.build_prefix }} destination-dir: unstable/${{ steps.metadata.outputs.build_prefix }}
- name: Upload latest artifacts to Cloudflare R2 (main branch only) - name: Upload latest artifacts to Cloudflare R2 (main branch only)
if: steps.metadata.outputs.branch_name == 'main' if: steps.metadata.outputs.branch_name == 'main' && hashFiles('r2-upload/unstable/latest/*') != ''
uses: ryand56/r2-upload-action@latest uses: ryand56/r2-upload-action@latest
with: with:
r2-account-id: ${{ secrets.R2_ACCOUNT_ID }} r2-account-id: ${{ secrets.R2_ACCOUNT_ID }}