【问题标题】:GitHub Action that updates the workflow file of another Action更新另一个 Action 的工作流文件的 GitHub Action
【发布时间】:2021-10-26 14:29:21
【问题描述】:

我在同一个 repo 中有两个 GitHub Actions。我正在尝试从另一个更新一个,但在尝试提交和推送更改时出现以下错误:

! [remote rejected] HEAD -> some-branch (refusing to allow a GitHub App to create or update workflow .github/workflows/the-other-action.yml without workflows permission)

这是我尝试运行的 GH Action 的简化版本:

name: my-action

on:
  workflow_dispatch:
  schedule:
    - cron: "0 9 * * *"

jobs:
  components:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the code
        uses: actions/checkout@v2

      - name: Update the other Action
        run: |
          # Do something to .github/workflows/the-other-action.yaml here

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3
        with:
            token: ${{ secrets.GITHUB_TOKEN }}
            branch: some-branch
            commit-message: Updated stuff

我想知道如何将workflows 权限授予GITHUB_TOKEN,但不知道如何?

(对于上下文:我每天运行一次此操作,以检查其他操作中使用的工具的新版本是否已发布。如果是,它会创建一个 PR 更新其他操作以使用较新版本而是)

【问题讨论】:

  • 您需要在此处使用具有工作流权限的PAT,而不是具有已定义范围的GITHUB_TOKEN。这是${{ secrets.GITHUB_TOKEN }} 你的 PAT 吗?如果是,那就有问题了,因为you can't add secrets with the GITHUB_ prefix.
  • 感谢@GuiFalourd! GITHUB_TOKEN 是默认令牌,而不是 PAT。但我最终使用 PAT 作为解决方法。很高兴知道使用默认令牌是不可能的。
  • 太棒了! :D 如果这解决了您的问题,我可以为您的问题添加官方答案吗?
  • @GuiFalourd,当然!

标签: github github-actions


【解决方案1】:

您需要在此处使用具有工作流程权限Personal Access Token,而不是具有已定义范围的GITHUB_TOKEN

此外,如果 ${{ secrets.GITHUB_TOKEN }} 是您的 PAT,则可能会出现问题,因为 you can't add secrets with the GITHUB_ prefix。所以你必须按照这个语法重命名秘密。

【讨论】:

    猜你喜欢
    • 2021-12-28
    • 2020-09-11
    • 2021-10-20
    • 2022-10-02
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 2020-01-01
    相关资源
    最近更新 更多