From 105c3aae5b4350f0576277128c8500ea4ed889b7 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 24 Apr 2026 09:11:29 +0800 Subject: [PATCH] fix(workflows): streamline release process for Linux and macOS - Removed the workflow_dispatch trigger from both release workflows to enforce tag-based releases. - Added a mechanism to wait for draft releases before uploading assets, ensuring all necessary files are present. - Implemented asset upload to GitHub releases and conditional publishing based on asset completeness. - Enhanced SHA256 checksum generation for both production and development binaries. --- .github/workflows/create-release.yml | 25 ++++++++++++++ .github/workflows/release-linux.yml | 50 +++++++++++++++++++++++----- .github/workflows/release-macos.yml | 44 +++++++++++++++++++----- 3 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/create-release.yml diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 00000000..2d772141 --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,25 @@ +name: Create Release + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + create: + runs-on: ubuntu-latest + steps: + - name: Create Draft Release + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG="${GITHUB_REF#refs/tags/}" + VERSION="${TAG#v}" + gh release create "$TAG" \ + --repo "$GITHUB_REPOSITORY" \ + --title "Yao v${VERSION}" \ + --generate-notes \ + --draft diff --git a/.github/workflows/release-linux.yml b/.github/workflows/release-linux.yml index 6c868e7f..0bfa35f4 100644 --- a/.github/workflows/release-linux.yml +++ b/.github/workflows/release-linux.yml @@ -1,7 +1,6 @@ name: Release Linux on: - workflow_dispatch: push: tags: - "v*" @@ -174,16 +173,49 @@ jobs: cp "artifacts/yao-${VERSION}-linux-amd64" "release/yao-${VERSION}-linux-amd64-dev" cp "artifacts/yao-${VERSION}-linux-arm64" "release/yao-${VERSION}-linux-arm64-dev" chmod +x release/yao-* + + for ARCH in amd64 arm64; do + sha256sum "release/yao-${VERSION}-linux-${ARCH}" | awk '{print $1}' > "release/yao-linux-${ARCH}-prod.sha256" + sha256sum "release/yao-${VERSION}-linux-${ARCH}-dev" | awk '{print $1}' > "release/yao-linux-${ARCH}-dev.sha256" + done ls -lh release/ - - name: Create GitHub Release - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ steps.version.outputs.tag }} - name: Yao v${{ steps.version.outputs.version }} - files: release/* - generate_release_notes: true - make_latest: false + - name: Wait for Draft Release + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG="${{ steps.version.outputs.tag }}" + for i in $(seq 1 30); do + if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" &>/dev/null; then + echo "Draft release found for $TAG." + exit 0 + fi + echo "Waiting for draft release... ($i/30)" + sleep 10 + done + echo "::error::Timed out waiting for draft release $TAG" + exit 1 + + - name: Upload Assets to GitHub Release + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG="${{ steps.version.outputs.tag }}" + gh release upload "$TAG" release/* --repo "$GITHUB_REPOSITORY" --clobber + + - name: Publish Release if Complete + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG="${{ steps.version.outputs.tag }}" + ASSET_COUNT=$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets | length') + echo "Current assets: $ASSET_COUNT / 16" + if [ "$ASSET_COUNT" -ge 16 ]; then + echo "All assets present, publishing release..." + gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --draft=false --latest + else + echo "Assets incomplete ($ASSET_COUNT/16), waiting for other workflow to publish." + fi - name: Upload Linux binaries to R2 env: diff --git a/.github/workflows/release-macos.yml b/.github/workflows/release-macos.yml index c7843705..566e2578 100644 --- a/.github/workflows/release-macos.yml +++ b/.github/workflows/release-macos.yml @@ -1,7 +1,6 @@ name: Release macOS on: - workflow_dispatch: push: tags: - "v*" @@ -280,13 +279,42 @@ jobs: chmod +x release/yao-* ls -lh release/ - - name: Create GitHub Release - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ steps.version.outputs.tag }} - name: Yao v${{ steps.version.outputs.version }} - files: release/* - generate_release_notes: true + - name: Wait for Draft Release + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG="${{ steps.version.outputs.tag }}" + for i in $(seq 1 30); do + if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" &>/dev/null; then + echo "Draft release found for $TAG." + exit 0 + fi + echo "Waiting for draft release... ($i/30)" + sleep 10 + done + echo "::error::Timed out waiting for draft release $TAG" + exit 1 + + - name: Upload Assets to GitHub Release + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG="${{ steps.version.outputs.tag }}" + gh release upload "$TAG" release/* --repo "$GITHUB_REPOSITORY" --clobber + + - name: Publish Release if Complete + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG="${{ steps.version.outputs.tag }}" + ASSET_COUNT=$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets | length') + echo "Current assets: $ASSET_COUNT / 16" + if [ "$ASSET_COUNT" -ge 16 ]; then + echo "All assets present, publishing release..." + gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --draft=false --latest + else + echo "Assets incomplete ($ASSET_COUNT/16), waiting for other workflow to publish." + fi - name: Upload macOS binaries to R2 env: