GitHub Actions memungkinkan kamu otomasi build, test, dan deploy setiap kali push kode. Gratis untuk public repo!
Basic Workflow
Buat file .github/workflows/ci.yml:
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run lint
- run: npm run build
- run: npm test
Auto Deploy ke VPS
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VPS_HOST }}
username: root
key: ${{ secrets.SSH_KEY }}
script: |
cd /root/myapp
git pull
docker compose up -d --build
Tips
- Simpan secrets di GitHub Settings > Secrets
- Gunakan caching untuk mempercepat build
- Jalankan linter dan tests sebelum deploy
- Notifikasi ke Slack/Discord saat deploy berhasil/gagal
Dengan CI/CD, kamu bisa deploy dengan confident setiap saat.