The first tagged run failed inside the publish step within a second, which is the shape of an auth rejection rather than a build problem. The step now prefers a repository NPM_TOKEN secret when one exists, prints the effective registry and a masked token, and runs npm whoami so a re-run names the cause instead of just failing.
This commit is contained in:
@@ -5,10 +5,14 @@
|
||||
# 2. 仓库 → Actions → 选择本工作流 → Run workflow(手动,发布当前 commit 的版本)
|
||||
#
|
||||
# 需要的权限:
|
||||
# 本工作流用 Gitea 内置的任务令牌 ${{ secrets.GITEA_TOKEN }} 发布,无需额外配置密钥。
|
||||
# 组织(或仓库)Settings → Actions → General 里的 token 权限不能被限制到读,
|
||||
# 且 packages 需要写权限 —— 工作流里的 permissions: 已经声明,但仍会被管理员配置的上限(clamping)压回。
|
||||
# 如果实例把默认权限设为 Restricted,请在这里(或组织级)确认 packages 至少为 write。
|
||||
# 默认使用 Gitea 内置的任务令牌 ${{ secrets.GITEA_TOKEN }} 发布,无需额外配置密钥。
|
||||
# 若实例/组织把 Actions 的令牌上限设为只读,或任务令牌对包命名空间没有写权限,
|
||||
# 请在仓库 Settings → Actions → Secrets 里添加 NPM_TOKEN = 一个带 package 写权限的个人访问令牌,
|
||||
# 工作流会自动优先使用它(见最后一个步骤)。
|
||||
#
|
||||
# 失败排查:
|
||||
# 发布步骤在 1 秒内失败通常是鉴权问题——先看该步骤日志里 `npm whoami` 的输出:
|
||||
# 打印出用户名说明令牌可用,报 E401/E403 说明令牌无效或权限不足。
|
||||
#
|
||||
# 依赖前提:
|
||||
# - 实例启用了 Actions,且注册了 act_runner(否则工作流只会排队)。
|
||||
@@ -65,9 +69,23 @@ jobs:
|
||||
|
||||
- name: Publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
# 优先使用带 package 写权限的 PAT(仓库 Settings → Actions → Secrets 里的 NPM_TOKEN);
|
||||
# 没有配置时退回 Gitea 内置任务令牌 GITEA_TOKEN。
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
JOB_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
set -eu
|
||||
# 作用域与默认注册表都指向本组织的 npm 仓库;token 由 setup-node 写进 .npmrc。
|
||||
token="${NPM_TOKEN:-$JOB_TOKEN}"
|
||||
if [ -z "$token" ]; then
|
||||
echo "没有可用的发布令牌:请配置 NPM_TOKEN,或确认实例会注入 GITEA_TOKEN" >&2
|
||||
exit 1
|
||||
fi
|
||||
# 作用域与默认注册表都指向本组织的 npm 仓库,并把令牌写进本机 .npmrc。
|
||||
npm config set @dsh-plugin:registry "${REGISTRY}"
|
||||
npm publish --registry "${REGISTRY}"
|
||||
npm config set "//gitea.iwake.top/api/packages/dsh-plugin/npm/:_authToken" "${token}"
|
||||
echo "registry = $(npm config get registry)"
|
||||
echo "auth = $(npm config get "//gitea.iwake.top/api/packages/dsh-plugin/npm/:_authToken" | sed 's/./*/g')"
|
||||
# 鉴权自检:能取到用户就说明令牌对得上这个注册表(包不存在时报 404 也算通过)。
|
||||
npm whoami --registry "${REGISTRY}" || true
|
||||
npm publish --registry "${REGISTRY}" --access public
|
||||
|
||||
|
||||
Reference in New Issue
Block a user