webfactory / ssh-agent

GitHub Action to setup `ssh-agent` with a private key
MIT License
1.23k stars 256 forks source link

fatal: Could not read from remote repository #23

Closed multimeric closed 4 years ago

multimeric commented 4 years ago

This might be obvious, but I'm having a lot of trouble using an SSH key (a deploy key) using this action. I have the following workflow (fragment):

      - uses: webfactory/ssh-agent@v0.2.0
        with:
          ssh-private-key: ${{ secrets.DeployKey }}

      - name: Checkout the other repository
        run: |
          git clone git@github.com:Org/RepoName.git

However that gives me:

Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I know the deploy key works, and I also know it's correctly inserted as a secret. Any idea why this might be happening?

multimeric commented 4 years ago

Ah, seems that this is orthogonal to this particular action. It can be solved by using actions/checkout to clone and ad-m/github-push-action to push, e.g.

      - uses: webfactory/ssh-agent@v0.2.0
        with:
          ssh-private-key: ${{ secrets.DeployKey }}

      - uses: actions/checkout@v2
        name: Checkout the other repo
        with:
          path: SomeRepo
          ref: master
          repository: 'org/SomeRepo'

      - name: Commit files
        run: |
          cd SomeRepo
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add -A
          git commit -m "Update"

      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          directory: SomeRepo
          github_token: ${{ secrets.GITHUB_TOKEN }}