How do I clone A repo in B repo github actions if two repo is in same organization, not using PAT?

huangapple go评论59阅读模式
英文:

How do I clone A repo in B repo github actions if two repo is in same organization, not using PAT?

问题

在B存储库中,我需要克隆同一组织中的其他存储库。

例如,在B的操作中,我想要动态克隆A/C/D/E...和其他存储库。我不想添加每个私有存储库的个人访问令牌(PAT),因为所有存储库都在同一组织中,所以我只想使用全局组织密钥。

我尝试了这个:

      - name: 使用环境变量
        if: github.event.pull_request.merged
        env:
          SERVICE_NAME: ${{ env.SERVICE_NAME }}
          ENVIRONMENT: ${{ env.ENVIRONMENT }}
          VERSION: ${{ env.VERSION }}
        run: |
          echo "服务名称: $SERVICE_NAME"
          echo "环境: $ENVIRONMENT"
          echo "版本: $VERSION"          

      - name: 检出部署元数据
        uses: actions/checkout@v3
        with:
          ref: 'refs/heads/master'

      - name: 克隆部署服务器
        uses: actions/checkout@v3
        with:
          repository: private-repo/${{ env.SERVICE_NAME }}
          ref: v${{ env.VERSION }}
          token: ${{ secrets.GITHUB_TOKEN }}

但这不起作用。如何在不使用每个存储库的PAT的情况下克隆同一组织中的其他私有存储库?

英文:

In B repo, I have to clone other repos in same organization.

like, in B's action I want to clone A/C/D/E... and other repos dynamically.
I don't want to add each other private repo's PAT, because all repos are in same organization so I just want to use global organization secret.

I tried this:

      - name: Use environment variables
        if: github.event.pull_request.merged
        env:
          SERVICE_NAME: ${{ env.SERVICE_NAME }}
          ENVIRONMENT: ${{ env.ENVIRONMENT }}
          VERSION: ${{ env.VERSION }}
        run: |
          echo "Service name: $SERVICE_NAME"
          echo "Environment: $ENVIRONMENT"
          echo "Version: $VERSION"

      - name: checkout deploy-metadata
        uses: actions/checkout@v3
        with:
          ref: 'refs/heads/master'

      - name: clone deploying server
        uses: actions/checkout@v3
        with:
          repository: private-repo/${{ env.SERVICE_NAME }}
          ref: v${{ env.VERSION }}
          token: ${{ secrets.GITHUB_TOKEN }}

but this doesn't work. How to clone other private repo in same organization without using each repo's PAT?

答案1

得分: 1

这部分内容不需要翻译,因为它包括代码和引用链接,只提供翻译好的非代码文本部分:

"That was discussed before, and that thread references the documentation "Checkout multiple repos (private)""

${{ github.token }} is scoped to the current repository, so if you want to checkout a different repository that is private you will need to provide your own PAT.

So as long as you can provide a token of an account which has read access to each of those target repository, you should be able to clone them.

英文:

That was discussed before, and that thread references the documentation "Checkout multiple repos (private)"

> ${{ github.token }} is scoped to the current repository, so if you want to checkout a different repository that is private you will need to provide your own PAT.

- name: Checkout
  uses: actions/checkout@v3
  with:
    path: main

- name: Checkout private tools
  uses: actions/checkout@v3
  with:
    repository: my-org/my-private-tools
    token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT
    path: my-tools

So as long as you can provide a token of an account which has read access to each of those target repository, you should be able to clone them.

huangapple
  • 本文由 发表于 2023年2月27日 16:20:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578151.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定