CI/CD Pipeline Kurulumu: GitHub Actions ile Otomatik Deploy

z

zafer ak

Yazar

08 December 2025 2 dakika okuma 2 görüntülenme
CI/CD Pipeline Kurulumu: GitHub Actions ile Otomatik Deploy
GitHub Actions kullanarak CI/CD pipeline oluşturma. Test, build ve deploy süreçlerini otomatikleştirme rehberi.

CI/CD Nedir?

Continuous Integration (CI): Kod değişikliklerinin sürekli test edilmesi.

Continuous Deployment (CD): Başarılı testlerden sonra otomatik deploy.

GitHub Actions Temelleri

Workflow Yapısı

name: CI/CD Pipeline

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
      - name: Install dependencies
        run: composer install
      - name: Run tests
        run: php artisan test

Laravel CI Pipeline

name: Laravel CI

on: [push, pull_request]

jobs:
  laravel-tests:
    runs-on: ubuntu-latest

    services:
      mysql:
        image: mysql:8.0
        env:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: testing
        ports:
          - 3306:3306
        options: >-
          --health-cmd="mysqladmin ping"
          --health-interval=10s
          --health-timeout=5s
          --health-retries=3

    steps:
    - uses: actions/checkout@v4

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.3'
        extensions: mbstring, xml, ctype, json, mysql
        coverage: xdebug

    - name: Copy .env
      run: cp .env.example .env

    - name: Install Dependencies
      run: composer install -q --no-ansi --no-interaction

    - name: Generate key
      run: php artisan key:generate

    - name: Run Migrations
      run: php artisan migrate
      env:
        DB_CONNECTION: mysql
        DB_HOST: 127.0.0.1
        DB_PORT: 3306
        DB_DATABASE: testing
        DB_USERNAME: root
        DB_PASSWORD: password

    - name: Execute tests
      run: php artisan test --coverage

Otomatik Deploy

  deploy:
    needs: laravel-tests
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'

    steps:
    - name: Deploy to server
      uses: appleboy/ssh-action@master
      with:
        host: ${{ secrets.SERVER_HOST }}
        username: ${{ secrets.SERVER_USER }}
        key: ${{ secrets.SSH_PRIVATE_KEY }}
        script: |
          cd /var/www/myapp
          git pull origin main
          composer install --no-dev
          php artisan migrate --force
          php artisan config:cache
          php artisan route:cache
          php artisan view:cache

Secrets Yönetimi

Repository → Settings → Secrets and variables → Actions

  • SERVER_HOST
  • SERVER_USER
  • SSH_PRIVATE_KEY
  • DEPLOY_PATH

Paralel Jobs

jobs:
  test-php:
    runs-on: ubuntu-latest
    # PHP testleri

  test-js:
    runs-on: ubuntu-latest
    # JavaScript testleri

  deploy:
    needs: [test-php, test-js]
    # Her iki test başarılı olunca deploy

Sonuç

CI/CD pipeline, modern yazılım geliştirmenin temelidir. GitHub Actions ile ücretsiz ve güçlü pipeline'lar oluşturabilirsiniz.

İlgili Yazılar