Prechádzať zdrojové kódy

【维护】发布脚本增加鉴权预检

原脚本在 gh 未鉴权时会先推送 tag、再在创建 Release 时失败,留下没有
Release 的悬空 tag。现把鉴权检查前移,并支持用 GH_TOKEN 免登录发布。

- release.sh 在打 tag 前校验 gh 鉴权;设置 GH_TOKEN 时跳过 gh auth status。
- 前置说明补充 GH_TOKEN 用法。
- docs/development.md 同步更新中英文发布前置描述。
PJ568 1 mesiac pred
rodič
commit
141a24b4fd
2 zmenil súbory, kde vykonal 10 pridanie a 4 odobranie
  1. 2 2
      docs/development.md
  2. 8 2
      scripts/release.sh

+ 2 - 2
docs/development.md

@@ -37,7 +37,7 @@ scripts/release.sh
 scripts/release.sh --dry-run
 ```
 
-发布前置:已安装并登录 GitHub CLI(`gh`),且仓库已配置 `remote origin`。`release.sh` 会校验工作区干净、tag 不存在,发布后自动创建带 zip 附件的 Release。
+发布前置:已安装并完成鉴权的 GitHub CLI(`gh auth login`,或提供 `GH_TOKEN` 环境变量),且仓库已配置 `remote origin`。`release.sh` 会在打 tag 之前校验工作区干净、tag 不存在以及 gh 鉴权,发布后自动创建带 zip 附件的 Release。
 
 ## 部署(本机)
 
@@ -91,7 +91,7 @@ scripts/release.sh
 scripts/release.sh --dry-run
 ```
 
-Release prerequisites: GitHub CLI (`gh`) installed and logged in, and a configured `remote origin`. `release.sh` verifies a clean work tree and a fresh tag, then creates a Release with the zip attached.
+Release prerequisites: an installed and authenticated GitHub CLI (`gh auth login`, or a `GH_TOKEN` environment variable), and a configured `remote origin`. `release.sh` checks a clean work tree, a fresh tag and gh authentication before tagging, then creates a Release with the zip attached.
 
 ## Deploy (Local)
 

+ 8 - 2
scripts/release.sh

@@ -3,8 +3,8 @@
 # 构建 → 打包 → 打 tag → 推送 → 创建 GitHub Release
 # build → package → tag → push → create GitHub Release
 # 用法 / Usage:scripts/release.sh [--dry-run]
-# 前置 / Prerequisites:已安装并登录 gh,且仓库已配置 remote origin
-#   GitHub CLI (gh) installed and logged in, with a configured remote origin
+# 前置 / Prerequisites:已安装 gh 并完成鉴权(gh auth login,或提供 GH_TOKEN),且仓库已配置 remote origin
+#   GitHub CLI (gh) installed and authenticated (gh auth login, or provide GH_TOKEN), with a configured remote origin
 set -euo pipefail
 
 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -60,6 +60,12 @@ fi
 command -v gh >/dev/null 2>&1 || { echo "错误:未安装 GitHub CLI(gh)| Error: GitHub CLI (gh) not installed" >&2; exit 1; }
 git remote get-url origin >/dev/null 2>&1 || { echo "错误:未配置 git remote origin | Error: no git remote 'origin' configured" >&2; exit 1; }
 
+# 需要可用的 gh 鉴权(或提供 GH_TOKEN);在打 tag 之前校验,避免留下没有 Release 的悬空 tag
+# Require working gh auth (or GH_TOKEN); checked before tagging to avoid a dangling tag without a Release
+if [ -z "${GH_TOKEN:-}" ]; then
+  gh auth status >/dev/null 2>&1 || { echo "错误:gh 未登录,请先 gh auth login 或设置 GH_TOKEN | Error: gh is not authenticated; run gh auth login or set GH_TOKEN" >&2; exit 1; }
+fi
+
 git tag -a "$TAG" -m "PerformanceScope $TAG"
 git push origin "$BRANCH"
 git push origin "$TAG"