Dragos Stoica
Dragos Stoica

Reputation: 1935

Github Actions remote repo issues

I am using Github and I need to implement a feature using Github Actions as per below:

I have two repos - one private and one public. Whenever a pull request is created for 'master' branch on the public reposity we need to push the source branch (altogether) into the private repository.

My workflow file looks like below:

  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      # Runs a set of commands using the runners shell
      - name: Run a multi-line script
        env:
         INTERVIEW_TOKEN: ${{ secrets.INTERVIEW_TOKEN }}
        run: |
          echo ${{github.head_ref}}
          git remote -v 
          git fetch
          git checkout ${{github.head_ref}}
          git remote add private-origin https://stoicad:[email protected]/stoicad/interview-private.git
          git remote -v 
          git push -u private-origin ${{github.head_ref}}

It should be pretty straightforward:

The actual result:

PR_TEST_BRANCH
origin  https://github.com/stoicad/interview (fetch)
origin  https://github.com/stoicad/interview (push)
From https://github.com/stoicad/interview
 * [new branch]      PR_TEST_BRANCH -> origin/PR_TEST_BRANCH
 * [new branch]      master         -> origin/master
Previous HEAD position was 7607d53 Merge e1fa33b54d0611dd0b5c5ccfe86d9d00442cdcbb into f882b0a96f557dfe1614fb79920799167b1963a7
Switched to a new branch 'PR_TEST_BRANCH'
Branch 'PR_TEST_BRANCH' set up to track remote branch 'PR_TEST_BRANCH' from 'origin'.
origin  https://github.com/stoicad/interview (fetch)
origin  https://github.com/stoicad/interview (push)
private-origin  ***github.com/stoicad/interview-private.git (fetch)
private-origin  ***github.com/stoicad/interview-private.git (push)
remote: Repository not found.
fatal: repository 'https://github.com/stoicad/interview-private.git/' not found
Error: Process completed with exit code 128.

Am I missing something? Both repositories were created by myself, the generated token has for sure all the rights, what else can be? Why it throws an error saying "Repository not found"?

Upvotes: 1

Views: 5270

Answers (2)

Dragos Stoica
Dragos Stoica

Reputation: 1935

Ended up with the following solution based on Sam-Sundar answer:

  1. Generate ssh key using: ssh-keygen -t ed25519 -a 100 (when you're asked for a passphrase just hit enter)
  2. Register public key on Github private repository (interview.git) under

Settings > Deploy Keys > Add Deploy Key

  1. Store private key on Github public repository (interview-private.git) under

Settings > Secrets > New Repository Secret (I called it INTERVIEW_TOKEN)

  1. Update workflow file with:

    enter image description here

Sorry for posting an image, but the code formatting from stackoverflow it's not working with those git commands.

Upvotes: 5

Sam-Sundar
Sam-Sundar

Reputation: 747

You can add this action after your checkout step and then you can push to your private repo.

Note:- Please replace your private repo URL from https+auth_token to SSH. Eg: git remote add ssh://[email protected]/your_group/your_project.git

Upvotes: 1

Related Questions