ci: 允许对同版本覆盖重发版
- 解析版本时不再 exit 1,改为记录 tag_exists=true 并打印警告 - 创建 Tag 步骤:若 tag 已存在则先本地删除再远端删除,再重新打带注释的 tag - 创建 Release 步骤:先查询同名 Release,若存在则 DELETE 旧 Release,再 POST 新建 Made-with: Cursor
This commit is contained in:
@@ -39,7 +39,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
# ── 版本检查(提前拦截,避免后续步骤白跑)──────────────────────────
|
||||
# ── 版本解析 ────────────────────────────────────────────────────────
|
||||
- name: 解析版本
|
||||
id: ver
|
||||
run: |
|
||||
@@ -49,11 +49,12 @@ jobs:
|
||||
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
if git rev-parse "refs/tags/${tag}" >/dev/null 2>&1; then
|
||||
echo "错误: 版本 ${tag} 已存在,禁止重复发版。"
|
||||
echo "请先 bump crates/secrets-mcp/Cargo.toml 中的 version,再执行 cargo build 同步 Cargo.lock。"
|
||||
exit 1
|
||||
echo "⚠ 版本 ${tag} 已存在,将覆盖重新发版。"
|
||||
echo "tag_exists=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "将创建新版本 ${tag}"
|
||||
echo "tag_exists=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
echo "将创建新版本 ${tag}"
|
||||
|
||||
# ── Rust 工具链 ──────────────────────────────────────────────────────
|
||||
- name: 安装 Rust 与 musl 工具链
|
||||
@@ -107,13 +108,18 @@ jobs:
|
||||
path: target/${{ env.MUSL_TARGET }}/release/${{ env.MCP_BINARY }}
|
||||
retention-days: 3
|
||||
|
||||
# ── 创建 Tag(构建成功后才打,避免留下指向失败提交的 tag)──────────
|
||||
# ── 创建 / 覆盖 Tag(构建成功后才打)───────────────────────────────
|
||||
- name: 创建 Tag
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -a "${{ steps.ver.outputs.tag }}" -m "Release ${{ steps.ver.outputs.tag }}"
|
||||
git push origin "${{ steps.ver.outputs.tag }}"
|
||||
tag="${{ steps.ver.outputs.tag }}"
|
||||
if [ "${{ steps.ver.outputs.tag_exists }}" = "true" ]; then
|
||||
git tag -d "$tag" 2>/dev/null || true
|
||||
git push origin ":refs/tags/$tag" 2>/dev/null || true
|
||||
fi
|
||||
git tag -a "$tag" -m "Release $tag"
|
||||
git push origin "$tag"
|
||||
|
||||
# ── Release(可选,需配置 RELEASE_TOKEN)───────────────────────────
|
||||
- name: 创建并发布 Release
|
||||
@@ -140,6 +146,19 @@ jobs:
|
||||
--arg body "$body" \
|
||||
'{tag_name: $tag, name: $name, body: $body, draft: false}')
|
||||
|
||||
# 若已存在同名 Release 则先删除(覆盖重发)
|
||||
existing_code=$(curl -sS -o /tmp/existing-release.json -w '%{http_code}' \
|
||||
-H "Authorization: token $RELEASE_TOKEN" \
|
||||
"${release_api}/tags/${tag}")
|
||||
if [ "$existing_code" = "200" ]; then
|
||||
old_id=$(jq -r '.id // empty' /tmp/existing-release.json)
|
||||
if [ -n "$old_id" ]; then
|
||||
curl -sS -o /dev/null -H "Authorization: token $RELEASE_TOKEN" \
|
||||
-X DELETE "${release_api}/${old_id}"
|
||||
echo "已删除旧 Release: ${old_id}"
|
||||
fi
|
||||
fi
|
||||
|
||||
http_code=$(curl -sS -o /tmp/release.json -w '%{http_code}' \
|
||||
-H "Authorization: token $RELEASE_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
|
||||
Reference in New Issue
Block a user