|
| 1 | +# This is a Semaphore configuration file for Laravel projects using Docker |
| 2 | +# For more information about Semaphore configuration visit: |
| 3 | +# https://docs.semaphoreci.com/reference/pipeline-yaml-reference/ |
| 4 | + |
| 5 | +version: v1.0 # Semaphore configuration version |
| 6 | +name: "🚀 Laravel CI Pipeline" # Pipeline display name |
| 7 | + |
| 8 | +# Define the machine type, OS image, and containers |
| 9 | +agent: |
| 10 | + machine: |
| 11 | + type: {{ machine_type }} |
| 12 | + os_image: {{ os_image }} |
| 13 | + |
| 14 | + containers: |
| 15 | + - name: main |
| 16 | + image: 'registry.semaphoreci.com/php:8.3-apache' # PHP 8.3 with Apache |
| 17 | + - name: postgres |
| 18 | + image: 'registry.semaphoreci.com/postgres:17' # PostgreSQL 17 for database operations |
| 19 | + - name: redis |
| 20 | + image: 'registry.semaphoreci.com/redis:7.0' # Redis 7.0 for caching |
| 21 | + |
| 22 | +# Configure when to stop the pipeline early |
| 23 | +fail_fast: |
| 24 | + stop: |
| 25 | + when: branch != 'main' # Stop all blocks if a job fails on non-main branches |
| 26 | +auto_cancel: |
| 27 | + running: |
| 28 | + when: branch != 'main' # Cancel running pipelines on non-main branches |
| 29 | + queued: |
| 30 | + when: branch = 'main' # Cancel queued pipelines on main branch |
| 31 | + |
| 32 | +# Commands to run before each job |
| 33 | +global_job_config: |
| 34 | + prologue: |
| 35 | + commands: |
| 36 | + - checkout # Get the code from repository |
| 37 | + - cache restore # Restore cached dependencies |
| 38 | + - composer install # Install PHP dependencies |
| 39 | + - npm ci # Install Node.js dependencies |
| 40 | + |
| 41 | +# Pipeline blocks represent groups of jobs that can run in parallel |
| 42 | +blocks: |
| 43 | + # Block for setting up dependencies and caching |
| 44 | + - name: "🛠 Setup and Cache" |
| 45 | + dependencies: [] |
| 46 | + task: |
| 47 | + jobs: |
| 48 | + - name: Install Dependencies |
| 49 | + commands: |
| 50 | + - cache store # Cache dependencies for future runs |
| 51 | + |
| 52 | + # Block for asset compilation |
| 53 | + - name: "🎨 Assets" |
| 54 | + dependencies: ["🛠 Setup and Cache"] |
| 55 | + task: |
| 56 | + jobs: |
| 57 | + - name: Compile Assets |
| 58 | + commands: |
| 59 | + - npm run build # Build frontend assets |
| 60 | + |
| 61 | + # Block for code quality checks |
| 62 | + - name: "🔍 Code Quality" |
| 63 | + dependencies: ["🛠 Setup and Cache"] |
| 64 | + task: |
| 65 | + jobs: |
| 66 | + - name: Lint and Format |
| 67 | + commands: |
| 68 | + - ./vendor/bin/pint --test # Check code style |
| 69 | + - ./vendor/bin/phpstan analyze # Static analysis |
| 70 | + - npm run lint # Check JavaScript code |
| 71 | + |
| 72 | + # Block for security checks |
| 73 | + - name: "🔐 Security Checks" |
| 74 | + dependencies: ["🛠 Setup and Cache"] |
| 75 | + task: |
| 76 | + jobs: |
| 77 | + - name: Security Scan |
| 78 | + commands: |
| 79 | + - composer audit # Check PHP dependencies |
| 80 | + - npm audit # Check Node.js dependencies |
| 81 | + |
| 82 | + # Block for running tests |
| 83 | + - name: "🧪 Test Suite" |
| 84 | + dependencies: ["🛠 Setup and Cache"] |
| 85 | + task: |
| 86 | + env_vars: |
| 87 | + - name: APP_ENV |
| 88 | + value: testing |
| 89 | + - name: DB_CONNECTION |
| 90 | + value: pgsql |
| 91 | + - name: DB_HOST |
| 92 | + value: postgres # PostgreSQL container name |
| 93 | + - name: REDIS_HOST |
| 94 | + value: redis # Redis container name |
| 95 | + jobs: |
| 96 | + - name: "🟢 PHPUnit Tests" |
| 97 | + parallelism: 4 # Run tests in parallel |
| 98 | + commands: |
| 99 | + - php artisan test --parallel --coverage-clover=report.xml # Run tests with coverage and generate JUnit report |
| 100 | + epilogue: |
| 101 | + always: |
| 102 | + commands: |
| 103 | + - '[[ -f report.xml ]] && test-results publish report.xml' # Publish test results if available |
| 104 | + |
| 105 | + # Block for browser tests |
| 106 | + - name: "🌐 Browser Tests" |
| 107 | + dependencies: ["🧪 Test Suite"] |
| 108 | + task: |
| 109 | + jobs: |
| 110 | + - name: Dusk Tests |
| 111 | + commands: |
| 112 | + - php artisan dusk:chrome-driver # Install Chrome driver |
| 113 | + - php artisan serve & sleep 5 # Start test server |
| 114 | + - php artisan dusk # Run browser tests |
| 115 | + |
| 116 | +after_pipeline: |
| 117 | + task: |
| 118 | + jobs: |
| 119 | + - name: "Merge Reports 📊" |
| 120 | + commands: |
| 121 | + - test-results gen-pipeline-report # Generate a summary of the test results |
0 commit comments