无法在 GitHub 操作中推送到受保护的分支

Chu*_*nes 2 github-actions

我创建了一个 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
Run Code Online (Sandbox Code Playgroud)

我使用的 KEY 是我从我的帐户创建的个人访问令牌。我已经设置了 repo,以便我可以推送访问 master 分支。当我使用访问令牌从我的机器尝试推送命令时,它可以正常工作。但是每次我在 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.
Run Code Online (Sandbox Code Playgroud)

我一直在绞尽脑汁想弄明白这一点,而且我想出主意。如果我删除分支保护,则此操作可以正常工作。

pet*_*ans 5

我认为这是因为actions/checkout. 它存储在一个extraheader配置选项中,该选项优先于您手动设置的凭据。

尝试不坚持认证:

  - uses: actions/checkout@v2
    with:
      persist-credentials: false
Run Code Online (Sandbox Code Playgroud)

或者:

  - uses: actions/checkout@v2
    with:
      token: ${{ secrets.KEY }}
Run Code Online (Sandbox Code Playgroud)

我知道这一点是因为我过去在覆盖此配置选项时遇到了自己的问题