build: 完善 deploy.py 校验逻辑(ssh -q 静默 + 完整 hash 比对)

This commit is contained in:
Ubuntu
2026-09-17 10:53:04 +08:00
parent 9510d7509e
commit d023ef0cd8
+10 -8
View File
@@ -29,7 +29,7 @@ os.chdir(ROOT)
# "The following paths are ignored by one of your .gitignore files")
DEFAULT_MSG = 'chore: 部署更新'
SSH_BASE = ("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "
SSH_BASE = ("ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "
"-o ConnectTimeout=10 ubuntu@106.55.169.92")
REMOTE_DIR = "/var/www/qianshi"
TIMEOUT = 60
@@ -104,16 +104,18 @@ def deploy(msg=DEFAULT_MSG):
return False
log(' %s' % out.splitlines()[-1] if out else ' ok')
# 校验三端一致
_, local = sh(['git', 'rev-parse', '--short', 'HEAD'])
_, srv = remote('git rev-parse --short HEAD', 30)
srv = srv.strip().splitlines()[-1] if srv else '?'
if local != srv:
log('!! 本地 %s != 服务器 %s,同步失败' % (local, srv))
# 校验两端一致(取完整 hash 的最末纯 hash 行,避免 pull 进度信息干扰)
_, local = sh(['git', 'rev-parse', 'HEAD'])
_, srv = remote('git rev-parse HEAD', 30)
srv_hash = next((l for l in srv.splitlines() if len(l) == 40 and all(
c in '0123456789abcdef' for c in l)), '?')
if local != srv_hash:
log('!! 本地 %s != 服务器 %s,同步失败' % (local[:7], srv_hash[:7]))
return False
log(' 服务器 HEAD: %s' % srv_hash[:7])
log('')
log('=== 部署完成 ===')
log('提交: %s %s' % (local, msg))
log('提交: %s %s' % (local[:7], msg))
log('本地/服务器 已同步,工作流无 commit 交叉')
return True