0

我正在尝试使用 gh cli 作为工作流程的一部分访问另一个 github 存储库。我正在使用如下gh release view命令

run: |
    echo "::set-output name=description::$(gh release view --repo <owner/repo>)"
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

工作流程因 404 失败,我知道这是因为存储库是私有的,即使两个存储库具有相同的所有者。在本地进行身份验证时,该命令可以正常工作。

有没有办法在工作流程中访问该仓库?

4

1 回答 1

1

GITHUB_TOKEN 仅适用于触发存储库。如果您需要访问其他存储库或其他帐户中的任何资源,则需要将范围更广的令牌传递给结帐步骤。这可以是 GitHub 应用令牌、个人访问令牌等。

将令牌存储在 Secrets/Actions 中并将其传递给结帐任务的令牌参数。

或者,您可以通过“ssh-key”参数传入 ssh 密钥。

- uses: actions/checkout@v2
  with:
    # Repository name with owner. For example, actions/checkout
    # Default: ${{ github.repository }}
    repository: ''

    # Personal access token (PAT) used to fetch the repository. The PAT is configured
    # with the local git config, which enables your scripts to run authenticated git
    # commands. The post-job step removes the PAT.
    #
    # We recommend using a service account with the least permissions necessary. Also
    # when generating a new PAT, select the least scopes necessary.
    #
    # [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
    #
    # Default: ${{ github.token }}
    token: ''

    # SSH key used to fetch the repository. The SSH key is configured with the local
    # git config, which enables your scripts to run authenticated git commands. The
    # post-job step removes the SSH key.
    #
    # We recommend using a service account with the least permissions necessary.
    #
    # [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
    ssh-key: ''

这同样适用于通过 API 或 GitHub CLI 调用其他存储库中的资源。

于 2022-02-10T18:06:11.343 回答