From 1dd4070030e7a386ec48a5dd4390f173cd20674f Mon Sep 17 00:00:00 2001 From: maotoumao Date: Sat, 14 Mar 2026 17:45:57 +0800 Subject: [PATCH] chore: temp --- .github/workflows/artifact-upload-gitcode.yml | 173 ---------- .github/workflows/artifact-upload.yml | 143 -------- .github/workflows/build.yml | 319 +++++++++++------- .github/workflows/release.yml | 98 ++++++ 4 files changed, 287 insertions(+), 446 deletions(-) delete mode 100644 .github/workflows/artifact-upload-gitcode.yml delete mode 100644 .github/workflows/artifact-upload.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/artifact-upload-gitcode.yml b/.github/workflows/artifact-upload-gitcode.yml deleted file mode 100644 index 7c084ce..0000000 --- a/.github/workflows/artifact-upload-gitcode.yml +++ /dev/null @@ -1,173 +0,0 @@ -name: 发布到GitCode - -on: - workflow_dispatch: - inputs: - run_id: - description: 'GitHub Action Run ID to download artifacts from' - required: true - type: string - -jobs: - download-and-upload: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '18' - - - name: Download artifacts from specified run - id: download - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RUN_ID: ${{ github.event.inputs.run_id }} - run: | - echo "Checking artifacts for run ID: $RUN_ID" - - # Get artifacts list for the specified run - artifacts_response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ - "https://api.github.com/repos/${{ github.repository }}/actions/runs/$RUN_ID/artifacts") - - # Check if there are any artifacts - artifacts_count=$(echo "$artifacts_response" | jq '.total_count') - - if [ "$artifacts_count" -eq 0 ]; then - echo "No artifacts found for run ID: $RUN_ID" - echo "has_artifacts=false" >> $GITHUB_OUTPUT - exit 0 - fi - - echo "Found $artifacts_count artifact(s)" - echo "has_artifacts=true" >> $GITHUB_OUTPUT - - # Create downloads directory - mkdir -p ./downloads - - # Download all artifacts - echo "$artifacts_response" | jq -r '.artifacts[] | "\(.id) \(.name)"' | while read artifact_id artifact_name; do - echo "Downloading artifact: $artifact_name (ID: $artifact_id)" - - # Download artifact - curl -L -H "Authorization: token $GITHUB_TOKEN" \ - "https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact_id/zip" \ - -o "./downloads/${artifact_name}.zip" - - echo "Downloaded: ${artifact_name}.zip" - done - - - name: Process and upload artifacts to GitCode - if: steps.download.outputs.has_artifacts == 'true' - env: - GITCODE_PAT: ${{ secrets.GitCodePAT }} - GITCODE_REPO: https://gitcode.com/maotoumao/MusicFreeDesktopRelease.git - GIT_USER_NAME: maotoumao - GIT_USER_EMAIL: lhx_xjtu@163.com - run: | - # Configure git - git config --global user.name "$GIT_USER_NAME" - git config --global user.email "$GIT_USER_EMAIL" - - # Clone the GitCode repository - echo "Cloning GitCode repository..." - git clone https://$GIT_USER_NAME:$GITCODE_PAT@gitcode.com/maotoumao/MusicFreeDesktopRelease.git gitcode-repo - cd gitcode-repo - - # Get current date for commit message - CURRENT_DATE=$(date '+%Y-%m-%d %H:%M:%S') - - # Process artifacts - cd ../downloads - - for zip_file in *.zip; do - if [ ! -f "$zip_file" ]; then - continue - fi - - echo "Processing: $zip_file" - - # Create a directory for this artifact - artifact_dir="${zip_file%.zip}" - mkdir -p "$artifact_dir" - - # Extract the artifact zip - unzip -q "$zip_file" -d "$artifact_dir" - - # Process files in the extracted directory - for file in "$artifact_dir"/*; do - if [ -f "$file" ]; then - filename=$(basename "$file") - echo "Processing file: $filename" - - # Check if filename contains "portable" - if [[ "$filename" == *"portable"* ]]; then - echo "File contains 'portable', uploading zip directly: $filename" - # Copy portable zip file directly to GitCode repo - cp "$file" "../gitcode-repo/$filename" - else - echo "File does not contain 'portable', checking if it's a zip/archive: $filename" - - # Check if it's a zip file and extract it - if [[ "$filename" == *.zip ]]; then - echo "Extracting and uploading contents of: $filename" - extract_dir="${filename%.zip}_extracted" - mkdir -p "$extract_dir" - unzip -q "$file" -d "$extract_dir" - - # Copy all extracted files to GitCode repo - for extracted_file in "$extract_dir"/*; do - if [ -f "$extracted_file" ]; then - extracted_filename=$(basename "$extracted_file") - echo "Copying extracted file: $extracted_filename" - cp "$extracted_file" "../gitcode-repo/$extracted_filename" - fi - done - - # Clean up extraction directory - rm -rf "$extract_dir" - else - echo "Copying file directly: $filename" - # Copy non-zip files directly to GitCode repo - cp "$file" "../gitcode-repo/$filename" - fi - fi - fi - done - - # Clean up artifact directory - rm -rf "$artifact_dir" - done - - # Commit and push to GitCode - cd ../gitcode-repo - - # Add all files - git add . - - # Check if there are any changes to commit - if git diff --staged --quiet; then - echo "No changes to commit" - else - echo "Committing and pushing changes to GitCode..." - git commit -m "Update release artifacts - $CURRENT_DATE" - git push --force origin master - echo "✅ Successfully pushed artifacts to GitCode" - fi - - - name: Cleanup - if: always() - run: | - rm -rf ./downloads - rm -rf ./gitcode-repo - - - name: Summary - run: | - if [ "${{ steps.download.outputs.has_artifacts }}" == "true" ]; then - echo "✅ Artifacts processed and pushed to GitCode successfully" - else - echo "ℹ️ No artifacts found for the specified run ID" - fi diff --git a/.github/workflows/artifact-upload.yml b/.github/workflows/artifact-upload.yml deleted file mode 100644 index 70c2b3f..0000000 --- a/.github/workflows/artifact-upload.yml +++ /dev/null @@ -1,143 +0,0 @@ -name: 发布到飞书 - -on: - workflow_dispatch: - inputs: - run_id: - description: 'GitHub Action Run ID to download artifacts from' - required: true - type: string - -jobs: - download-and-upload: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '18' - - - name: Install dependencies for upload script - run: | - npm install @larksuiteoapi/node-sdk - - - name: Download artifacts from specified run - id: download - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RUN_ID: ${{ github.event.inputs.run_id }} - run: | - echo "Checking artifacts for run ID: $RUN_ID" - - # Get artifacts list for the specified run - artifacts_response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ - "https://api.github.com/repos/${{ github.repository }}/actions/runs/$RUN_ID/artifacts") - - # Check if there are any artifacts - artifacts_count=$(echo "$artifacts_response" | jq '.total_count') - - if [ "$artifacts_count" -eq 0 ]; then - echo "No artifacts found for run ID: $RUN_ID" - echo "has_artifacts=false" >> $GITHUB_OUTPUT - exit 0 - fi - - echo "Found $artifacts_count artifact(s)" - echo "has_artifacts=true" >> $GITHUB_OUTPUT - - # Create downloads directory - mkdir -p ./downloads - - # Download all artifacts - echo "$artifacts_response" | jq -r '.artifacts[] | "\(.id) \(.name)"' | while read artifact_id artifact_name; do - echo "Downloading artifact: $artifact_name (ID: $artifact_id)" - - # Download artifact - curl -L -H "Authorization: token $GITHUB_TOKEN" \ - "https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact_id/zip" \ - -o "./downloads/${artifact_name}.zip" - - echo "Downloaded: ${artifact_name}.zip" - done - - - name: Process and upload artifacts - if: steps.download.outputs.has_artifacts == 'true' - env: - FEISHU_APP_ID: ${{ secrets.FEISHU_APP_ID }} - FEISHU_APP_SECRET: ${{ secrets.FEISHU_APP_SECRET }} - FEISHU_PARENT_NODE: E438flrKhlBJvfdmT57cMpOunlE - run: | - cd ./downloads - - for zip_file in *.zip; do - if [ ! -f "$zip_file" ]; then - continue - fi - - echo "Processing: $zip_file" - - # Create a directory for this artifact - artifact_dir="${zip_file%.zip}" - mkdir -p "$artifact_dir" - - # Extract the artifact zip - unzip -q "$zip_file" -d "$artifact_dir" - - # Process files in the extracted directory - for file in "$artifact_dir"/*; do - if [ -f "$file" ]; then - filename=$(basename "$file") - echo "Processing file: $filename" - - # Check if filename contains "portable" - if [[ "$filename" == *"portable"* ]]; then - echo "File contains 'portable', uploading directly: $filename" - # Upload file directly without extraction - node ../scripts/feishu-upload.js "$file" "$filename" - else - echo "File does not contain 'portable', checking if it's a zip/archive: $filename" - - # Check if it's a zip file and extract it - if [[ "$filename" == *.zip ]]; then - echo "Extracting and uploading contents of: $filename" - extract_dir="${filename%.zip}_extracted" - mkdir -p "$extract_dir" - unzip -q "$file" -d "$extract_dir" - - # Upload all extracted files - for extracted_file in "$extract_dir"/*; do - if [ -f "$extracted_file" ]; then - extracted_filename=$(basename "$extracted_file") - echo "Uploading extracted file: $extracted_filename" - node ../scripts/feishu-upload.js "$extracted_file" "$extracted_filename" - fi - done - else - echo "Uploading file directly: $filename" - # Upload non-zip files directly - node ../scripts/feishu-upload.js "$file" "$filename" - fi - fi - fi - done - - # Clean up extracted directory - rm -rf "$artifact_dir" - done - - - name: Cleanup - if: always() - run: | - rm -rf ./downloads - - - name: Summary - run: | - if [ "${{ steps.download.outputs.has_artifacts }}" == "true" ]; then - echo "✅ Artifacts processed and uploaded successfully" - else - echo "ℹ️ No artifacts found for the specified run ID" - fi diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 36c57c5..6369e82 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,136 +1,195 @@ -name: 打包 -on: - workflow_dispatch: +name: Build + +on: + workflow_dispatch: + jobs: - build-windows: - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 18 - - run: echo (node -p -e '`VERSION=${require("./package.json").version}`') >> $Env:GITHUB_ENV - - run: npm install - - run: npm run package - - uses: maotoumao/inno-setup-action-cli@main - with: - filepath: ./release/build-windows.iss - variables: /DMyAppVersion=${{ env.VERSION }} /DMyAppId=${{ secrets.MYAPPID }} - - name: Rename Setup File - run: Rename-Item -Path "./out/MusicFreeSetup.exe" -NewName "MusicFree-${{ env.VERSION }}-win32-x64-setup.exe" - - name: Upload Setup - uses: actions/upload-artifact@v4 - with: - name: MusicFree-${{ env.VERSION }}-win32-x64-setup - path: ./out/MusicFree-${{ env.VERSION }}-win32-x64-setup.exe - - name: Generate Portable - run: mkdir ./out/MusicFree-win32-x64/portable - - uses: vimtor/action-zip@v1.1 - with: - files: ./out/MusicFree-win32-x64 - dest: MusicFree-${{ env.VERSION }}-win32-x64-portable.zip - - name: Upload Portable - uses: actions/upload-artifact@v4 - with: - name: MusicFree-${{ env.VERSION }}-win32-x64-portable - path: ${{ github.workspace }}/MusicFree-${{ env.VERSION }}-win32-x64-portable.zip + build-meta: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Generate build metadata + run: | + VERSION=$(node -p "require('./package.json').version") + BRANCH=${GITHUB_REF_NAME} + COMMIT=${GITHUB_SHA} + echo "{\"branch\":\"${BRANCH}\",\"version\":\"${VERSION}\",\"commit\":\"${COMMIT}\"}" > build-meta.json + cat build-meta.json + - uses: actions/upload-artifact@v4 + with: + name: build-meta + path: build-meta.json + retention-days: 30 - build-windows-legacy: - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 18 - - run: echo (node -p -e '`VERSION=${require("./package.json").version}`') >> $Env:GITHUB_ENV - - run: npm install - - run: npm install electron@22 - - run: npm run package - - uses: maotoumao/inno-setup-action-cli@main - with: - filepath: ./release/build-windows.iss - variables: /DMyAppVersion=${{ env.VERSION }} /DMyAppId=${{ secrets.MYAPPID }} - - name: Rename Setup File - run: Rename-Item -Path "./out/MusicFreeSetup.exe" -NewName "MusicFree-${{ env.VERSION }}-win32-x64-legacy-setup.exe" - - name: Upload Setup - uses: actions/upload-artifact@v4 - with: - name: MusicFree-${{ env.VERSION }}-win32-x64-legacy-setup - path: ./out/MusicFree-${{ env.VERSION }}-win32-x64-legacy-setup.exe - - name: Generate Portable - run: mkdir ./out/MusicFree-win32-x64/portable - - uses: vimtor/action-zip@v1.1 - with: - files: ./out/MusicFree-win32-x64 - dest: MusicFree-${{ env.VERSION }}-win32-x64-legacy-portable.zip - - name: Upload Portable - uses: actions/upload-artifact@v4 - with: - name: MusicFree-${{ env.VERSION }}-win32-x64-legacy-portable - path: ${{ github.workspace }}/MusicFree-${{ env.VERSION }}-win32-x64-legacy-portable.zip + build-windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - run: pnpm install --frozen-lockfile + - name: Read version + run: | + $version = node -p "require('./package.json').version" + echo "VERSION=$version" >> $env:GITHUB_ENV + - run: pnpm run package + - uses: maotoumao/inno-setup-action-cli@main + with: + filepath: ./release/build-windows.iss + variables: /DMyAppVersion=${{ env.VERSION }} /DMyAppId=${{ secrets.MYAPPID }} + - name: Rename setup file + run: | + Rename-Item -Path "./out/MusicFreeSetup.exe" -NewName "MusicFree-${{ env.VERSION }}-win32-x64-setup.exe" + - name: Generate portable + run: | + New-Item -ItemType Directory -Path "./out/MusicFree-win32-x64/portable" -Force + - name: Archive portable + run: | + Compress-Archive -Path "./out/MusicFree-win32-x64/*" -DestinationPath "./out/MusicFree-${{ env.VERSION }}-win32-x64-portable.zip" + - uses: actions/upload-artifact@v4 + with: + name: MusicFree-${{ env.VERSION }}-win32-x64-setup + path: ./out/MusicFree-${{ env.VERSION }}-win32-x64-setup.exe + retention-days: 30 + - uses: actions/upload-artifact@v4 + with: + name: MusicFree-${{ env.VERSION }}-win32-x64-portable + path: ./out/MusicFree-${{ env.VERSION }}-win32-x64-portable.zip + retention-days: 30 - build-macos-x64: - runs-on: macos-13 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - uses: actions/setup-node@v4 - with: - node-version: 18 - - run: node -p -e '`VERSION=${require("./package.json").version}`' >> $GITHUB_ENV - - run: npm install - - run: npm run make - - run: ls ./out/make - - name: Rename DMG File - run: mv "./out/make/MusicFree-${{ env.VERSION }}-x64.dmg" "./out/make/MusicFree-${{ env.VERSION }}-darwin-x64.dmg" - - name: Upload Setup - uses: actions/upload-artifact@v4 - with: - name: MusicFree-${{ env.VERSION }}-darwin-x64 - path: ./out/make/MusicFree-${{ env.VERSION }}-darwin-x64.dmg + build-windows-legacy: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - run: pnpm install + - name: Read version + run: | + $version = node -p "require('./package.json').version" + echo "VERSION=$version" >> $env:GITHUB_ENV + - name: Override Win7 compatibility files + run: | + Get-ChildItem -Recurse -Filter "*.win7.ts" | ForEach-Object { + $target = $_.FullName -replace '\.win7\.ts$', '.ts' + Write-Host "Overriding: $target" + Copy-Item $_.FullName $target -Force + } + - name: Install Electron 22 + run: pnpm add electron@22 --save-dev + - run: pnpm run package + - uses: maotoumao/inno-setup-action-cli@main + with: + filepath: ./release/build-windows.iss + variables: /DMyAppVersion=${{ env.VERSION }} /DMyAppId=${{ secrets.MYAPPID }} + - name: Rename setup file + run: | + Rename-Item -Path "./out/MusicFreeSetup.exe" -NewName "MusicFree-${{ env.VERSION }}-win32-x64-legacy-setup.exe" + - name: Generate portable + run: | + New-Item -ItemType Directory -Path "./out/MusicFree-win32-x64/portable" -Force + - name: Archive portable + run: | + Compress-Archive -Path "./out/MusicFree-win32-x64/*" -DestinationPath "./out/MusicFree-${{ env.VERSION }}-win32-x64-legacy-portable.zip" + - uses: actions/upload-artifact@v4 + with: + name: MusicFree-${{ env.VERSION }}-win32-x64-legacy-setup + path: ./out/MusicFree-${{ env.VERSION }}-win32-x64-legacy-setup.exe + retention-days: 30 + - uses: actions/upload-artifact@v4 + with: + name: MusicFree-${{ env.VERSION }}-win32-x64-legacy-portable + path: ./out/MusicFree-${{ env.VERSION }}-win32-x64-legacy-portable.zip + retention-days: 30 - build-macos-arm64: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - uses: actions/setup-node@v4 - with: - node-version: 18 - - run: node -p -e '`VERSION=${require("./package.json").version}`' >> $GITHUB_ENV - - run: npm install - - run: npm run make -- --arch="arm64" - - name: Rename DMG File - run: mv "./out/make/MusicFree-${{ env.VERSION }}-arm64.dmg" "./out/make/MusicFree-${{ env.VERSION }}-darwin-arm64.dmg" - - name: Upload Setup - uses: actions/upload-artifact@v4 - with: - name: MusicFree-${{ env.VERSION }}-darwin-arm64 - path: ./out/make/MusicFree-${{ env.VERSION }}-darwin-arm64.dmg + build-macos-x64: + runs-on: macos-13 + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - run: pnpm install --frozen-lockfile + - name: Read version + run: | + VERSION=$(node -p "require('./package.json').version") + echo "VERSION=$VERSION" >> $GITHUB_ENV + - run: pnpm run make + - name: Rename DMG + run: mv "./out/make/MusicFree-${{ env.VERSION }}-x64.dmg" "./out/make/MusicFree-${{ env.VERSION }}-darwin-x64.dmg" + - uses: actions/upload-artifact@v4 + with: + name: MusicFree-${{ env.VERSION }}-darwin-x64 + path: ./out/make/MusicFree-${{ env.VERSION }}-darwin-x64.dmg + retention-days: 30 - build-ubuntu: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 18 - - run: node -p -e '`VERSION=${require("./package.json").version}`' >> $GITHUB_ENV - - run: npm install - - run: npm run make - - name: Find and Rename DEB File - run: | - DEB_FILE=$(find ./out/make/deb/x64/ -name "*.deb" | head -1) - if [ -n "$DEB_FILE" ]; then - mv "$DEB_FILE" "./out/make/deb/x64/MusicFree-${{ env.VERSION }}-linux-amd64.deb" - fi - - name: Upload Setup - uses: actions/upload-artifact@v4 - with: - name: MusicFree-${{ env.VERSION }}-linux-amd64 - path: ./out/make/deb/x64/MusicFree-${{ env.VERSION }}-linux-amd64.deb + build-macos-arm64: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - run: pnpm install --frozen-lockfile + - name: Read version + run: | + VERSION=$(node -p "require('./package.json').version") + echo "VERSION=$VERSION" >> $GITHUB_ENV + - run: pnpm run make -- --arch=arm64 + - name: Rename DMG + run: mv "./out/make/MusicFree-${{ env.VERSION }}-arm64.dmg" "./out/make/MusicFree-${{ env.VERSION }}-darwin-arm64.dmg" + - uses: actions/upload-artifact@v4 + with: + name: MusicFree-${{ env.VERSION }}-darwin-arm64 + path: ./out/make/MusicFree-${{ env.VERSION }}-darwin-arm64.dmg + retention-days: 30 + build-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install system dependencies + run: sudo apt-get update && sudo apt-get install -y rpm + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - run: pnpm install --frozen-lockfile + - name: Read version + run: | + VERSION=$(node -p "require('./package.json').version") + echo "VERSION=$VERSION" >> $GITHUB_ENV + - run: pnpm run make + - name: Rename DEB + run: | + DEB_FILE=$(find ./out/make/deb/x64/ -name "*.deb" | head -1) + if [ -n "$DEB_FILE" ]; then + mv "$DEB_FILE" "./out/make/deb/x64/MusicFree-${{ env.VERSION }}-linux-amd64.deb" + fi + - name: Rename RPM + run: | + RPM_FILE=$(find ./out/make/rpm/x64/ -name "*.rpm" | head -1) + if [ -n "$RPM_FILE" ]; then + mv "$RPM_FILE" "./out/make/rpm/x64/MusicFree-${{ env.VERSION }}-linux-amd64.rpm" + fi + - uses: actions/upload-artifact@v4 + with: + name: MusicFree-${{ env.VERSION }}-linux-amd64-deb + path: ./out/make/deb/x64/MusicFree-${{ env.VERSION }}-linux-amd64.deb + retention-days: 30 + - uses: actions/upload-artifact@v4 + with: + name: MusicFree-${{ env.VERSION }}-linux-amd64-rpm + path: ./out/make/rpm/x64/MusicFree-${{ env.VERSION }}-linux-amd64.rpm + retention-days: 30 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6df7a1d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,98 @@ +name: Release + +on: + workflow_dispatch: + inputs: + run_id: + description: 'Build workflow run ID to download artifacts from' + required: true + type: string + release_notes: + description: 'Release notes (optional, overrides release/version.json changeLog)' + required: false + type: string + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Download all artifacts from build run + env: + GH_TOKEN: ${{ github.token }} + run: | + mkdir -p artifacts + gh run download ${{ inputs.run_id }} --dir artifacts + + - name: Read build metadata + id: meta + run: | + META_FILE="artifacts/build-meta/build-meta.json" + if [ ! -f "$META_FILE" ]; then + echo "::error::build-meta.json not found. Make sure the build workflow completed successfully." + exit 1 + fi + VERSION=$(jq -r '.version' "$META_FILE") + BRANCH=$(jq -r '.branch' "$META_FILE") + COMMIT=$(jq -r '.commit' "$META_FILE") + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "branch=$BRANCH" >> $GITHUB_OUTPUT + echo "commit=$COMMIT" >> $GITHUB_OUTPUT + echo "tag=v$VERSION" >> $GITHUB_OUTPUT + # Auto-detect prerelease from branch name + if [[ "$BRANCH" == *"dev"* ]] || [[ "$BRANCH" == *"beta"* ]] || [[ "$BRANCH" == *"alpha"* ]]; then + echo "prerelease=true" >> $GITHUB_OUTPUT + else + echo "prerelease=false" >> $GITHUB_OUTPUT + fi + + - name: Generate release notes + id: notes + env: + RELEASE_NOTES_INPUT: ${{ inputs.release_notes }} + run: | + if [ -n "$RELEASE_NOTES_INPUT" ]; then + printf '%s\n' "$RELEASE_NOTES_INPUT" > release-notes.md + else + jq -r '.changeLog | join("\n")' release/version.json > release-notes.md + fi + echo "=== Release notes ===" + cat release-notes.md + + - name: Collect release assets + run: | + mkdir -p release-assets + find artifacts -type f \( -name "*.exe" -o -name "*.zip" -o -name "*.dmg" -o -name "*.deb" -o -name "*.rpm" \) -exec cp {} release-assets/ \; + echo "=== Release assets ===" + ls -lh release-assets/ + + - name: Create tag + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG="${{ steps.meta.outputs.tag }}" + COMMIT="${{ steps.meta.outputs.commit }}" + # Check if tag already exists + if gh api "repos/${{ github.repository }}/git/refs/tags/${TAG}" &>/dev/null; then + echo "::error::Tag ${TAG} already exists. Aborting." + exit 1 + fi + gh api "repos/${{ github.repository }}/git/refs" \ + -X POST \ + -f ref="refs/tags/${TAG}" \ + -f sha="${COMMIT}" + + - name: Create GitHub Draft Release + env: + GH_TOKEN: ${{ github.token }} + run: | + gh release create "${{ steps.meta.outputs.tag }}" \ + --title "MusicFree ${{ steps.meta.outputs.version }}" \ + --notes-file release-notes.md \ + --draft \ + ${{ steps.meta.outputs.prerelease == 'true' && '--prerelease' || '' }} \ + release-assets/*