Files
gitea bfbf6cf55f chore: 加固 Gitea Release 上传,避免维护期丢资产
0.9.5 的 Release workflow 因 Gitea 服务端维护期不稳,5 个资产
上传 3 次重试全部失败,Gitea 侧只落地 7/12(已手动补齐)。
根因不是代码缺陷,但二进制变大后并发大文件上传放大了影响。

- job timeout-minutes: 30 → 60,给重试留足窗口。
- 单资产重试次数 3 → 5,间隔保持 3 秒。
- 上传从「2 并发 + wait」改为串行,维护期不再互相抢带宽;
  幂等逻辑不变(已存在资产校验 SHA-256 后跳过,字节不同才删除重传)。
- 同步 release-validation.test.ts:断言改 attempt 2/5,
  并发用例改为验证严格单 worker(peak === 1),
  失败用例的 spawnSync 超时放宽到 40s。

校验:YAML parse 通过;bun test 1114 pass / 0 fail;
bun run check、check:readme 37/37 全通过。
本次只改 CI,不打 tag、不发版。
2026-11-06 10:39:49 +08:00

230 lines
9.9 KiB
YAML

name: 🚀 Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: Release tag already merged into main (e.g. v0.8.14)
required: true
type: string
mirror_only:
description: Reuse the existing GitHub assets and repair only the Gitea mirror
required: false
default: false
type: boolean
concurrency:
group: release-${{ inputs.tag || github.ref_name }}
cancel-in-progress: false
permissions:
contents: read
jobs:
build-and-publish:
name: 🚀 Build & Publish Multi-Platform Binaries
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: write
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
MIRROR_ONLY: ${{ inputs.mirror_only || false }}
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ inputs.tag || github.ref }}
fetch-depth: 0
- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.3.14
# A tag alone does not prove review. Also verify the commit actually being
# compiled, so manual dispatch cannot validate one tag and ship another ref.
- name: Verify release commit and version
run: |
git fetch --no-tags origin main:refs/remotes/origin/main
bun run scripts/release/verify-release.ts "$RELEASE_TAG"
- name: Install dependencies
if: ${{ !inputs.mirror_only }}
run: bun install --frozen-lockfile
- name: Check committed version consistency
if: ${{ !inputs.mirror_only }}
run: bun run check:version
- name: Generate & bundle OpenAPI
if: ${{ !inputs.mirror_only }}
run: bun run openapi:all
- name: Type-check
if: ${{ !inputs.mirror_only }}
run: bun run check
- name: Test
if: ${{ !inputs.mirror_only }}
run: bun test
- name: Compile multi-target binaries
if: ${{ !inputs.mirror_only }}
run: |
mkdir -p dist/bin
node scripts/build/build-binary.mjs --all --release
- name: Verify packaged MCP entrypoint
if: ${{ !inputs.mirror_only }}
run: bun run scripts/build/verify-binary.ts dist/bin/hose-use-linux-x64
- name: Verify plugin bundle runtime
if: ${{ !inputs.mirror_only }}
run: |
bun run build:plugin
bun run scripts/build/verify-binary.ts dist/mcp/server.js --plugin
- name: Package plugin archive
if: ${{ !inputs.mirror_only }}
run: bun run package:plugin
- name: Package release archives
if: ${{ !inputs.mirror_only }}
run: |
sudo apt-get update && sudo apt-get install -y zip
package_unix() {
local binary="$1"
local archive="$2"
local stage
stage=$(mktemp -d)
cp "dist/bin/${binary}" "${stage}/${binary}"
ln -s "${binary}" "${stage}/hose-aipro"
tar -czf "dist/bin/${archive}" -C "${stage}" "${binary}" hose-aipro
rm -rf "${stage}"
}
package_unix hose-use-linux-x64 hose-use-linux-x64.tar.gz
package_unix hose-use-linux-arm64 hose-use-linux-arm64.tar.gz
package_unix hose-use-darwin-x64 hose-use-darwin-x64.tar.gz
package_unix hose-use-darwin-arm64 hose-use-darwin-arm64.tar.gz
stage=$(mktemp -d)
cp dist/bin/hose-use-windows-x64.exe "${stage}/hose-use-windows-x64.exe"
printf '@echo off\r\n"%%~dp0hose-use-windows-x64.exe" %%*\r\n' > "${stage}/hose-aipro.cmd"
(cd "${stage}" && zip -q "${GITHUB_WORKSPACE}/dist/bin/hose-use-windows-x64.zip" hose-use-windows-x64.exe hose-aipro.cmd)
rm -rf "${stage}"
# Includes the plugin archive alongside platform binaries and archives.
(cd dist/bin && sha256sum hose-use-* > checksums.txt)
- name: Publish GitHub Release
if: ${{ !inputs.mirror_only }}
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG_MSG=$(git tag -l --format='%(contents)' "${RELEASE_TAG}" | sed '/^$/d')
if [ -n "$TAG_MSG" ]; then
gh release view "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" --title "${RELEASE_TAG}" --notes "$TAG_MSG" --generate-notes
else
gh release view "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1 || gh release create "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" --title "${RELEASE_TAG}" --generate-notes
fi
gh release upload "${RELEASE_TAG}" dist/bin/hose-use-* dist/bin/checksums.txt --repo "${GITHUB_REPOSITORY}" --clobber
- name: Publish Gitea Release
env:
GH_TOKEN: ${{ github.token }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_HOST: "https://git.ying-qing.cn"
GITEA_REPO: "gitea/hose-use"
run: |
set -euo pipefail
if [ -z "$GITEA_TOKEN" ]; then
if [ "${MIRROR_ONLY:-false}" = "true" ]; then
echo "::error::GITEA_TOKEN is required to repair the mirror."
exit 1
fi
echo "::notice::GITEA_TOKEN secret not configured, skipping Gitea upload."
exit 0
fi
TAG_NAME="${RELEASE_TAG}"
if [ "${MIRROR_ONLY:-false}" = "true" ]; then
# Preserve the published bytes and checksums; never rebuild or replace GitHub assets.
# hose-use-* also includes the plugin archive, covered by checksums.txt.
mkdir -p dist/bin
gh release download "$TAG_NAME" --repo "$GITHUB_REPOSITORY" --dir dist/bin --pattern 'hose-use-*' --pattern checksums.txt
(cd dist/bin && sha256sum --strict -c checksums.txt)
fi
TAG_MSG=$(git tag -l --format='%(contents)' "${TAG_NAME}" | sed '/^$/d')
NOTES="${TAG_MSG:-Automated release for ${TAG_NAME}}"
echo "==> Creating release on Gitea for ${TAG_NAME}..."
RELEASE_RESP=$(curl -sS --connect-timeout 15 --max-time 60 -X POST "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG_NAME}\",\"name\":\"${TAG_NAME}\",\"body\":$(echo "$NOTES" | jq -Rsa .),\"draft\":false,\"prerelease\":false}")
RELEASE_ID=$(echo "$RELEASE_RESP" | jq -r '.id // empty')
if [ -z "$RELEASE_ID" ]; then
RELEASE_ID=$(curl -fsS --connect-timeout 15 --max-time 60 -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/tags/${TAG_NAME}" | jq -r '.id // empty')
fi
if [ -z "$RELEASE_ID" ]; then
echo "::error::Failed to create or find Gitea release ID. Response: $RELEASE_RESP"
exit 1
fi
echo "==> Uploading assets to Gitea release ID ${RELEASE_ID}..."
upload_asset() {
local file="$1" filename expected_hash attempt info existing remote_hash asset_id response delete_failed
filename=$(basename "$file")
expected_hash=$(sha256sum "$file" | awk '{ print $1 }')
for attempt in 1 2 3 4 5; do
if [ "$attempt" -gt 1 ]; then sleep "${GITEA_RETRY_DELAY:-3}"; fi
echo " [start] Uploading ${filename} to Gitea (attempt ${attempt}/5)..."
if ! info=$(curl -fsS --connect-timeout 15 --max-time 60 -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}"); then
continue
fi
existing=$(printf '%s' "$info" | jq -r --arg name "$filename" '.assets[]? | select(.name == $name) | .id')
if [ -n "$existing" ]; then
if ! remote_hash=$(curl -fLsS --connect-timeout 15 --max-time 600 -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/${GITEA_REPO}/releases/download/${TAG_NAME}/${filename}" | sha256sum | awk '{ print $1 }'); then
continue
fi
if [ "$remote_hash" = "$expected_hash" ]; then
echo " [skip] ${filename} already matches SHA-256"
return 0
fi
# Match GitHub --clobber only when the existing bytes differ.
delete_failed=0
for asset_id in $existing; do
curl -fsS --connect-timeout 15 --max-time 60 -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}/assets/${asset_id}" || delete_failed=1
done
if [ "$delete_failed" -ne 0 ]; then continue; fi
fi
if response=$(curl -fsS --connect-timeout 15 --max-time 600 -w "\nHTTP_STATUS:%{http_code}" -X POST "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}/assets?name=${filename}" \
-H "Authorization: token ${GITEA_TOKEN}" \
-F "attachment=@${file}"); then
echo " [done] ${filename} -> $(printf '%s' "$response" | tail -n 1)"
return 0
fi
done
echo "::error::Failed to upload ${filename} after 5 attempts."
return 1
}
# 串行上传:Gitea 维护期并发推大文件容易把重试窗口耗光,宁可慢也不要丢资产。
# 配合 job 超时 60 分钟与单资产 5 次重试,给服务端抖动留出余量。
failed=0
for file in dist/bin/hose-use-* dist/bin/checksums.txt; do
upload_asset "$file" || failed=1
done
if [ "$failed" -ne 0 ]; then
echo "::error::One or more Gitea assets failed to upload."
exit 1
fi
echo "✓ Successfully published release assets to Gitea!"