simpliplay-desktop/.github/workflows/draft-release.yml
2025-08-06 18:12:01 -05:00

112 lines
3.9 KiB
YAML

name: Draft Release
on:
workflow_dispatch:
jobs:
create-draft-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare folder
run: mkdir -p all-artifacts
- name: Poll for expected artifacts
run: |
echo "Polling (every 15 seconds) until all required artifacts are available..."
REQUIRED=("linux-x64-appimage" "linux-x64-snap" "linux-arm64-snap" "builds" "builds-x64" "builds-arm64")
while true; do
echo "⏳ Checking artifacts..."
# Clean up and re-download artifacts each poll
rm -rf all-artifacts
mkdir -p all-artifacts
# Download all available artifacts for this run
gh run download --dir all-artifacts || true
missing=0
for ARTIFACT in "${REQUIRED[@]}"; do
if [ ! -d "all-artifacts/$ARTIFACT" ]; then
echo "❌ Missing: $ARTIFACT"
missing=1
fi
done
if [ "$missing" -eq 0 ]; then
echo "✅ All required artifacts found."
break
fi
echo "🔁 Not all artifacts found. Retrying in 15 seconds..."
sleep 15
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract ZIP files and prepare list of files to upload
run: |
echo "🔍 Extracting ZIP files and collecting allowed SimpliPlay files..."
# Extract all ZIPs to their own folder
find all-artifacts -type f -name '*.zip' | while read zipfile; do
extract_dir="${zipfile%.zip}"
echo "📦 Extracting $zipfile to $extract_dir"
unzip -o "$zipfile" -d "$extract_dir"
done
# Prepare list for upload-files.txt, only SimpliPlay* with allowed extensions
rm -f upload-files.txt
find all-artifacts -type f \( -iname '*.exe' -o -iname '*.dmg' -o -iname '*.snap' -o -iname '*.AppImage' \) | \
grep 'SimpliPlay' > upload-files.txt
echo "Filtered files to upload:"
cat upload-files.txt
- name: Rename files if duplicates exist on release
id: rename
run: |
release_tag="draft-${{ github.run_number }}"
existing_assets=$(gh release view "$release_tag" --json assets --jq '.assets[].name' || echo "")
echo "Existing assets on release $release_tag:"
echo "$existing_assets"
# Prepare a new upload list with renamed files if needed
rm -f upload-files-renamed.txt
touch upload-files-renamed.txt
while IFS= read -r filepath; do
filename=$(basename "$filepath")
dirname=$(basename $(dirname "$filepath"))
if echo "$existing_assets" | grep -qx "$filename"; then
# rename to avoid conflict, e.g., append source folder
extension="${filename##*.}"
name="${filename%.*}"
newname="${name}-${dirname}.${extension}"
echo "Renaming $filename to $newname because it exists in release"
cp "$filepath" "all-artifacts/$newname"
echo "all-artifacts/$newname" >> upload-files-renamed.txt
else
echo "$filepath" >> upload-files-renamed.txt
fi
done < upload-files.txt
echo "Final list of files to upload:"
cat upload-files-renamed.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub Draft Release
uses: softprops/action-gh-release@v2
with:
tag_name: "draft-${{ github.run_number }}"
draft: true
files: ${{ join(fromJSON(format('["%s"]', join(fromFile('upload-files-renamed.txt'), '","'))), ' ') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}