From 2a5d18e33980bf8fc2459466c6d52094b944f63e Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Wed, 26 Aug 2026 12:58:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Nacos=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=9B=9E=E8=AF=BB=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/scripts/publish-nacos.mjs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.gitea/scripts/publish-nacos.mjs b/.gitea/scripts/publish-nacos.mjs index bb95d787..70d1bbfd 100644 --- a/.gitea/scripts/publish-nacos.mjs +++ b/.gitea/scripts/publish-nacos.mjs @@ -107,10 +107,22 @@ async function verify(baseUrls, token, namespace, configGroup, dataId, expectedC const expectedHash = sha256(expectedContent); for (const baseUrl of baseUrls) { const query = new URLSearchParams({ dataId, group: configGroup, tenant: namespace }); - const response = await fetch(`${baseUrl}/nacos/v1/cs/configs?${query}&accessToken=${encodeURIComponent(token)}`); - const content = await response.text(); - if (!response.ok || sha256(content) !== expectedHash) { - throw new Error(`Nacos 配置校验失败:${baseUrl}/${namespace}/${dataId} HTTP ${response.status}`); + let lastStatus = 0; + let lastContent = ''; + for (let attempt = 1; attempt <= 3; attempt += 1) { + const response = await fetch(`${baseUrl}/nacos/v1/cs/configs?${query}&accessToken=${encodeURIComponent(token)}`); + const content = await response.text(); + lastStatus = response.status; + lastContent = content; + if (response.ok && sha256(content) === expectedHash) { + break; + } + if (attempt < 3) { + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + } + if (lastStatus !== 200 || sha256(lastContent) !== expectedHash) { + throw new Error(`Nacos 配置校验失败:${baseUrl}/${namespace}/${dataId} HTTP ${lastStatus} ${lastContent.slice(0, 200)}`); } } }