Dhamo
Dhamo

Reputation: 1251

Checkout a specific branch - Not Found error in github actions

My scenario: I am in a repo1 (that is where I have this workflow file) and trying to pull repo 2 (both are in the same organization) from repo 1 with the following code:

- name: Checkout aaa-frontend repo
  uses: actions/checkout@v2
  with:
    repository: Orgn1-Global/aaa-frontend
    path: develop
    token: ${{ github.token }} 

From the below error, I assume that, it is able to locate the repository but only has a problem in locating the branch. Is this correct?

Run actions/checkout@v2
Syncing repository: Orgn1-Global/aaa-frontend
Getting Git version info
Initializing the repository
Disabling automatic garbage collection
Setting up auth
Determining the default branch
  Retrieving the default branch name
  Not Found
  Waiting 17 seconds before trying again
  Retrieving the default branch name
  Not Found
  Waiting 12 seconds before trying again
  Retrieving the default branch name
  Error: Not Found

and what's the right way to pull the 'main' branch of repo 2 from this repo 1?

Upvotes: 0

Views: 8823

Answers (3)

Dove
Dove

Reputation: 173

As it is an issue with the permissions, I'm adding the option how to resolve it with the help of GitHub app. (Could be resolved also with PAM, but GitHub app is more convenient as it is not personal account dependent). Tested with checkout of private repo in the organization.

Steps:

  1. Under your organization create GitHub app with permission to read content (Repository -> Contents -> Read-only)

  2. Install app and select the repository you want to checkout from (or use it for all repositories in your org)

  3. Generate private key (in General in your GitHub app) and store it as a secret (for example with name PRIVATE_KEY) into your calling repository (the one with checkout in the workflow)

  4. Store App ID (in General in your GitHub app) as a variable (for example with name APP_ID) into your calling repository (the one with checkout in the workflow)

  5. Use actions/create-github-app-token before checkout to create a token (which will give you the permissions) like:

    - uses: actions/create-github-app-token@v1
      id: create-token
      with:
        app-id: ${{ vars.APP_ID }}
        private-key: ${{ secrets.PRIVATE_KEY }}
        owner: ${{ github.repository_owner }}
        repositories: aaa-frontend
    
  6. Add generated token into the checkout actions. Like:

    - uses: actions/checkout@v4
      with:
        repository: Orgn1-Global/aaa-frontend
        path: develop
        token: ${{ steps.create-token.outputs.token }}
    

Great YouTube resource how to create GitHub app and use it: Working with GitHub Apps instead of a PAT

Other useful resources:

Upvotes: 1

Samit Kumar Patel
Samit Kumar Patel

Reputation: 2098

If I understand your requirement correctly, do you want to checkout repo1 and repo2 in the repo1 action workflow ?

If Yes - It has to be like this:

# checkout of repo1 - where you have your workflow file
- name: Checkout
  uses: actions/checkout@v2
  with:
    path: main
# checkout repo2 in a folder called my-tools
- name: Checkout tools repo
  uses: actions/checkout@v2
  with:
    repository: my-org/repo2
    path: my-tools

you can always find an awesome examples in Github action public repository. Here is the checkout one.

Upvotes: 1

Sam-Sundar
Sam-Sundar

Reputation: 747

Below piece of code should fetch you main branch of aaa-frontend repo

- name: Checkout aaa-frontend repo
  uses: actions/checkout@v2
  with:
    repository: Orgn1-Global/aaa-frontend
    path: develop
    token: ${{ github.token }} 
    ref: main

Upvotes: 1

Related Questions