Search code examples
gitubuntugithubcommand-line-interfacegithub-actions

Automatically pull from remote using GitHub Actions


I have a private repository on GitHub and my goal is that whenever there is a new commit, the repository us updated on the VPS.

What I am currently doing is using an SSH action to log on to the server, locate the repository, and pull from the origin

The issue with this is that the repository is private and requires authentication. I tried settings my username and password in the global git config but even after doing that it still requires authentication.


Solution

  • Figured out the solution on my own. The issue with the various things I was doing was as follows. I was trying to do something along the lines of git pull https://${{ secrets.TOKEN }}@github.com/repo

    The solution was putting the entire command git pull https://[email protected]/repo as a secret and then running the script: ${{ secrets.SCRIPT }} via SSH.

    My action at the end of this:

    name: Remote SSH
    on: [push]
    jobs:
    
      build:
        name: Build
        runs-on: ubuntu-latest
        steps:
        - name: executing remote ssh commands using password
          uses: appleboy/ssh-action@master
          with:
            host: ${{ secrets.IP }}
            username: ${{ secrets.USER }}
            password: ${{ secrets.PRIVATE_KEY }}
            port: ${{ secrets.PORT }}
            script: |
              cd Repository
              ${{ secrets.SCRIPT}}
              pm2 restart 0