CI/CD with GitHub Actions
CI/CD automates testing and deployment. Every push triggers tests; successful merges to main automatically deploy. GitHub Actions is the most widely used platform for PHP and Python projects.
# .github/workflows/ci.yml
name: CI Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: test_db
MYSQL_ROOT_PASSWORD: root
ports: [ "3306:3306" ]
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: pdo, pdo_mysql
- run: composer install --no-progress
- run: vendor/bin/phpunit --coverage-text
env:
DB_HOST: 127.0.0.1
DB_DATABASE: test_db
DB_PASSWORD: root
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy to Production
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_HOST }}
username: ${{ secrets.PROD_USER }}
key: ${{ secrets.PROD_SSH_KEY }}
script: |
cd /var/www/ezycoders
git pull origin main
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan cache:clear
Q: CI vs CD?
CI (Continuous Integration): auto build and test on every push — catches bugs early. CD (Continuous Delivery): auto deploy to staging after CI passes — humans approve production. CD (Continuous Deployment): fully automated to production. Most teams: CI + CD to staging, manual production gate.
Comments (0)
No comments yet. Be the first!
Leave a Comment