GitHub Actions, ücretsiz kota ile başlayan ve public repo''larda sınırsız olan güçlü bir CI/CD platformudur. Her push''ta test çalıştırmak, container build etmek, production''a deploy etmek — hepsi tek YAML dosyasında. Bu rehber sıfırdan bir Node.js projesi için tam CI/CD pipeline kurmayı anlatır.
Temel Workflow Yapısı
İlgili rehberler: Yazılım geliştirme süreçleri · PostgreSQL optimizasyonu · Git ileri seviye komutlar · Redis nedir, nasıl kullanılır · Docker ile deploy
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
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 test
Matrix Strategy
Aynı job''u birden fazla Node sürümü, OS veya ortamda paralel çalıştırmak için.
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci && npm test
Docker Image Build + Registry Push
jobs:
docker:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
Secret Yönetimi
Settings → Secrets and variables → Actions altından secret tanımlayın. Log''larda otomatik maskelenir. Environment-specific secret''lar için environments kullanın (production''a promote için manual approval eklenebilir).
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- run: echo ${{ secrets.DATABASE_URL }}
- uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/app
git pull
npm ci --production
pm2 reload ecosystem.config.js
ed25519 formatında olmalı. Anahtarı GitHub secret''a koyarken BEGIN/END satırları dahil edin, satır sonları bozulmasın.Servis Konteyner (DB ile Test)
jobs:
integration-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: test
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 5
redis:
image: redis:7
ports: ['6379:6379']
env:
DATABASE_URL: postgres://postgres:test@localhost:5432/postgres
REDIS_URL: redis://localhost:6379
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci
- run: npm run migrate
- run: npm run test:integration
Cache Optimizasyonu
- uses: actions/cache@v4
with:
path: |
~/.npm
node_modules
.next/cache
key: ${{ runner.os }}-build-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-build-
Reusable Workflow
# .github/workflows/reusable-deploy.yml
name: Deploy
on:
workflow_call:
inputs:
env: { required: true, type: string }
secrets:
SSH_KEY: { required: true }
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- run: echo Deploying to ${{ inputs.env }}
# Ana workflow'tan çağır
jobs:
prod:
uses: ./.github/workflows/reusable-deploy.yml
with: { env: production }
secrets: inherit
Workflow Dispatch (Manuel Tetikleme)
on:
workflow_dispatch:
inputs:
environment:
type: choice
options: [staging, production]
version:
type: string
default: latest
Self-Hosted Runner
Ücretsiz GitHub-hosted runner''lar kısıtlı (public 2000 dk/ay, private planlara göre). Ağır iş için kendi sunucunuzda runner çalıştırabilirsiniz — Settings → Actions → Runners → New self-hosted runner.
Yaygın Hatalar
GITHUB_TOKENpermission''ları default kısıtlı — gerekirse workflow''apermissions:ekle- Concurrent runs aynı environment''a deploy''u çakıştırır —
concurrency:ile kontrol et actions/checkout@v4default 1 commit çeker — full history gerekliysefetch-depth: 0- Dependency install''de
npm installyerinenpm cikullan — lockfile''ı kesin uygular
Modern Yazılım Geliştirme ve DevOps Pratikleri
Profesyonel yazılım geliştirme süreci üç pillar üzerine kuruludur: kaynak kontrolü (Git + GitHub/GitLab pull request akışı, code review zorunlu), CI/CD pipeline (otomatik test + lint + build + deploy), ve gözlemlenebilirlik (Sentry/Datadog/Grafana ile log, metric, trace toplama). Test piramidi (unit > integration > e2e) ile kod kalitesini garantilemek, mikroservis mimarisinde Docker container ve Kubernetes orkestrasyonu kullanmak, REST veya GraphQL API tasarımında OpenAPI/GraphQL Schema sözleşmesi tutmak modern standardlardır. Yazılım geliştirme yaşam döngüsü boyunca (gereksinim → tasarım → implementasyon → test → deploy → bakım) Agile/Scrum sprintleri 1-2 hafta, DevOps takımları sürekli teslim (continuous delivery) prensibiyle çalışır.
GitHub Actions, GitLab CI veya Jenkins pipeline tasarımı için bize yazın