在 GitHub 操作中使用 GitHub CLI 访问另一个存储库

Accessing another repository with GitHub CLI in GitHub Actions

我正在尝试使用 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,我知道这是因为存储库是私有的,即使两个存储库具有相同的所有者。 在本地进行身份验证时,该命令工作正常。

有什么方法可以在工作流程中访问该存储库吗?

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 调用其他存储库中的资源。