From 2ad1abe8465ea064d52d6f69465db9a5a6618f33 Mon Sep 17 00:00:00 2001 From: voson Date: Wed, 18 Mar 2026 15:04:07 +0800 Subject: [PATCH] ci: fix release 401 handling and notify based on actual results - Replace curl -fsS with HTTP status code checking to avoid hard failures on 401/404 - Release creation failure no longer blocks the entire workflow, just skips asset upload - Notification now depends on all jobs and reports actual success/failure per platform Made-with: Cursor --- .gitea/workflows/secrets.yml | 80 +++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/.gitea/workflows/secrets.yml b/.gitea/workflows/secrets.yml index 5d19e1f..d078957 100644 --- a/.gitea/workflows/secrets.yml +++ b/.gitea/workflows/secrets.yml @@ -79,13 +79,18 @@ jobs: tag="${{ steps.ver.outputs.tag }}" version="${{ steps.ver.outputs.version }}" release_api="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases" - existing_release=$(curl -fsS -H "Authorization: token $RELEASE_TOKEN" \ - "${release_api}/tags/${tag}" || true) - release_id=$(printf '%s' "$existing_release" | jq -r '.id // empty') - if [ -n "$release_id" ]; then - echo "release_id=${release_id}" >> "$GITHUB_OUTPUT" - exit 0 + http_code=$(curl -sS -o /tmp/release.json -w '%{http_code}' \ + -H "Authorization: token $RELEASE_TOKEN" \ + "${release_api}/tags/${tag}") + + if [ "$http_code" = "200" ]; then + release_id=$(jq -r '.id // empty' /tmp/release.json) + if [ -n "$release_id" ]; then + echo "已找到现有 Release: ${release_id}" + echo "release_id=${release_id}" >> "$GITHUB_OUTPUT" + exit 0 + fi fi previous_tag="${{ steps.ver.outputs.previous_tag }}" @@ -94,34 +99,34 @@ jobs: else changes=$(git log --pretty=format:'- %s (%h)') fi - if [ -z "$changes" ]; then - changes="- 首次发布" - fi + [ -z "$changes" ] && changes="- 首次发布" - cat > release-body.md <> "$GITHUB_OUTPUT" + if [ -n "$release_id" ]; then + echo "已创建 Release: ${release_id}" + echo "release_id=${release_id}" >> "$GITHUB_OUTPUT" + else + echo "⚠ 创建 Release 失败 (HTTP ${http_code}),跳过产物上传" + cat /tmp/create-release.json 2>/dev/null || true + echo "release_id=" >> "$GITHUB_OUTPUT" + fi probe-runners: name: 探测 Runner @@ -375,7 +380,7 @@ jobs: notify: name: 通知 - needs: [version, probe-runners] + needs: [version, probe-runners, check, build-linux, build-macos, build-windows] if: always() && github.event_name == 'push' runs-on: debian timeout-minutes: 1 @@ -395,21 +400,40 @@ jobs: commit=$(git log -1 --pretty=format:"%s" 2>/dev/null || echo "N/A") url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_number }}" - msg="${{ env.BINARY_NAME }} 通知" + version_r="${{ needs.version.result }}" + check_r="${{ needs.check.result }}" + linux_r="${{ needs.build-linux.result }}" + macos_r="${{ needs.build-macos.result }}" + windows_r="${{ needs.build-windows.result }}" + + if [ "$version_r" = "success" ] && [ "$check_r" = "success" ]; then + status="构建成功 ✅" + else + status="构建失败 ❌" + fi + + icon() { + case "$1" in + success) echo "✅" ;; + skipped) echo "⏭" ;; + *) echo "❌" ;; + esac + } + + msg="${{ env.BINARY_NAME }} ${status}" if [ "$tag_exists" = "false" ]; then msg="${msg} - 🆕 已创建版本标签并开始构建发布" + 🆕 新版本 ${tag}" else msg="${msg} - 🔄 检测到已有版本标签,已开始重复构建" + 🔄 重复构建 ${tag}" fi msg="${msg} - Runner 可用性:linux=${{ needs.probe-runners.outputs.has_linux }}, macOS=${{ needs.probe-runners.outputs.has_macos }}, windows=${{ needs.probe-runners.outputs.has_windows }} + 构建结果:linux$(icon "$linux_r") macOS$(icon "$macos_r") windows$(icon "$windows_r") 提交:${commit} - 版本:${tag} 作者:${{ github.actor }} 详情:${url}" payload=$(jq -n --arg text "$msg" '{msg_type: "text", content: {text: $text}}') - curl -fsS -H "Content-Type: application/json" -X POST -d "$payload" "$WEBHOOK_URL" + curl -sS -H "Content-Type: application/json" -X POST -d "$payload" "$WEBHOOK_URL"