如何解决无法推送到GitHub Action中的受保护分支
我创建了一个GitHub操作,以创建一个新版本并将其发布给我们的JS回购。看起来与此类似
steps:
# Checks-out your repository under $GITHUB_WORKSPACE,so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.18.3
registry-url: https://npm.pkg.github.com/
scope: '<redacted>'
- name: Install Dependencies
run: npm ci
- name: Build
run: npm run build
- name: Bump Version & Push
run: |
git config --local user.email "<redacted>"
git config --local user.name "<redacted>"
npm version patch
git push https://${{ secrets.KEY }}@github.com/<redacted> HEAD:master --follow-tags
我正在使用的KEY是我从我的帐户创建的个人访问令牌。我已经设置了存储库,以便可以推送访问master分支。当我尝试使用访问令牌从机器上执行push命令时,它可以正常工作。但是,每次我在GitHub Action中看到这一点
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: You're not authorized to push to this branch. Visit https://docs.github.com/articles/about-protected-branches/ for more information.
我一直在绞尽脑汁,试图弄清楚这一点,但我有很多想法。如果我删除分支保护,则此操作正常。
解决方法
我认为这是因为actions/checkout
如何保持身份验证。它存储在extraheader
配置选项中,该选项优先于您手动设置的凭据。
尝试不保留身份验证:
- uses: actions/checkout@v2
with:
persist-credentials: false
或者:
- uses: actions/checkout@v2
with:
token: ${{ secrets.KEY }}
我之所以知道这一点,是因为我过去曾经使用过own issue来覆盖此配置选项。
,只需将n拖放到“添加文件”按钮下
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。