How to access private repositories from Github Actions?

September 12, 20212 min read#ios, #swift, #github, #github-actions, #continuous-delivery, #continuous-integration

The problem

I have an iOS app project with dependencies as Swift Packages hosted in private repositories on Github.

When working locally, my laptop can resolve the depedencies and checkout successfully because it has the private key configured for Github.

But when running in Github Actions, the private repositories can not be accessed since the runners is not configured to access the private repositories.

The Solution

Since the private repositories that my app dependeing on are mine as well, therefore I can add the required configuration into those private repositories.

The following steps are required to setup the SSH keys for the runner during runtime to access the private repositories:

  • Create 2 SSH keys for the 2 private repositories by running ssh-keygen -t ed25519 twice.
  • Put each public key as deployment key into each private repository.
  • Put 2 private keys as a secret into the main repository.
  • Change your action a bit
- uses: shaunco/ssh-agent@git-repo-mapping # this action will configure git to use the right SSH key per each repository. 
    ssh-private-key: |
      ${{ secrets.SUBMODULE_1_SSH_PRIVATE_KEY}}
      ${{ secrets.SUBMODULE_2_SSH_PRIVATE_KEY}}
    repo-mappings: |

- uses: actions/checkout@v2
    submodules: recursive # this is important not to forget


I have shown you the steps to configure Github Actions to access private repostiories under your control. This also works when you have submodules from private repositories in you main repository. For private repositories not under your control, you might need other solution though.

Quick Drop logo

Profile picture

Personal blog by An Tran. I'm focusing on creating useful apps.
#Swift #Kotlin #Mobile #MachineLearning #Minimalist

© An Tran - 2024