How can a Github workflow read a file on another private repository hosted on the same GitHub account?

I have a private git repository like:

Github.com/acct/repo1

I have a test.json file in another private repository in the same GitHub subscription and account like:

Github.com/acct/repo2/test.json

How can a workflow in repo1 have http get access to the url Github.com/acct/repo2/test.json ?

All I need is a simple way to read the content of test.json in a workflow running on repo2 .

It works the best for me to read the file using a curl get request.

You can use a Personal Access Token (PAT) with the repo scope to authorize the request to the raw.githubusercontent.com URL for the file. If you add the PAT as a secret for your repository, you can do something like this:

- name: get file
  env:
    TOKEN: ${{ secrets.repo_token }}
  run: |
    curl -H "Authorization: token ${TOKEN}" https://raw.githubusercontent.com/acct/repo2/main/test.json

Thank you so much for help.

Any suggestion for learning path where do I learn details like this?

1 Like

You’re welcome! :smiley_cat:

Nothing too specific, I’m afraid. The key here is knowing that PATs can be used to authorize all sorts of things. I then just checked the documentation on scopes to see which would be needed, and tried downloading a file from a private repository to make sure it’d actually work. I picked up most of the general concepts by poking around the documentation and reading here on the forum. :wink:

1 Like