Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 452
factor Avatar asked Apr 19 '26 02:04

factor


2 Answers

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
like image 174
factor Avatar answered Apr 21 '26 17:04

factor


According to the doc you can use env like this

  - name: pass environment
    uses: appleboy/ssh-action@master
    env:
      FOO: "BAR"
      BAR: "FOO"
      SHA: ${{ github.sha }}
    with:
      host: ${{ secrets.HOST }}
      username: ${{ secrets.USERNAME }}
      key: ${{ secrets.KEY }}
      port: ${{ secrets.PORT }}
      envs: FOO,BAR
      script: |
        echo "I am $FOO"
        echo "I am $BAR"
        echo "sha: $SHA"
like image 29
argame.io Avatar answered Apr 21 '26 16:04

argame.io



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!