0%

2023-04-06 如何解决 semantic-release 在 Github Actions 运行时 403 的问题

2023-04-06 如何解决 semantic-release 在 Github Actions 运行时 403 的问题

温馨提示:本文使用 ChatGPT 润色

出现问题

前几天写了一个 npm 包,按照惯例 push 到 GitHub 上用 semantic-release 来发布,在配置完 GH_TOKEN 和 NPM_TOKEN 之后遇到了 403 权限问题:

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://[secure]@github.com/CaoMeiYouRen/xxxxx.

This can be caused by:

简单来说就是没有 Git 权限来推送到我的代码仓库。

但很奇怪的是,我的配置和以往的项目是一样的,检查了 semantic-release 的版本之后也是一样的,甚至在当天还发布过老项目的 fix 版本,也是正常 release 了,这就非常奇怪了。

解决问题

在翻看过 semantic-release 的 issues 之后,我发现了一个解决方案:semantic-release/issues/2636 , 其中有提到要做如下的配置。

具体参考:Pushing package.json changes to a master branch

1
2
3
4
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false # <--- this

在修改了 GitHub Actions 的相关配置之后,执行成功了,问题解决!

总结

这次出现问题的原因可能是因为 Github Actions 出现了安全性升级,在权限方面更加严格了,具体的原因还有待后续分析。

本文作者:草梅友仁
本文地址: https://blog.cmyr.ltd/archives/4a22ebbf.html
版权声明:转载请注明出处!

坚持原创技术分享,您的支持将鼓励我继续创作!