【问题标题】:Can't push to protected branch in GitHub Action无法推送到 GitHub Action 中的受保护分支
【发布时间】:2020-09-04 11:25:58
【问题描述】:

我创建了一个 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 是我从我的帐户创建的个人访问令牌。我已经设置了 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.

我一直在绞尽脑汁试图弄清楚这一点,并且我正在提出想法。如果我删除分支保护,此操作可以正常工作。

【问题讨论】:

    标签: github-actions


    【解决方案1】:

    我认为这是因为actions/checkout 坚持身份验证的方式。它存储在 extraheader 配置选项中,该选项优先于您手动设置的凭据。

    尽量不要持久化身份验证:

      - uses: actions/checkout@v2
        with:
          persist-credentials: false
    

    或者:

      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.KEY }}
    

    我知道这一点是因为我的 own issue 过去曾覆盖此配置选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-04
      • 2020-11-08
      • 2021-02-10
      • 2012-11-23
      • 2013-01-15
      • 1970-01-01
      • 2016-12-13
      • 2020-12-07
      相关资源
      最近更新 更多