JustPaste
JustPaste
Tools & Software 20 Januari 2026 1 menit baca 1.935 views Regi Pratama

GitHub Actions: CI/CD Pipeline untuk Project Laravel

Continuous Integration dan Continuous Deployment (CI/CD) tidak lagi eksklusif untuk tim besar. GitHub Actions membuatnya accessible untuk semua.

Apa itu CI/CD?

  • CI (Continuous Integration): Otomasi run test setiap kali push kode

  • CD (Continuous Deployment): Otomasi deploy ke server setelah test pass

Membuat Workflow File

# .github/workflows/laravel.yml
name: Laravel CI

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

jobs: test: runs-on: ubuntu-latest

services: mysql: image: mysql:8.0 env: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: testing options: --health-cmd="mysqladmin ping" --health-retries=3

steps: - uses: actions/checkout@v4

- name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.3' extensions: mbstring, pdo_mysql, redis

- name: Install Dependencies run: composer install --prefer-dist --no-progress

- name: Setup .env run: | cp .env.testing .env php artisan key:generate

- name: Run Tests run: php artisan test --parallel

Deployment Step

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

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

Bagikan artikel ini: