Auto-Deploy on Merge
Deploy your application automatically when code is merged to main.
Deploy to a VPS
yaml
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install and build
run: |
npm ci
npm run build
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/my-app
git pull origin main
npm ci --production
npm run build
pm2 restart my-appSecrets
Never hardcode credentials. Go to Settings → Secrets → Actions in your repo:
- SERVER_HOST — your server IP
- SERVER_USER — SSH username
- SSH_PRIVATE_KEY — your private key
Use them in workflows with ${{ secrets.NAME }}.
Environment protection
For production deploys, require manual approval:
yaml
jobs:
deploy:
runs-on: ubuntu-latest
environment: production # Requires approvalConfigure in Settings → Environments → production → Add reviewers.
Status badges
Add a badge to your README:
markdown
