diff --git a/.gitea/workflows/secrets.yml b/.gitea/workflows/secrets.yml index 1d79698..5317edf 100644 --- a/.gitea/workflows/secrets.yml +++ b/.gitea/workflows/secrets.yml @@ -128,71 +128,6 @@ jobs: echo "release_id=" >> "$GITHUB_OUTPUT" fi - probe-runners: - name: 探测 Runner - runs-on: debian - outputs: - has_linux: ${{ steps.probe.outputs.has_linux }} - has_macos: ${{ steps.probe.outputs.has_macos }} - has_windows: ${{ steps.probe.outputs.has_windows }} - steps: - - name: 查询可用 Runner - id: probe - env: - RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }} - run: | - fallback_all() { - echo "has_linux=true" >> "$GITHUB_OUTPUT" - echo "has_macos=true" >> "$GITHUB_OUTPUT" - echo "has_windows=true" >> "$GITHUB_OUTPUT" - } - - if [ -z "$RELEASE_TOKEN" ]; then - echo "未配置 RELEASE_TOKEN,默认尝试所有平台" - fallback_all; exit 0 - fi - - command -v jq >/dev/null 2>&1 || (sudo apt-get update -qq && sudo apt-get install -y -qq jq) - - http_code=$(curl -sS -o /tmp/runners.json -w '%{http_code}' \ - -H "Authorization: token $RELEASE_TOKEN" \ - "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/runners") - - if [ "$http_code" != "200" ]; then - echo "Runner API 返回 HTTP ${http_code},默认尝试所有平台" - fallback_all; exit 0 - fi - - has_runner() { - local label="$1" - jq -e --arg label "$label" ' - (.runners // .data // . // []) - | any( - ( - (.online == true) - or ( - ((.status // "") | ascii_downcase) - | IN("online", "idle", "busy", "active") - ) - ) - and ( - (.labels // []) - | map(if type == "object" then (.name // .label // "") else tostring end | ascii_downcase) - | index($label) - ) != null - ) - ' /tmp/runners.json >/dev/null - } - - for pair in "debian:has_linux" "darwin-arm64:has_macos" "windows:has_windows"; do - label="$(printf '%s' "${pair%%:*}" | tr '[:upper:]' '[:lower:]')"; key="${pair##*:}" - if has_runner "$label"; then - echo "${key}=true" >> "$GITHUB_OUTPUT" - else - echo "${key}=false" >> "$GITHUB_OUTPUT" - fi - done - check: name: 质量检查 (fmt / clippy / test) runs-on: debian @@ -227,10 +162,9 @@ jobs: build-linux: name: Build (x86_64-unknown-linux-musl) - needs: [version, probe-runners, check] - if: always() && needs.check.result == 'success' && needs.probe-runners.outputs.has_linux == 'true' + needs: [version, check] runs-on: debian - timeout-minutes: 1 + timeout-minutes: 10 steps: - name: 安装依赖 run: | @@ -276,10 +210,10 @@ jobs: build-macos: name: Build (aarch64-apple-darwin) - needs: [version, probe-runners, check] - if: always() && needs.check.result == 'success' && needs.probe-runners.outputs.has_macos == 'true' + needs: [version, check] + if: vars.BUILD_MACOS != 'false' runs-on: darwin-arm64 - timeout-minutes: 1 + timeout-minutes: 10 steps: - name: 安装依赖 run: | @@ -323,10 +257,10 @@ jobs: build-windows: name: Build (x86_64-pc-windows-msvc) - needs: [version, probe-runners, check] - if: always() && needs.check.result == 'success' && needs.probe-runners.outputs.has_windows == 'true' + needs: [version, check] + if: vars.BUILD_WINDOWS == 'true' runs-on: windows - timeout-minutes: 1 + timeout-minutes: 10 steps: - name: 安装依赖 shell: pwsh @@ -374,8 +308,8 @@ jobs: publish-release: name: 发布草稿 Release - needs: [version, check, build-linux, build-macos, build-windows] - if: always() && needs.version.outputs.release_id != '' + needs: [version, build-linux] + if: needs.version.outputs.release_id != '' runs-on: debian timeout-minutes: 2 steps: @@ -385,21 +319,11 @@ jobs: run: | [ -z "$RELEASE_TOKEN" ] && exit 0 - 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 }}" - - for result in "$version_r" "$check_r" "$linux_r" "$macos_r" "$windows_r"; do - case "$result" in - success|skipped) ;; - *) - echo "存在失败或取消的 job,保留草稿 Release" - exit 0 - ;; - esac - done + if [ "$linux_r" != "success" ]; then + echo "Linux 构建未成功 (${linux_r}),保留草稿 Release" + exit 0 + fi release_api="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/${{ needs.version.outputs.release_id }}" http_code=$(curl -sS -o /tmp/publish-release.json -w '%{http_code}' \ @@ -416,7 +340,7 @@ jobs: notify: name: 通知 - needs: [version, probe-runners, check, build-linux, build-macos, build-windows, publish-release] + needs: [version, check] if: always() && github.event_name == 'push' runs-on: debian timeout-minutes: 1 @@ -427,6 +351,7 @@ jobs: - name: 发送飞书通知 env: WEBHOOK_URL: ${{ vars.WEBHOOK_URL }} + RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }} run: | [ -z "$WEBHOOK_URL" ] && exit 0 command -v jq >/dev/null 2>&1 || (sudo apt-get update -qq && sudo apt-get install -y -qq jq) @@ -438,25 +363,40 @@ jobs: 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 }}" - publish_r="${{ needs.publish-release.result }}" - if [ "$version_r" = "success" ] && [ "$check_r" = "success" ] \ - && [ "$linux_r" != "failure" ] && [ "$linux_r" != "cancelled" ] \ - && [ "$macos_r" != "failure" ] && [ "$macos_r" != "cancelled" ] \ - && [ "$windows_r" != "failure" ] && [ "$windows_r" != "cancelled" ] \ - && [ "$publish_r" != "failure" ] && [ "$publish_r" != "cancelled" ]; then - status="构建成功 ✅" + # 通过 API 查询当前 run 的构建 job 状态(best-effort) + linux_r="unknown"; macos_r="unknown"; windows_r="unknown"; publish_r="unknown" + if [ -n "$RELEASE_TOKEN" ]; then + sleep 3 + run_api="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/actions/tasks" + http_code=$(curl -sS -o /tmp/jobs.json -w '%{http_code}' \ + -H "Authorization: token $RELEASE_TOKEN" "$run_api" 2>/dev/null) || true + if [ "$http_code" = "200" ] && [ -f /tmp/jobs.json ]; then + get_status() { + jq -r --arg name "$1" ' + (.workflow_runs // .task_runs // . // [])[]? + | select(.name == $name) + | .status // "unknown" + ' /tmp/jobs.json 2>/dev/null | head -1 + } + s=$(get_status "Build (x86_64-unknown-linux-musl)"); [ -n "$s" ] && linux_r="$s" + s=$(get_status "Build (aarch64-apple-darwin)"); [ -n "$s" ] && macos_r="$s" + s=$(get_status "Build (x86_64-pc-windows-msvc)"); [ -n "$s" ] && windows_r="$s" + s=$(get_status "发布草稿 Release"); [ -n "$s" ] && publish_r="$s" + fi + fi + + if [ "$version_r" = "success" ] && [ "$check_r" = "success" ]; then + status="检查通过 ✅" else - status="构建失败 ❌" + status="检查失败 ❌" fi icon() { case "$1" in success) echo "✅" ;; skipped) echo "⏭" ;; + unknown) echo "⏳" ;; *) echo "❌" ;; esac } @@ -471,6 +411,7 @@ jobs: fi msg="${msg} + 质量检查:$(icon "$check_r") 构建结果:linux$(icon "$linux_r") macOS$(icon "$macos_r") windows$(icon "$windows_r") Release:$(icon "$publish_r") 提交:${commit}