fix: deploy verify parsing must ignore ssh warning lines (#55)

Co-authored-by: host <host@test.local>
This commit is contained in:
openqjandhost authored and GitHub committed 2026-10-27 00:41:40 +08:00
1 parent 32125f7a98
commit 84ff968111
2 files changed
+45 -2

No files matched your search

+16 -2
View File
@@ -35,6 +35,7 @@ import argparse
import hashlib
import json
import os
import re
import shutil
import subprocess
import sys
@@ -183,11 +184,24 @@ def scp_cmd(host, user, local, remote):
def remote_sha(host, user, remote_path):
"""远端 sha256sum 的输出里取 64 位 hex。不能取 split()[0]:经 pty
的 ssh helper 会把 stderr 的 Warning(例如 Permanently added to
the list of known hosts)合并进 stdout 放在 sha 行前面,首 token
于是变成 Warning:,导致传输明明成功却被判验真失败(2026-10-27
新链路首推实测)。"""
r = subprocess.run(ssh_cmd(host, user, "sha256sum %s" % remote_path),
capture_output=True, text=True)
if r.returncode != 0:
return None
return r.stdout.split()[0] if r.stdout.split() else None
m = re.search(r"\b[0-9a-f]{64}\b", r.stdout)
return m.group(0) if m else None
def live_commit(text):
"""从 ssh 输出里取 40 位 commit。理由同 remote_sha:helper 的
Warning 行会混进 stdout,直接 strip() 比对必失败。"""
m = re.search(r"\b[0-9a-f]{40}\b", text)
return m.group(0) if m else None
def remote_rm(host, user, remote_path):
@@ -312,7 +326,7 @@ def main(argv=None):
live = subprocess.run(
ssh_cmd(host, user, "cat /opt/codex-app-server/DEPLOYED_COMMIT"),
capture_output=True, text=True)
if live.stdout.strip() != commit:
if live_commit(live.stdout) != commit:
print("二次核对失败:live DEPLOYED_COMMIT=%s,期望 %s。"
"请立即用 deploy/rollback.sh 检查,不要再推新版。"
% (live.stdout.strip(), commit), file=sys.stderr)