Skip to content

Instantly share code, notes, and snippets.

@zellwk
Created August 2, 2023 03:58
Show Gist options
  • Save zellwk/c621f73a3c75ac964f56f0c811d7ec80 to your computer and use it in GitHub Desktop.
Save zellwk/c621f73a3c75ac964f56f0c811d7ec80 to your computer and use it in GitHub Desktop.
Github Actions
# See https://zellwk.com/blog/github-actions-deploy/ an explanation of this code
name: deploy
on:
push:
branches:
- main
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- run: npm install
- run: npm run build
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: unnecessary
- name: Adding Known Hosts
run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Deploy with rsync
run: rsync -avz -e "ssh -p ${{ secrets.SSH_PORT }}" ./dist/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/var/www/students.asyncjs.today/dist/
- name: Restart Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd /PATH_TO_FOLDER
git fetch origin master
git reset --hard FETCH_HEAD
git clean -d -f --exclude secrets
npm install --production
npm run restart
@karabomaila
Copy link

I don’t understand you, what do you mean?

@sainikbiswas
Copy link

Hi @zellwk Thanks for sharing this. Your blog post https://zellwk.com/blog/github-actions-deploy/ was very helpful and it helped me setup the workflow the way I wanted it. I had to tweak my configuration a little bit to get it working but it was worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment