fix(ci): vps-deploy/workflow四雷根治(pipefail×3+ssh裸连+收尾非幂等+关issue不查gap)——issue#33基建工作包#1-#4 [nas]
pipefail+SIGPIPE 三处(本机复现rc=141确定性,run724根因): - L82端口释放检测被反转(最危险): netstat大输出|grep -q命中即提前退出→上游tr吃SIGPIPE(141)→pipefail判整管道失败→走||分支谎报「已释放」→下一步/run撞10048竞态 - L91 API等待循环同雷=run724死因: 检测恒假→120轮耗尽exit1→收尾三步全跳过 - L98 /docs探活同族(输出仅3字节几乎不触发,顺手修) 修法: grep -q 'x' → grep 'x' >/dev/null(读完整流不提前退出,无SIGPIPE) workflow内裸ssh全量补 -o ConnectTimeout=20(对齐vps_restart_resident.sh写法): 单次ssh挂死原会让整步无限冻结; vps-deploy.yml 9处+ci-cd.yml 2处(NAS) 收尾三步抽幂等脚本 scripts/ci/vps_finalize.sh(工作包#2): - run681/715/724三实录: 部署本体成功但收尾被前序步骤失败整段跳过,只能人工拼三段补 - 现在workflow尾步自动调; 被跳过时Mac本机手跑即补: GTOKEN=<token> bash scripts/ci/vps_finalize.sh <部署的sha> - 常驻重启失败不阻断tag/issue记账(代码已就位,末尾非零退出提醒); tag -f+push -f天然幂等; issue按真实gap开/关 关issue按真实gap(工作包#3,2026-08-21事故): - 旧代码硬编码VPS_LOG=""无脑关issue——用户dispatch填旧sha(f28f9cf≠be315a0)漏推P0后,gap非空也关→用户误以为推完 - 修=finalize算vps-deployed..origin/master真实gap,非空则issue保持open并列剩余清单 - gap改按subject算(--format='%h %s'|grep,与enforce-label同定义): --grep匹配整个message,commit body里引用的命令文本会误命中(曾误开issue#7); ci-cd.yml check-vps-needed同步改 - vps_pending_check.py: GITHUB_SHA缺失时回退VPS_DEPLOY_SHA(支持Mac手跑); 有上轮部署sha时body加「仍未上VPS」警示
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
# vps-deploy 收尾三步: 常驻滚动重启 + 打 vps-deployed tag + [待推VPS] issue 维护。
|
||||
# 为什么抽脚本(2026-08-22 基建工作包#2, issue#33): run681/715/724 三次实录——部署本体
|
||||
# 成功但前序步骤(端口等待/API探活)失败时, 收尾三步被整段跳过, 只能人工拼三段补。
|
||||
# 抽出后幂等可重入:
|
||||
# - workflow 正常走到尾: vps-deploy.yml 最后一步自动调用
|
||||
# - 收尾被跳过时: Mac 本机手跑补, 不再人工拼命令:
|
||||
# GTOKEN=<gitea token> bash scripts/ci/vps_finalize.sh <本轮部署的sha>
|
||||
# 三步各自幂等: 常驻重启(盘中 09:15-15:30 自动跳过) / tag -f + push -f / issue 按真实 gap 开或关。
|
||||
# ⚠️ gap 按 subject 算(与 enforce-label 同定义, git log --format='%h %s' 再 grep):
|
||||
# 不能用 --grep='\[vps\]'——它匹配整个 message, commit body 里引用的命令文本会误命中(曾误开 issue#7)。
|
||||
set -euo pipefail
|
||||
VPS_DEPLOYED_TAG=vps-deployed
|
||||
SHA="${1:?用法: GTOKEN=<token> bash scripts/ci/vps_finalize.sh <本轮部署的sha(40位)>}"
|
||||
export GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-sanguo/sanguo_vnpy_v2}"
|
||||
|
||||
FAIL=0
|
||||
|
||||
# ---- 1) 常驻进程滚动重启(幂等; 失败不阻断 tag/issue 记账——代码已就位, 末尾非零退出提醒人工) ----
|
||||
if bash scripts/nas_sync/vps_restart_resident.sh; then
|
||||
echo "✅ 收尾 1/3: 常驻进程已滚动重启(或盘中自动跳过)"
|
||||
else
|
||||
echo "❌ 收尾 1/3: 常驻重启失败(部署本体已成功, 代码已就位)——重跑本脚本即可补"
|
||||
FAIL=1
|
||||
fi
|
||||
|
||||
# ---- 2) 打 tag(VPS 版本真相; tag -f + push -f 幂等)。origin 在 workflow checkout 里
|
||||
# 已是带 token 的 remote, 手跑时是本仓库日常 remote, 两种上下文都直推 ----
|
||||
git tag -f "$VPS_DEPLOYED_TAG" "$SHA"
|
||||
git push -f origin "refs/tags/$VPS_DEPLOYED_TAG"
|
||||
echo "✅ 收尾 2/3: $VPS_DEPLOYED_TAG → ${SHA:0:7}"
|
||||
|
||||
# ---- 3) [待推VPS] issue 维护: 按 vps-deployed..origin/master 真实 gap 决定开/关 ----
|
||||
# (2026-08-21 事故: 用户 dispatch 填了旧 sha, 收尾硬编码 VPS_LOG="" 无脑关 issue——
|
||||
# gap 非空也关, 用户误以为推完。修 = 算真实 gap, 非空则 issue 保持 open 并列出剩余清单)
|
||||
if [ -z "${GTOKEN:-}" ]; then
|
||||
echo "⚠️ 收尾 3/3: GTOKEN 未设置, 跳过 issue 维持(workflow 自带; 手跑需 GTOKEN)——issue 保持现状偏保守"
|
||||
else
|
||||
git fetch origin master --depth 200 2>/dev/null || git fetch origin master
|
||||
export VPS_LOG="$(git log --format='%h %s' "$VPS_DEPLOYED_TAG..origin/master" | grep -E '\[vps\]' || true)"
|
||||
export VPS_DEPLOY_SHA="$SHA"
|
||||
python3 scripts/ci/vps_pending_check.py
|
||||
echo "✅ 收尾 3/3: issue 维护完成(按真实 gap 开/关)"
|
||||
fi
|
||||
|
||||
exit $FAIL
|
||||
@@ -21,7 +21,7 @@ API_BASE = "http://192.168.2.154:3000/api/v1/repos/"
|
||||
def main():
|
||||
token = os.environ["GTOKEN"]
|
||||
repo = os.environ["GITHUB_REPOSITORY"]
|
||||
sha = os.environ["GITHUB_SHA"]
|
||||
sha = os.environ.get("GITHUB_SHA") or os.environ.get("VPS_DEPLOY_SHA") or "HEAD"
|
||||
vps_log = os.environ.get("VPS_LOG", "").strip()
|
||||
api = API_BASE + repo
|
||||
|
||||
@@ -53,10 +53,15 @@ def main():
|
||||
n = len([l for l in vps_log.splitlines() if l.strip()])
|
||||
print(f"⚠️ 待推 VPS: {n} 个 [vps] commit")
|
||||
print(vps_log)
|
||||
prev = os.environ.get("VPS_DEPLOY_SHA", "")
|
||||
body = (
|
||||
f"nas-verify 绿 @{sha[:7]}, 以下 [vps] commit 待推 VPS:\n"
|
||||
f"```\n{vps_log}\n```\n\n"
|
||||
f"推法: Gitea → Actions → vps-deploy.yml → Run workflow, sha={sha}\n"
|
||||
+ (
|
||||
f"⚠️ 上一轮 vps-deploy 只部署到 @{prev[:7]}, 上述 commit 仍未上 VPS —— issue 保持 open(不再无脑关)。\n\n"
|
||||
if prev else ""
|
||||
)
|
||||
+ f"推法: Gitea → Actions → vps-deploy.yml → Run workflow, sha={sha}\n"
|
||||
f"agent: dispatch vps-deploy.yml inputs={{sha:{sha}}}"
|
||||
)
|
||||
if pending:
|
||||
|
||||
Reference in New Issue
Block a user