From 82ed8b16075553f139640e33137f249b0136a20b Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 4 Jan 2025 00:22:22 +1100 Subject: [PATCH 1/9] adds ci, updates composer --- .github/workflows/ci.yml | 50 ++++++++++++++++++++++++++++++++++++++++ composer.json | 29 ++++++++++++----------- 2 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ede3baf --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI Tests + +on: + pull_request: + push: + branches: + - master + - v* + +jobs: + tests: + runs-on: ubuntu-22.04 + + strategy: + fail-fast: false + matrix: + stability: [prefer-stable] + php: [8.1, 8.2, 8.3, 8.4] + laravel: [10] + + name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + # Docs: https://github.com/shivammathur/setup-php + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip + ini-values: error_reporting=E_ALL + tools: composer:v2 + # todo: Add + coverage: none + + - name: Install dependencies + run: | + composer require "illuminate/contracts=^${{ matrix.laravel }}" --no-update + composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader + - name: Prepare the application + run: | + php artisan key:generate + - name: Clear Config + run: | + php artisan config:clear + php artisan cache:clear + - name: Run phpunit tests + run: composer test diff --git a/composer.json b/composer.json index e5e41c6..4cbb33a 100644 --- a/composer.json +++ b/composer.json @@ -17,30 +17,31 @@ } ], "require": { - "php": "^7.3|^8.0", - "fideloper/proxy": "^4.4", - "fruitcake/laravel-cors": "^2.0", - "guzzlehttp/guzzle": "^7.0.1", - "laravel/framework": "^8.0", - "laravel/tinker": "^2.5", - "specialtactics/l5-api": "^3.0" + "php": ">=8.1", + "guzzlehttp/guzzle": "^7.6", + "laravel/framework": "^10.43", + "laravel/tinker": "^2.9", + "specialtactics/l5-api": "^5.0" }, "require-dev": { - "barryvdh/laravel-ide-helper": "^2.9", - "beyondcode/laravel-dump-server": "^1.4", + "barryvdh/laravel-ide-helper": "^2.15", + "beyondcode/laravel-dump-server": "^1.9", "facade/ignition": "^2.7", - "fakerphp/faker": "^1.9.1", - "mockery/mockery": "^1.4.1", - "nunomaduro/collision": "^5.0", + "fakerphp/faker": "^1.15", + "mockery/mockery": "^1.5", + "nunomaduro/collision": "^6.5", "phpunit/phpunit": "^9.3.3", - "laravel/telescope": "^4.4" + "laravel/telescope": "^5.1" }, "autoload": { "psr-4": { "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" - } + }, + "classmap": [ + "database/migrations" + ] }, "autoload-dev": { "psr-4": { From efb1f80a4a300a88d461da84e668149eeb2a5c6b Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 4 Jan 2025 00:24:22 +1100 Subject: [PATCH 2/9] dont really need this for api projects --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 4cbb33a..7a3cc12 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,6 @@ "require-dev": { "barryvdh/laravel-ide-helper": "^2.15", "beyondcode/laravel-dump-server": "^1.9", - "facade/ignition": "^2.7", "fakerphp/faker": "^1.15", "mockery/mockery": "^1.5", "nunomaduro/collision": "^6.5", From 72074a027461ab6049e3b185ce8cf0b5c3a31591 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 4 Jan 2025 00:28:34 +1100 Subject: [PATCH 3/9] add setup steps in ci --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ede3baf..70aa689 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,8 @@ jobs: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader - name: Prepare the application run: | - php artisan key:generate + composer post-root-package-install + composer post-create-project-cmd - name: Clear Config run: | php artisan config:clear From 404a8c0c17bc5ac29f8d0376d79928560a6bdfa9 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 4 Jan 2025 00:29:23 +1100 Subject: [PATCH 4/9] composer run --- .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 70aa689..958cb70 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,8 +41,8 @@ jobs: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader - name: Prepare the application run: | - composer post-root-package-install - composer post-create-project-cmd + composer run post-root-package-install + composer run post-create-project-cmd - name: Clear Config run: | php artisan config:clear From 2777e682ab6cc737e0b5d067c7e7ff979ac3bb24 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 4 Jan 2025 16:23:00 +1100 Subject: [PATCH 5/9] Adds postgres service --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 958cb70..9b2cab1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,22 @@ jobs: name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} + # Service containers to run with `container-job` + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: secret + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - name: Checkout code uses: actions/checkout@v4 @@ -39,13 +55,35 @@ jobs: run: | composer require "illuminate/contracts=^${{ matrix.laravel }}" --no-update composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader + - name: Prepare the application run: | composer run post-root-package-install composer run post-create-project-cmd + - name: Clear Config run: | php artisan config:clear php artisan cache:clear + + - name: Connect to PostgreSQL + # Runs a script that creates a PostgreSQL table, populates + # the table with data, and then retrieves the data. + run: node client.js + # Environment variables used by the `client.js` script to create a new PostgreSQL table. + env: + # The hostname used to communicate with the PostgreSQL service container + POSTGRES_HOST: postgres + # The default PostgreSQL port + POSTGRES_PORT: 5432 + + - name: Set postgres envs for app + run: | + echo "DB_HOST=postgres" >> .env + echo "DB_HOST=postgres" >> .env + echo "DB_DATABASE=postgres" >> .env + echo "DB_DATABASE_TEST=postgres" >> .env + echo "DB_USERNAME=postgres" >> .env + - name: Run phpunit tests run: composer test From ce506fa93162c8bf23fb51f0a9b369f3cf5db99e Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 4 Jan 2025 16:36:23 +1100 Subject: [PATCH 6/9] remove the test script --- .github/workflows/ci.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b2cab1..2a734c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,17 +66,6 @@ jobs: php artisan config:clear php artisan cache:clear - - name: Connect to PostgreSQL - # Runs a script that creates a PostgreSQL table, populates - # the table with data, and then retrieves the data. - run: node client.js - # Environment variables used by the `client.js` script to create a new PostgreSQL table. - env: - # The hostname used to communicate with the PostgreSQL service container - POSTGRES_HOST: postgres - # The default PostgreSQL port - POSTGRES_PORT: 5432 - - name: Set postgres envs for app run: | echo "DB_HOST=postgres" >> .env From cf68a31a8cc965880a463ccf5f7feec2397c2c25 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 4 Jan 2025 16:43:35 +1100 Subject: [PATCH 7/9] try postgres host localhost --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a734c4..57a5d2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,8 +68,7 @@ jobs: - name: Set postgres envs for app run: | - echo "DB_HOST=postgres" >> .env - echo "DB_HOST=postgres" >> .env + echo "DB_HOST=localhost" >> .env echo "DB_DATABASE=postgres" >> .env echo "DB_DATABASE_TEST=postgres" >> .env echo "DB_USERNAME=postgres" >> .env From 507afec8d79f57dd63949d59ee453367bced5d73 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 4 Jan 2025 22:35:02 +1100 Subject: [PATCH 8/9] try mapping port --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57a5d2f..e516e1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,8 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 5432:5432 steps: - name: Checkout code @@ -68,7 +70,7 @@ jobs: - name: Set postgres envs for app run: | - echo "DB_HOST=localhost" >> .env + echo "DB_HOST=postgres" >> .env echo "DB_DATABASE=postgres" >> .env echo "DB_DATABASE_TEST=postgres" >> .env echo "DB_USERNAME=postgres" >> .env From 200e0dbbfe550c02a57541116f20c7a77c91b68e Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 4 Jan 2025 22:36:33 +1100 Subject: [PATCH 9/9] try localhost again --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e516e1a..f1a1a75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: - name: Set postgres envs for app run: | - echo "DB_HOST=postgres" >> .env + echo "DB_HOST=localhost" >> .env echo "DB_DATABASE=postgres" >> .env echo "DB_DATABASE_TEST=postgres" >> .env echo "DB_USERNAME=postgres" >> .env