From d2fcd2b9830aeb278ebe104cbd0b0ecb06256635 Mon Sep 17 00:00:00 2001 From: Mucheen <1528136628@qq.com> Date: Fri, 20 Nov 2026 21:02:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(release):=20=E5=8C=BA=E5=88=86=E8=8D=89?= =?UTF-8?q?=E7=A8=BF=E5=92=8C=E5=B7=B2=E5=8F=91=E5=B8=83=E7=9A=84=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 13f264f..74f540a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,6 +13,9 @@ jobs: check: runs-on: ubuntu-latest timeout-minutes: 5 + permissions: + # GitHub only exposes draft releases to callers with push access. + contents: write outputs: exists: ${{ steps.release.outputs.exists }} steps: @@ -21,11 +24,32 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then - echo "exists=true" >> "$GITHUB_OUTPUT" - else - echo "exists=false" >> "$GITHUB_OUTPUT" - fi + state=$(gh api graphql \ + -f query='query($owner: String!, $repo: String!, $tag: String!) { + repository(owner: $owner, name: $repo) { + release(tagName: $tag) { isDraft } + } + }' \ + -f owner="$GITHUB_REPOSITORY_OWNER" -f repo="${GITHUB_REPOSITORY#*/}" -f tag="$GITHUB_REF_NAME" \ + --jq '.data.repository | + if . == null then "unavailable" + elif .release == null then "missing" + elif .release.isDraft == true then "draft" + elif .release.isDraft == false then "published" + else "unavailable" + end') + case "$state" in + missing) echo "exists=false" >> "$GITHUB_OUTPUT" ;; + published) echo "exists=true" >> "$GITHUB_OUTPUT" ;; + draft) + echo "::error::A draft release exists for $GITHUB_REF_NAME. Review it and resolve the draft before rerunning." + exit 1 + ;; + *) + echo "::error::Could not determine the release state for $GITHUB_REF_NAME." + exit 1 + ;; + esac package: needs: check @@ -82,4 +106,4 @@ jobs: (cd dist && sha256sum ./*.zip) echo '```' } > "$RUNNER_TEMP/notes.md" - gh release create "$GITHUB_REF_NAME" dist/*.zip --title "Python Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}" + gh release create "$GITHUB_REF_NAME" dist/*.zip --verify-tag --title "Python Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}"