From 5c1c86bb737e4e76a4733447071ee807a6719d1c Mon Sep 17 00:00:00 2001 From: Mubbasher Ahmed Qureshi Date: Fri, 18 Jul 2025 16:21:20 +0500 Subject: [PATCH 1/7] ci(updated ci action): added linter, code analysis, unit tests --- .github/workflows/ci.yml | 149 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4131776..22a6de0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,3 +29,152 @@ jobs: run: | # Validate all commits in the PR npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose + + lint: + runs-on: ubuntu-latest + needs: validate-commits + if: always() && (needs.validate-commits.result == 'success' || needs.validate-commits.result == 'skipped') + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv + coverage: none + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install Composer dependencies + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader + + - name: Run Laravel Pint + uses: aglipanci/laravel-pint-action@2.4 + with: + preset: laravel + verboseMode: true + + analyze: + runs-on: ubuntu-latest + needs: lint + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv + coverage: none + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install Composer dependencies + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader + + - name: Copy environment file + run: cp .env.example .env + + - name: Generate application key + run: php artisan key:generate + + - name: Run Larastan (PHPStan) + run: ./vendor/bin/phpstan analyse --memory-limit=2G --error-format=github + + test: + runs-on: ubuntu-latest + needs: analyze + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: laravel_blog_test + MYSQL_USER: laravel_user + MYSQL_PASSWORD: laravel_password + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + redis: + image: redis:7-alpine + ports: + - 6379:6379 + options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv + coverage: xdebug + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install Composer dependencies + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader + + - name: Copy environment file + run: cp .env.example .env + + - name: Generate application key + run: php artisan key:generate + + - name: Set testing environment variables + run: | + echo "APP_ENV=testing" >> .env + echo "DB_CONNECTION=mysql" >> .env + echo "DB_HOST=127.0.0.1" >> .env + echo "DB_PORT=3306" >> .env + echo "DB_DATABASE=laravel_blog_test" >> .env + echo "DB_USERNAME=laravel_user" >> .env + echo "DB_PASSWORD=laravel_password" >> .env + echo "CACHE_STORE=array" >> .env + echo "SESSION_DRIVER=array" >> .env + echo "QUEUE_CONNECTION=sync" >> .env + + - name: Wait for MySQL to be ready + run: | + for i in {1..30}; do + if mysqladmin ping -h 127.0.0.1 -u laravel_user -plaravel_password --silent; then + echo "MySQL is ready" + break + fi + echo "Waiting for MySQL... ($i/30)" + sleep 2 + done + + - name: Run database migrations + run: php artisan migrate:fresh --seed --env=testing --force + + - name: Run tests with Pest (parallel) + run: php artisan test --parallel --recreate-databases --stop-on-failure From 5bad5d193c352f820ce89c8a5a0438dfcdeba481 Mon Sep 17 00:00:00 2001 From: Mubbasher Ahmed Qureshi Date: Fri, 18 Jul 2025 16:26:39 +0500 Subject: [PATCH 2/7] ci: fixed env file name --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22a6de0..55ce861 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,7 +90,7 @@ jobs: run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader - name: Copy environment file - run: cp .env.example .env + run: cp .env.docker.example .env - name: Generate application key run: php artisan key:generate @@ -144,7 +144,7 @@ jobs: run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader - name: Copy environment file - run: cp .env.example .env + run: cp .env.docker.example .env - name: Generate application key run: php artisan key:generate From 171476f1a4156ea49802f9aaf0a751bbb7bd41e1 Mon Sep 17 00:00:00 2001 From: Mubbasher Ahmed Qureshi Date: Fri, 18 Jul 2025 16:43:56 +0500 Subject: [PATCH 3/7] ci: fix mysql host for testing --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55ce861..4fcdd3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,7 +153,7 @@ jobs: run: | echo "APP_ENV=testing" >> .env echo "DB_CONNECTION=mysql" >> .env - echo "DB_HOST=127.0.0.1" >> .env + echo "DB_HOST=mysql" >> .env echo "DB_PORT=3306" >> .env echo "DB_DATABASE=laravel_blog_test" >> .env echo "DB_USERNAME=laravel_user" >> .env @@ -165,7 +165,7 @@ jobs: - name: Wait for MySQL to be ready run: | for i in {1..30}; do - if mysqladmin ping -h 127.0.0.1 -u laravel_user -plaravel_password --silent; then + if mysqladmin ping -h mysql -u laravel_user -plaravel_password --silent; then echo "MySQL is ready" break fi From 7aa1910a9200def0c2badbeefc378d4acf4b2063 Mon Sep 17 00:00:00 2001 From: Mubbasher Ahmed Qureshi Date: Fri, 18 Jul 2025 16:53:21 +0500 Subject: [PATCH 4/7] ci: fix mysql issue --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fcdd3c..0ce81bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,7 +153,7 @@ jobs: run: | echo "APP_ENV=testing" >> .env echo "DB_CONNECTION=mysql" >> .env - echo "DB_HOST=mysql" >> .env + echo "DB_HOST=127.0.0.1" >> .env echo "DB_PORT=3306" >> .env echo "DB_DATABASE=laravel_blog_test" >> .env echo "DB_USERNAME=laravel_user" >> .env @@ -165,7 +165,7 @@ jobs: - name: Wait for MySQL to be ready run: | for i in {1..30}; do - if mysqladmin ping -h mysql -u laravel_user -plaravel_password --silent; then + if mysqladmin ping -h 127.0.0.1 -u laravel_user -plaravel_password --silent; then echo "MySQL is ready" break fi @@ -177,4 +177,4 @@ jobs: run: php artisan migrate:fresh --seed --env=testing --force - name: Run tests with Pest (parallel) - run: php artisan test --parallel --recreate-databases --stop-on-failure + run: php artisan test --parallel --stop-on-failure From d326e6760aa8cfca939d6e885d17c914dad3e64f Mon Sep 17 00:00:00 2001 From: Mubbasher Ahmed Qureshi Date: Fri, 18 Jul 2025 16:56:35 +0500 Subject: [PATCH 5/7] ci: remove parallel testing --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ce81bf..780b112 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -176,5 +176,5 @@ jobs: - name: Run database migrations run: php artisan migrate:fresh --seed --env=testing --force - - name: Run tests with Pest (parallel) - run: php artisan test --parallel --stop-on-failure + - name: Run tests with Pest + run: php artisan test --stop-on-failure From 8ca08064edd5ea26f83d78e7c43bab43dafb1e3a Mon Sep 17 00:00:00 2001 From: Mubbasher Ahmed Qureshi Date: Fri, 18 Jul 2025 17:04:49 +0500 Subject: [PATCH 6/7] ci: use default mysql creds --- .github/workflows/ci.yml | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 780b112..1a8fced 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,11 +108,9 @@ jobs: env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: laravel_blog_test - MYSQL_USER: laravel_user - MYSQL_PASSWORD: laravel_password ports: - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + options: --health-cmd="mysqladmin ping -h localhost -u root -proot" --health-interval=10s --health-timeout=5s --health-retries=5 redis: image: redis:7-alpine @@ -156,25 +154,32 @@ jobs: echo "DB_HOST=127.0.0.1" >> .env echo "DB_PORT=3306" >> .env echo "DB_DATABASE=laravel_blog_test" >> .env - echo "DB_USERNAME=laravel_user" >> .env - echo "DB_PASSWORD=laravel_password" >> .env + echo "DB_USERNAME=root" >> .env + echo "DB_PASSWORD=root" >> .env echo "CACHE_STORE=array" >> .env echo "SESSION_DRIVER=array" >> .env echo "QUEUE_CONNECTION=sync" >> .env - name: Wait for MySQL to be ready run: | - for i in {1..30}; do - if mysqladmin ping -h 127.0.0.1 -u laravel_user -plaravel_password --silent; then + for i in {1..60}; do + if mysqladmin ping -h 127.0.0.1 -P 3306 -u root -proot --silent; then echo "MySQL is ready" + # Verify the database exists + mysql -h 127.0.0.1 -P 3306 -u root -proot -e "SHOW DATABASES;" | grep laravel_blog_test || exit 1 + echo "Database laravel_blog_test confirmed" break fi - echo "Waiting for MySQL... ($i/30)" - sleep 2 + echo "Waiting for MySQL... ($i/60)" + sleep 3 done + if [ $i -eq 60 ]; then + echo "MySQL failed to start within 3 minutes" + exit 1 + fi - name: Run database migrations run: php artisan migrate:fresh --seed --env=testing --force - - name: Run tests with Pest - run: php artisan test --stop-on-failure + - name: Run tests with Pest (parallel) + run: php artisan test --parallel --recreate-databases --stop-on-failure From 88642ea0c2cb932f21605507d2759b16792f27ac Mon Sep 17 00:00:00 2001 From: Mubbasher Ahmed Qureshi Date: Fri, 18 Jul 2025 17:11:30 +0500 Subject: [PATCH 7/7] ci: fix mysql env for testing --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a8fced..f74136b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -182,4 +182,8 @@ jobs: run: php artisan migrate:fresh --seed --env=testing --force - name: Run tests with Pest (parallel) + env: + DB_HOST: 127.0.0.1 + DB_USERNAME: root + DB_PASSWORD: root run: php artisan test --parallel --recreate-databases --stop-on-failure