githubsshcopygithub-actions

Github Actions - copy files to VPS


I would like to solve this at a small VPS Provider:

Github worflow, when pushed files to GitHub, then "GH workflows" copies the php files to the live VPS server.

How can I copy them?

.github/workflows/vps-deploy-prod.yml:

name: vps-deploy-prod

on:
  push:
    branches:
      - master

jobs:

  build: 'VPS Run Deploy'
  runs-on: ubuntu-latest    
  steps:
    - name: 'Checkout'
      uses: action/checkout@master
    - name: 'Deploy'
      run: make vps-run-deploy

The Makefile:

##### VPS specific target
vps-run-deploy:

?? copy files via ssh scp...?

Solution

  • You might consider the GitHub action appleboy/scp-action

    GitHub Action for copying files and artifacts via SSH.

    Here is an example in this project: renatomh/gobarber-backend/.github/workflows/main.yml:

          # Copy the repository to the directory on the server/VPS used for the application
          - name: Copy dist to VPS
            uses: appleboy/scp-action@master
            with:
              host: ${{ secrets.SSH_HOST }}
              username: ${{ secrets.SSH_USER }}
              port: ${{ secrets.SSH_PORT }}
              key: ${{ secrets.SSH_KEY }}
              # Selecting all folders except "node_modules"
              source: ".,!node_modules"
              # The path is based on the directory where the user logged into the server starts
              target: "~/app/gobarber-backend"