Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning private github repository within organisation in actions

Tags:

I have 2 private GitHub repositories (say A and B) in the organization (say ORG). Repository A has repository B in requirements.txt:

-e [email protected]:ORG/B.git#egg=B 

And I have the following workflow for A (in .github/workflows/test.yml):

name: Python package  on: push  jobs:   build:      runs-on: ubuntu-latest      steps:     - uses: actions/checkout@v1      - name: Install requirements       run: |         pip install -r requirements.txt      - name: Test with pytest       run: |         pytest ./tests 

As B is private, it fails on installing it.

Is it possible to install B while testing A in this workflow if they are in the same organization? How?

like image 564
Yevhen Kuzmovych Avatar asked Aug 22 '19 15:08

Yevhen Kuzmovych


People also ask

Can you clone a private GitHub repo?

You also have the option to clone a private GitHub repository using SSH. To do this, you need to start by generating an SSH keypair on your local device. Then add a public key to your GitHub account. This gives you the ability to connect your local device with GibHub using a secure channel over an unsecured network.

Is GitHub actions free for private repositories?

GitHub Actions usage is free for standard GitHub-hosted runners in public repositories, and for self-hosted runners. For private repositories, each GitHub account receives a certain amount of free minutes and storage for use with GitHub-hosted runners, depending on the product used with the account.


2 Answers

I did this way!

- uses: actions/checkout@v1     with:     repository: organization_name/repo_name     token: ${{ secrets.ACCESS_TOKEN }} 

You need to provide a valid token, you can generate it following this guide

like image 163
Duvan Avatar answered Sep 18 '22 22:09

Duvan


Since access tokens are bound to an account and have write access to all its private repos, it's a very bad solution.

Instead, use deploy keys.

Deploy keys

Deploy keys are simply SSH keys that you can use to clone a repo.

  1. Create a new SSH key pair on your computer
  2. Put the public key in the private dependency repo's Deploy keys
  3. Put the private key in the app repo's Actions secrets
  4. Delete the keys from your computer

secrets

Once it's set, you can set the private key in the GitHub Action's SSH Agent. There's no need to import a third-party GitHub Action, a 2-liner will suffice.

eval `ssh-agent -s` ssh-add - <<< '${{ secrets.PRIVATE_SSH_KEY }}' pip install -r requirements.txt 

I found that ssh-add command here.

like image 37
Nato Boram Avatar answered Sep 20 '22 22:09

Nato Boram