简体   繁体   English

如何在另一个 git repo 中添加私有 git repo 作为子模块

[英]How to Add Private git repo as a submodule in another git repo

How to add a private git repository as a submodule in another git repository?如何将私有 git 存储库添加为另一个 git 存储库中的子模块?

locally when i do git submodule update it works fine, but in the github action runner, it fails with error stating url not found at the checkout step.当我在本地执行git submodule update它工作正常,但在 github 操作运行器中,它失败并显示在结帐步骤未找到 url的错误。

Here's how i have configured my workflow file.这是我配置工作流文件的方式。

jobs:
  update_submodules:
    runs-on: ubuntu-latest

    steps:
      # Checkout the repository to the GitHub Actions runner
      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: true

      # - name: Clone submodule
      #   run: git submodule update --init --recursive

      - name: Pull & update submodules recursively
        run: |
          git submodule update --init --recursive
          git submodule update --recursive --remote

It fails in the second step.它在第二步中失败。

You could not have to code the submodule update init , as it is an option of the action/checkout itself.您不必submodule update init进行编码,因为它是action/checkout本身的一个选项。

For instance, actions/checkout issue 116 shows:例如, actions/checkout issue 116显示:

  • Generate PAT: https://github.com/settings/tokens生成 PAT: https ://github.com/settings/tokens
  • And add the secret: https://github.com/<-- username -->/<-- repo -->/settings/secrets/new , give it a unique name say MY_REPO_PAT .并添加秘密: https://github.com/<-- username -->/<-- repo -->/settings/secrets/new ,给它一个唯一的名字说MY_REPO_PAT
  • Configure action as follows:配置动作如下:
 steps: - name: Checkout uses: actions/checkout@v2 with: token: ${{ secrets.MY_REPO_PAT }} submodules: recursive

Or (alternative), issue 287 :或者(替代), 第 287 期

I have a solution that doesn't require personal access tokens but keeps the reference to the child repo commit in one place (using git submodules)我有一个不需要个人访问令牌但将子回购提交的引用保存在一个地方的解决方案(使用 git 子模块)

 - name: clone submodule uses: actions/checkout@v2 with: repository: <org name>/<repo name> path: path ssh-key: ${{ secrets.SSH_KEY }} persist-credentials: true - name: checkout submodule run: | git submodule init git submodule update

Although the action checks out master , the git submodule commands check out the correct commit, this avoids having to keep the ref in github actions.尽管该操作检查了master ,但git submodule命令检查了正确的提交,这避免了必须将 ref 保留在 github 操作中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM