DevOps untuk Developer: CI/CD Pipeline dengan GitHub Actions
Continuous Integration dan Continuous Deployment (CI/CD) adalah praktik essential untuk developer modern. GitHub Actions membuatnya mudah dan gratis untuk project open source.
Apa itu CI/CD?
- CI (Continuous Integration): Otomatis build dan test setiap kali ada push/PR
- CD (Continuous Deployment): Otomatis deploy ke production setelah test pass
Pipeline 1: Next.js Project
# .github/workflows/nextjs-ci.yml
name: Next.js CI/CD
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
build-and-test:
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 dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Build
run: npm run build
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: Run tests
run: npm test --if-present
deploy:
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-args: '--prod'
Pipeline 2: Laravel Project
# .github/workflows/laravel-ci.yml
name: Laravel CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: testing
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: pdo_pgsql
- name: Install Composer Dependencies
run: composer install --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate --env=testing
- name: Run migrations
run: php artisan migrate --env=testing
env:
DB_CONNECTION: pgsql
DB_HOST: localhost
DB_PORT: 5432
DB_DATABASE: testing
DB_USERNAME: postgres
DB_PASSWORD: postgres
- name: Run tests
run: php artisan test
env:
DB_CONNECTION: pgsql
DB_HOST: localhost
Best Practices
- Branch protection — Wajib PR dan review sebelum merge ke main
- Environment secrets — Simpan credentials di GitHub Secrets
- Cache dependencies — Percepat build dengan caching
- Parallel jobs — Jalankan test secara parallel
- Status badges — Tampilkan build status di repository
Kesimpulan
GitHub Actions membuat CI/CD accessible untuk semua developer. Mulai dari project kecil hingga enterprise, otomatisasi build-test-deploy akan meningkatkan kualitas dan kecepatan delivery Anda.