feat: Enhance artifact handling in CI workflow with verification and manifest generation

This commit is contained in:
Janez T
2025-10-22 17:18:50 +02:00
parent 0d12ca0ae7
commit 049199fdfb

View File

@@ -461,6 +461,14 @@ jobs:
with: with:
path: artifacts path: artifacts
- name: Verify downloaded artifacts
run: |
echo "=== Verifying downloaded artifacts structure ==="
ls -lah artifacts/ || echo "No artifacts directory found!"
echo ""
echo "=== All files in artifacts directory ==="
find artifacts -type f -ls || echo "No files found!"
- name: Checkout code for git log - name: Checkout code for git log
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
@@ -511,79 +519,72 @@ jobs:
mkdir -p r2-upload/unstable/latest mkdir -p r2-upload/unstable/latest
fi fi
# Copy and rename artifacts with metadata # Helper function to copy artifact
if [ -f artifacts/android-apk/app-release.apk ]; then copy_artifact() {
cp artifacts/android-apk/app-release.apk \ local src_path="$1"
"r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.apk" local dest_name="$2"
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then local platform="$3"
cp artifacts/android-apk/app-release.apk \
"r2-upload/unstable/latest/meshcore-sar-latest.apk"
fi
fi
if [ -f artifacts/android-appbundle/app-release.aab ]; then if [ -f "$src_path" ]; then
cp artifacts/android-appbundle/app-release.aab \ echo "✅ Copying $platform: $src_path"
"r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.aab" cp "$src_path" \
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/$dest_name"
cp artifacts/android-appbundle/app-release.aab \
"r2-upload/unstable/latest/meshcore-sar-latest.aab"
fi
fi
if [ -f artifacts/macos-dmg/MeshCore-SAR.dmg ]; then
cp artifacts/macos-dmg/MeshCore-SAR.dmg \
"r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.dmg"
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then
cp artifacts/macos-dmg/MeshCore-SAR.dmg \ local latest_name="${dest_name/${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}/latest}"
"r2-upload/unstable/latest/meshcore-sar-latest.dmg" cp "$src_path" "r2-upload/unstable/latest/$latest_name"
fi fi
return 0
else
echo "⚠️ Skipping $platform: $src_path not found"
return 1
fi fi
}
if [ -f artifacts/windows-executable/MeshCore-SAR-Windows.zip ]; then # Copy Android APK
cp artifacts/windows-executable/MeshCore-SAR-Windows.zip \ copy_artifact \
"r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}-windows.zip" "artifacts/android-apk/app-release.apk" \
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then "meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.apk" \
cp artifacts/windows-executable/MeshCore-SAR-Windows.zip \ "Android APK"
"r2-upload/unstable/latest/meshcore-sar-latest-windows.zip"
fi # Copy Android App Bundle
fi copy_artifact \
"artifacts/android-appbundle/app-release.aab" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.aab" \
"Android App Bundle"
# Copy macOS DMG
copy_artifact \
"artifacts/macos-dmg/MeshCore-SAR.dmg" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}.dmg" \
"macOS DMG"
# Copy Windows ZIP
copy_artifact \
"artifacts/windows-executable/MeshCore-SAR-Windows.zip" \
"meshcore-sar-${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}-windows.zip" \
"Windows ZIP"
# Copy commits data # Copy commits data
if [ -f commits.json ]; then if [ -f commits.json ]; then
echo "✅ Copying commits.json"
cp commits.json "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/" cp commits.json "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/"
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then
cp commits.json "r2-upload/unstable/latest/" cp commits.json "r2-upload/unstable/latest/"
fi fi
else
echo "⚠️ commits.json not found"
fi fi
# Create a build manifest echo ""
cat > "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/manifest.json" <<EOF echo "=== Preparation Summary ==="
{ echo "Files prepared in r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}:"
"build_id": "${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}", ls -lh "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/" || echo " (none)"
"commit": "${{ github.sha }}",
"commit_short": "${{ steps.metadata.outputs.commit_short }}",
"branch": "${{ steps.metadata.outputs.branch_name }}",
"tag": "${GITHUB_REF#refs/tags/}",
"timestamp": "${{ steps.metadata.outputs.timestamp }}",
"workflow_run": "${{ github.run_number }}",
"artifacts": $(ls -1 r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/ | grep -v manifest.json | grep -v commits.json | jq -R . | jq -s .)
}
EOF
# Create manifest for 'latest' if main branch
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then
cat > "r2-upload/unstable/latest/manifest.json" <<EOF echo ""
{ echo "Files prepared in r2-upload/unstable/latest:"
"build_id": "${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}", ls -lh "r2-upload/unstable/latest/" || echo " (none)"
"commit": "${{ github.sha }}",
"commit_short": "${{ steps.metadata.outputs.commit_short }}",
"branch": "${{ steps.metadata.outputs.branch_name }}",
"tag": "${GITHUB_REF#refs/tags/}",
"timestamp": "${{ steps.metadata.outputs.timestamp }}",
"workflow_run": "${{ github.run_number }}",
"artifacts": $(ls -1 r2-upload/unstable/latest/ | grep -v manifest.json | grep -v commits.json | jq -R . | jq -s .)
}
EOF
fi fi
- name: Generate index.html - name: Generate index.html
@@ -936,7 +937,9 @@ jobs:
# Add commit history section # Add commit history section
if [ -f "$BUILD_DIR/commits.json" ]; then if [ -f "$BUILD_DIR/commits.json" ]; then
cat >> "$BUILD_DIR/index.html" <<'HTMLEOF' # Read commits JSON and embed it directly in the HTML
COMMITS_DATA=$(cat "$BUILD_DIR/commits.json")
cat >> "$BUILD_DIR/index.html" <<HTMLEOF
</div> </div>
<div class="commits-section"> <div class="commits-section">
@@ -957,17 +960,18 @@ jobs:
</div> </div>
<script> <script>
// Load and display commits // Embedded commits data (no fetch needed)
fetch('commits.json') const commitsData = ${COMMITS_DATA};
.then(response => response.json())
.then(commits => { // Display commits
(function() {
const list = document.getElementById('commits-list'); const list = document.getElementById('commits-list');
if (commits.length === 0) { if (!commitsData || commitsData.length === 0) {
list.innerHTML = '<p style="color: #888;">No commit data available</p>'; list.innerHTML = '<p style="color: #888;">No commit data available</p>';
return; return;
} }
list.innerHTML = commits.map(commit => { list.innerHTML = commitsData.map(commit => {
const date = new Date(commit.date); const date = new Date(commit.date);
const dateStr = date.toLocaleString('en-US', { const dateStr = date.toLocaleString('en-US', {
year: 'numeric', year: 'numeric',
@@ -988,11 +992,7 @@ jobs:
</div> </div>
\`; \`;
}).join(''); }).join('');
}) })();
.catch(error => {
document.getElementById('commits-list').innerHTML =
'<p style="color: #888;">Failed to load commits</p>';
});
</script> </script>
</body> </body>
</html> </html>
@@ -1035,6 +1035,52 @@ jobs:
ls -lah "$LATEST_DIR/" ls -lah "$LATEST_DIR/"
fi fi
- name: Create build manifests
run: |
# Create manifest for build-specific directory (after index.html is generated)
cat > "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/manifest.json" <<EOF
{
"build_id": "${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}",
"commit": "${{ github.sha }}",
"commit_short": "${{ steps.metadata.outputs.commit_short }}",
"branch": "${{ steps.metadata.outputs.branch_name }}",
"tag": "${GITHUB_REF#refs/tags/}",
"timestamp": "${{ steps.metadata.outputs.timestamp }}",
"workflow_run": "${{ github.run_number }}",
"artifacts": $(ls -1 r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/ | grep -v manifest.json | grep -v commits.json | jq -R . | jq -s .)
}
EOF
echo "Generated manifest for build ${{ steps.metadata.outputs.build_prefix }}"
cat "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/manifest.json"
# Create manifest for 'latest' if main branch
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then
cat > "r2-upload/unstable/latest/manifest.json" <<EOF
{
"build_id": "${{ steps.metadata.outputs.build_prefix }}-${{ steps.metadata.outputs.timestamp }}",
"commit": "${{ github.sha }}",
"commit_short": "${{ steps.metadata.outputs.commit_short }}",
"branch": "${{ steps.metadata.outputs.branch_name }}",
"tag": "${GITHUB_REF#refs/tags/}",
"timestamp": "${{ steps.metadata.outputs.timestamp }}",
"workflow_run": "${{ github.run_number }}",
"artifacts": $(ls -1 r2-upload/unstable/latest/ | grep -v manifest.json | grep -v commits.json | jq -R . | jq -s .)
}
EOF
echo "Generated manifest for latest"
cat "r2-upload/unstable/latest/manifest.json"
fi
# Final debug output
echo "=== Final files ready for upload ==="
echo "Build-specific directory:"
ls -lah "r2-upload/unstable/${{ steps.metadata.outputs.build_prefix }}/"
if [ "${{ steps.metadata.outputs.branch_name }}" == "main" ]; then
echo "Latest directory:"
ls -lah "r2-upload/unstable/latest/"
fi
- name: Upload build-specific artifacts to Cloudflare R2 - name: Upload build-specific artifacts to Cloudflare R2
uses: ryand56/r2-upload-action@latest uses: ryand56/r2-upload-action@latest
with: with: