在GitHub Actions中使用个人访问令牌(PAT)时遇到问题

8

我有一个GitHub账户。

我有一个私人组织,和几个私人存储库。

我想为我的私人组织中的私人存储库定义一个操作。

private_org\private_rpo

我可以使用${{ github.token }}action/checkout@2检出我的private_repo

然而,在这个存储库的操作中检出其他repo时,我卡住了。

以下是我的代码:

      - name: Get private_org/private_repo using actions/checkout@v2
        uses: actions/checkout@v2
        with:
          repository: private_org/private_repo
          token: ${{ github.token }}
          path: private_org/private_repo
          
      - name: Get private_org/private_repo_2 using actions/checkout@v2
        uses: actions/checkout@v2
        with:
          repository: private_org/private_repo_2
          token: ${{ github.pat }}
          path: private_org/private_repo_2 

我在我的账户(开发者设置)中创建了一个PAT,并将pat定义为private_org / private_repo中的secret。

然而,action/checkout@2报错:

运行 actions/checkout@v2
错误:需要输入并未提供:token

我应该如何解决这个问题?在哪里定义我的 pat secret?如何在这个私有仓库的 action 中 checkout 我的其他私有仓库?


我们还可以使用${{ secrets.GITHUB_TOKEN }}作为${{ github.token }}的更安全的替代方案,因为前者是在作业之前创建并在其之后销毁的。请查看此链接https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token - VIVEK JAIN
1个回答

7

这个问题发生的原因是您在Github Actions中没有正确使用secrets

这里是需要更新的部分:

      - name: Get private_org/private_repo_2 using actions/checkout@v2
        uses: actions/checkout@v2
        with:
          repository: private_org/private_repo_2
          token: ${{ secrets.pat }} # use "secrets." instead of "github."
          path: private_org/private_repo_2 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接