How to Add Private git repo as a submodule in another git repo

Viewed 106

How to add a private git repository as a submodule in another git repository?

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.

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.

1 Answers

You could not have to code the submodule update init, as it is an option of the action/checkout itself.

For instance, actions/checkout issue 116 shows:

  • Generate 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.
  • Configure action as follows:
   steps:
   - name: Checkout
     uses: actions/checkout@v2
     with:
       token: ${{ secrets.MY_REPO_PAT }}
       submodules: recursive

Or (alternative), issue 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)

   - 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.

Related