Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/DevOps & cloud

CI/CD Pipelines with GitHub Actions: Automate Everything

Build production-grade CI/CD pipelines — run tests, lint code, build Docker images, and deploy automatically on every push.

22 February 20261 min readDevOps & cloudاقرأ بالعربية

On this page

  1. Complete Laravel CI Pipeline
  2. Deploy on Merge

GitHub Actions is the most popular CI/CD platform for open-source projects. It runs workflows triggered by events like pushes and pull requests — directly inside your GitHub repository.

Complete Laravel CI Pipeline

yaml
name: CI

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

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:8.0
        env:
          MYSQL_ROOT_PASSWORD: secret
          MYSQL_DATABASE: testing
        ports:
          - 3306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s

    steps:
      - uses: actions/checkout@v4

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

      - name: Cache Composer
        uses: actions/cache@v4
        with:
          path: vendor
          key: composer-${{ hashFiles('composer.lock') }}

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

      - name: Copy Environment
        run: cp .env.example .env && php artisan key:generate

      - name: Run Tests
        env:
          DB_HOST: 127.0.0.1
          DB_DATABASE: testing
          DB_PASSWORD: secret
        run: php artisan test --coverage --min=80

Deploy on Merge

yaml
  deploy:
    needs: test
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to Production
        uses: appleboy/ssh-action@v1
        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 queue:restart

Combine with GitHub branch protection rules to enforce quality gates without slowing down developers.

All articles

Keep reading

  • Docker for Developers: From Zero to Containerized Applications28 February 20261 min read
  • Clean Code Principles: Write Code That Humans Can Read22 February 20261 min read
  • Database Migration Strategies for Zero-Downtime Deployments22 February 20261 min read