Modül 2 · İş Akışı Orkestrasyonu · ⏱ 6 dk

GitHub Actions ile CI/CD

CI CD with GitHub Actions

Bu derste neler öğreneceksin

  • .github/workflows YAML yazar
  • Test + lint + build step i tanımlar
  • Kestra Git sync ile entegre eder

CI/CD Pipeline: Test Otomasyonu

Manuel olarak pytest çalıştırmak insan hatasına açık. “Bugün test yapmayı unuttum, prod’a bozuk kod gitti.” Bunu önlemenin tek yolu: her push’ta CI zorunlu kılmak. CD ise test geçtiyse otomatik deploy.

GitHub Actions, GitHub’ın yerleşik CI/CD’si. Sıfır altyapı — runner GitHub tarafından sağlanır, kendi makinanda çalışmaz.

Production Workflow

# .github/workflows/ci.yml
name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.11", "3.12"]
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: pip

      - name: Bağımlılıkları kur
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          pip install -r requirements-dev.txt

      - name: Lint (ruff)
        run: ruff check .

      - name: Tip kontrolü (mypy)
        run: mypy src/

      - name: Unit test
        run: pytest tests/ -v --cov=src --cov-report=xml

      - name: Coverage raporu
        if: matrix.python-version == '3.12'
        uses: codecov/codecov-action@v4
        with:
          file: coverage.xml

Bu workflow her push + her PR’da çalışır:

  1. Kodu checkout eder
  2. Python 3.11 + 3.12’de paralel test eder
  3. Lint + tip kontrolü + coverage raporu
  4. Codecov’a coverage yükler

PR geçmeden merge edemezsin (branch protection kuralı).

Kestra Git Sync

Kestra’nın en güçlü production özelliği: flow dosyalarını GitHub’da tutmak. Kestra periyodik pull eder, schedule aktifse yeni sürümle tetikler.

kestra/config.yml:

kestra:
  git:
    url: https://github.com/senin/lemonade-flows.git
    branch: main
    path: flows/
    interval: 60
    username: ${KESTRA_GIT_USERNAME}
    password: ${KESTRA_GIT_PASSWORD}

Repo yapısı:

lemonade-flows/
├── flows/
│   ├── prod/
│   │   ├── nightly_orders.yml
│   │   └── orders_to_bigquery.yml
│   └── staging/
│       └── test_flow.yml
└── README.md

Workflow: VS Code’da flows/prod/nightly_orders.yml’i düzenle → git commit -m "fix: tarih format"git push → CI test geçer → Kestra 60 saniye içinde pull eder → bir sonraki schedule yeni sürümle çalışır.

Bu GitOps deseni — production state’i Git’te tut, audit trail otomatik oluşur, rollback tek komut.

Production’da Ek Güvenlik

# PR'larda gizli bilgi olmasın
- name: Gizli bilgi taraması
  uses: trufflesecurity/trufflehog@main
  with:
    path: ./
    base: ${{ github.event.pull_request.base.sha }}
    head: ${{ github.event.pull_request.head.sha }}

# Branch protection (GitHub UI'dan)
# - main branch requires 1 approval
# - status checks: CI test geçmeden merge yok
# - force push kapalı

Bugün Yaptık

  • GitHub Actions YAML yapısını üretim kalitesinde yazdık
  • Lint + tip kontrolü + coverage raporu pipeline’ı kurduk
  • Kestra Git sync ile GitOps pattern öğrendik

Ellerini Kirlet

  1. Repo köküne .github/workflows/ci.yml ekle, push et.
  2. Actions sekmesinde CI işinin yeşil geçtiğini gör.
  3. Kestra config.yml’e Git sync ekle. İlk push’tan sonra flows/ altındaki dosyalar Kestra UI’da görünmeli.
  4. README’ye “Deployment Flow” diyagramı ekle: developer → git push → CI test → Kestra pull → schedule execution.

Sıradaki

Bir sonraki ders: Pipeline’ı kağıtta yaz — robot egzersizi →