From 60a4011539d463d5a6a6958ed6f99fb7f52317f4 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 28 Apr 2026 12:05:33 +0800 Subject: [PATCH] fix(release): upload assets after packaging --- .github/workflows/release.yml | 101 +++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fe14ef8..39f6ae8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,8 +13,42 @@ env: ELECTRON_BUILDER_BINARIES_MIRROR: https://github.com/electron-userland/electron-builder-binaries/releases/download/ jobs: + prepare-release: + runs-on: ubuntu-latest + + steps: + - name: Check out git repository + uses: actions/checkout@v5 + with: + fetch-depth: 1 + + - name: Ensure GitHub release exists + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + run: | + set -euo pipefail + source .github/scripts/release-utils.sh + + TAG="$GITHUB_REF_NAME" + REPO="$GITHUB_REPOSITORY" + VERSION="${TAG#v}" + prerelease_args=() + if [[ "$VERSION" == *-* ]]; then + prerelease_args+=(--prerelease) + fi + + if gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then + retry_cmd 5 3 gh release edit "$TAG" --repo "$REPO" --draft=false "${prerelease_args[@]}" + else + retry_cmd 5 3 gh release create "$TAG" --repo "$REPO" --title "$TAG" --notes "Release $TAG" --target "$GITHUB_SHA" "${prerelease_args[@]}" + fi + + wait_for_release_id "$REPO" "$TAG" 12 2 >/dev/null + release-mac-arm64: runs-on: macos-14 + needs: prepare-release steps: - name: Check out git repository @@ -43,19 +77,29 @@ jobs: npx tsc npx vite build - - name: Package and Publish macOS arm64 (unsigned DMG + ZIP) + - name: Package and Upload macOS arm64 (unsigned DMG + ZIP) env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} CSC_IDENTITY_AUTO_DISCOVERY: "false" shell: bash run: | set -euo pipefail + source .github/scripts/release-utils.sh export ELECTRON_BUILDER_BINARIES_MIRROR="https://github.com/electron-userland/electron-builder-binaries/releases/download/" echo "Using ELECTRON_BUILDER_BINARIES_MIRROR=$ELECTRON_BUILDER_BINARIES_MIRROR" - if ! npx electron-builder --mac dmg zip --arm64 --publish always '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}'; then + if ! npx electron-builder --mac dmg zip --arm64 --publish never '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}'; then echo "::warning::DMG packaging failed (hdiutil instability on runner). Retrying with ZIP only." - npx electron-builder --mac zip --arm64 --publish always '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}' + npx electron-builder --mac zip --arm64 --publish never '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}' fi + assets=() + while IFS= read -r file; do + assets+=("$file") + done < <(find release -maxdepth 1 -type f | sort) + if [ "${#assets[@]}" -eq 0 ]; then + echo "No release files found in ./release" + exit 1 + fi + upload_release_assets_with_retry "$GITHUB_REPOSITORY" "$GITHUB_REF_NAME" "${assets[@]}" - name: Inject minimumVersion into latest yml env: @@ -81,6 +125,7 @@ jobs: release-linux: runs-on: ubuntu-latest + needs: prepare-release steps: - name: Check out git repository @@ -114,11 +159,23 @@ jobs: npx tsc npx vite build - - name: Package and Publish Linux + - name: Package and Upload Linux env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash run: | - npx electron-builder --linux --publish always '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}' + set -euo pipefail + source .github/scripts/release-utils.sh + npx electron-builder --linux --publish never '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}' + assets=() + while IFS= read -r file; do + assets+=("$file") + done < <(find release -maxdepth 1 -type f | sort) + if [ "${#assets[@]}" -eq 0 ]; then + echo "No release files found in ./release" + exit 1 + fi + upload_release_assets_with_retry "$GITHUB_REPOSITORY" "$GITHUB_REF_NAME" "${assets[@]}" - name: Inject minimumVersion into latest yml env: @@ -139,6 +196,7 @@ jobs: release: runs-on: windows-latest + needs: prepare-release steps: - name: Check out git repository @@ -167,11 +225,23 @@ jobs: npx tsc npx vite build - - name: Package and Publish + - name: Package and Upload Windows x64 env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash run: | - npx electron-builder --win nsis --x64 --publish always '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}' '--config.artifactName=${productName}-${version}-x64-Setup.${ext}' + set -euo pipefail + source .github/scripts/release-utils.sh + npx electron-builder --win nsis --x64 --publish never '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}' '--config.artifactName=${productName}-${version}-x64-Setup.${ext}' + assets=() + while IFS= read -r file; do + assets+=("$file") + done < <(find release -maxdepth 1 -type f | sort) + if [ "${#assets[@]}" -eq 0 ]; then + echo "No release files found in ./release" + exit 1 + fi + upload_release_assets_with_retry "$GITHUB_REPOSITORY" "$GITHUB_REF_NAME" "${assets[@]}" - name: Inject minimumVersion into latest yml env: @@ -192,6 +262,7 @@ jobs: release-windows-arm64: runs-on: windows-latest + needs: prepare-release steps: - name: Check out git repository @@ -220,11 +291,23 @@ jobs: npx tsc npx vite build - - name: Package and Publish Windows arm64 + - name: Package and Upload Windows arm64 env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash run: | - npx electron-builder --win nsis --arm64 --publish always '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}' '--config.publish.channel=latest-arm64' '--config.artifactName=${productName}-${version}-arm64-Setup.${ext}' + set -euo pipefail + source .github/scripts/release-utils.sh + npx electron-builder --win nsis --arm64 --publish never '--config.publish.owner=${{ github.repository_owner }}' '--config.publish.repo=${{ github.event.repository.name }}' '--config.publish.channel=latest-arm64' '--config.artifactName=${productName}-${version}-arm64-Setup.${ext}' + assets=() + while IFS= read -r file; do + assets+=("$file") + done < <(find release -maxdepth 1 -type f | sort) + if [ "${#assets[@]}" -eq 0 ]; then + echo "No release files found in ./release" + exit 1 + fi + upload_release_assets_with_retry "$GITHUB_REPOSITORY" "$GITHUB_REF_NAME" "${assets[@]}" - name: Inject minimumVersion into latest yml env: