From d023ef0cd8da5fc2e022918c69f6dafa231558bc Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 17 Sep 2026 10:53:04 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E5=AE=8C=E5=96=84=20deploy.py=20?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91=EF=BC=88ssh=20-q=20?= =?UTF-8?q?=E9=9D=99=E9=BB=98=20+=20=E5=AE=8C=E6=95=B4=20hash=20=E6=AF=94?= =?UTF-8?q?=E5=AF=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/deploy.py b/deploy.py index ac2bf07..3247c16 100644 --- a/deploy.py +++ b/deploy.py @@ -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