Git Workflow: Deploy to Staging with SSH

  1. In your git repository, create a dir called .github.
  2. cd into .github and create a dir called workflows
  3. cd into workflows
  4. create a  file named deploy-to-server.yml (name can be what you want, but should declar what your doing and always end in .yml)
  5. Copy and past the content below:


name: SSH Server Deploy
on:
push:
branches:
- dev
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: SSH Server Deploy
uses: kostya-ten/ssh-server-deploy@v4
with:
host: ${{ secrets.host }}
port: ${{ secrets.port }}
username: ${{ secrets.username }}
private_key: ${{ secrets.private_key }}
scp_source: ${{ secrets.scp_source }}
scp_target: ${{ secrets.scp_target}}

Now ssh into your server and cd to the appropriate host account. Then cd to the .ssh folder.

Create your ssh keypair like so: (credit to: https://zellwk.com/blog/github-actions-deploy/)

ssh-keygen -t rsa -b 4096 -C "your_git_email@example.com"

Name it the same as your .yml name is for easy reference.

No passphrase needed.

Authorize keys.

Add all secrets to the github > respository > settings > secerets > actions area. Lable them the same as yml file (you can name them what you want, but for easy reference keep whatever you name them the same).

Change, commit and push.