From 06889ab3ecbe67188385d6a62fe63a0e1c1c65e1 Mon Sep 17 00:00:00 2001 From: pyh Date: Wed, 30 Sep 2026 11:35:43 +0800 Subject: [PATCH] ci: point the default registry at Gitea and recognise npm's duplicate-version error Without setup-node nothing wrote the default registry, so npm compared versions against registry.npmjs.org and refused with 'cannot publish over the previously published versions'. The step now sets the default registry too, and treats both that message and Gitea's 409 as an idempotent skip. --- .gitea/workflows/publish.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml index b816292..87aed95 100644 --- a/.gitea/workflows/publish.yml +++ b/.gitea/workflows/publish.yml @@ -90,14 +90,18 @@ jobs: echo "没有可用的发布令牌:请配置 NPM_TOKEN,或确认实例会注入 GITEA_TOKEN" >&2 exit 1 fi - # 作用域与默认注册表都指向本组织的 npm 仓库,并把令牌写进本机 .npmrc。 + # 作用域与默认注册表都指向本组织的 npm 仓库(默认注册表也要设,否则 npm 会拿 + # registry.npmjs.org 的 packument 做“是否已发布”判断,甚至可能发错地方), + # 并把令牌写进本机 .npmrc。 # 注意:npm 不允许用 `npm config get` 读回 _authToken(会报 protected),所以不打印它。 + npm config set registry "${REGISTRY}" npm config set @dsh-plugin:registry "${REGISTRY}" npm config set "//gitea.iwake.top/api/packages/dsh-plugin/npm/:_authToken" "${token}" echo "registry = $(npm config get registry)" # 已发布的版本由注册表自己判定:Gitea 对同版本返回 409(package version already - # exists)。把它当成“本次无需发布”而不是失败;其他错误(E401/E403 等)照旧失败。 + # exists),npm 客户端在本地也会用 "cannot publish over the previously published + # versions" 拦下来。两种都算“本次无需发布”而不是失败;其余错误(E401/E403 等)照旧失败。 set +e output="$(npm publish --registry "${REGISTRY}" --access public 2>&1)" status=$? @@ -105,7 +109,7 @@ jobs: printf '%s\n' "${output}" if [ "${status}" -eq 0 ]; then echo "已发布 ${{ steps.version.outputs.name }}@${{ steps.version.outputs.version }}" - elif printf '%s' "${output}" | grep -Eq 'E409|already exists'; then + elif printf '%s' "${output}" | grep -Eqi 'E409|already exists|previously published|cannot publish over'; then echo "${{ steps.version.outputs.name }}@${{ steps.version.outputs.version }} 已存在,本次跳过(不算失败)" else exit "${status}"