yalegria / devops-git-actions

0 stars 0 forks source link

How to Copy Files to a Remote Server Via SSH #11

Open Voxelghiest opened 3 years ago

Voxelghiest commented 3 years ago

To copy files from a repo to a private server, I used a Copy Via SSH action that someone else has made. In order to use it, you add it as a step in your workflow, as explained on the action's page.

Voxelghiest commented 3 years ago

Add the following sample action under workflows folder.

Here's a sample action you could use to understand how the copying works. Make sure your secrets are correctly set up before running it.

name: Transfer Via SSH
on:
  push:
    branches:
      - main
jobs:
  sendFiles:
    name: Transfer Files
    runs-on: ubuntu-latest
    env:
      LOCAL_DIRECTORY: ./
      REMOTE_DIRECTORY: ~/
    steps:
      - name: Checkout Project
        uses: actions/checkout@v2
      - name: Send Files
        uses: garygrossgarten/github-action-scp@release
        with:
          local: ${{ env.LOCAL_DIRECTORY }}
          remote: ${{ env.REMOTE_DIRECTORY }}
          host: ${{ secrets.HOST }}
          username: ${{ secrets.SSH_USER }}
          password: ${{ secrets.SSH_PASS }}