From 5b95685ee67d5d0577c952ecba0f04e844f88db5 Mon Sep 17 00:00:00 2001 From: musimana <37738856+musimana@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:54:34 +0000 Subject: [PATCH 1/6] Created laravel.yml --- .github/workflows/laravel.yml | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/laravel.yml diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml new file mode 100644 index 00000000..9b1d6995 --- /dev/null +++ b/.github/workflows/laravel.yml @@ -0,0 +1,43 @@ +name: Laravel + +on: + push: + branches: [ "main", "develop" ] + pull_request: + branches: [ "main", "develop" ] + +jobs: + laravel-tests: + + runs-on: ubuntu-latest + + steps: + - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e + with: + php-version: '8.2' + - uses: actions/checkout@v3 + - name: Copy .env + run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Install Dependencies + run: | + composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + npm i + - name: Generate key + run: php artisan key:generate + - name: Directory Permissions + run: chmod -R 777 storage bootstrap/cache + - name: Compile the assets & start the server + run: npm run build && php artisan inertia:start-ssr + - name: Create Test Database + run: | + mkdir -p database + touch database/database.sqlite + - name: Run the linters + run: npm run lint + - name: Execute Type tests via Larastan + run: composer test:types + - name: Execute Unit tests via PHPUnit + env: + DB_CONNECTION: sqlite + DB_DATABASE: database/database.sqlite + run: php artisan test From 793d3d1c76da2fbdbfd9034d4d28812934e7d624 Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Fri, 22 Mar 2024 21:03:21 +0000 Subject: [PATCH 2/6] Updated SSR server to run in the background for tests & standardised step names --- .github/workflows/laravel.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 9b1d6995..d30c9a74 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -5,6 +5,7 @@ on: branches: [ "main", "develop" ] pull_request: branches: [ "main", "develop" ] + workflow_dispatch: jobs: laravel-tests: @@ -18,17 +19,17 @@ jobs: - uses: actions/checkout@v3 - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" - - name: Install Dependencies + - name: Install dependencies run: | composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist npm i - name: Generate key run: php artisan key:generate - - name: Directory Permissions + - name: Set directory permissions run: chmod -R 777 storage bootstrap/cache - name: Compile the assets & start the server - run: npm run build && php artisan inertia:start-ssr - - name: Create Test Database + run: npm run dev & + - name: Create test database run: | mkdir -p database touch database/database.sqlite From 9c697b69f7526fed69b849aadcb4fe2fbf4916bb Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Fri, 22 Mar 2024 21:24:29 +0000 Subject: [PATCH 3/6] Added step to setup required Node version --- .github/workflows/laravel.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index d30c9a74..3bc9e49a 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -17,6 +17,10 @@ jobs: with: php-version: '8.2' - uses: actions/checkout@v3 + - name: Setup Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" - name: Install dependencies From 87a2f62de44da9e1ff544c495e8335420c71c8a8 Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Fri, 22 Mar 2024 21:41:15 +0000 Subject: [PATCH 4/6] Reverted to production mode when compiling the assets for CI tests --- .github/workflows/laravel.yml | 2 +- tests/Pest/Expectations/ToHaveCorrectHtmlHead.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 3bc9e49a..3c518fea 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -32,7 +32,7 @@ jobs: - name: Set directory permissions run: chmod -R 777 storage bootstrap/cache - name: Compile the assets & start the server - run: npm run dev & + run: npm run build && php artisan inertia:start-ssr & - name: Create test database run: | mkdir -p database diff --git a/tests/Pest/Expectations/ToHaveCorrectHtmlHead.php b/tests/Pest/Expectations/ToHaveCorrectHtmlHead.php index 426ab109..1cea11e5 100644 --- a/tests/Pest/Expectations/ToHaveCorrectHtmlHead.php +++ b/tests/Pest/Expectations/ToHaveCorrectHtmlHead.php @@ -43,9 +43,12 @@ '', - '', - '', - '', + '', + '', + '', '', ], false); From 183a713c1fe33185b97f74c346d7d248a00bd1f1 Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Fri, 22 Mar 2024 21:55:23 +0000 Subject: [PATCH 5/6] Updated assertions to work with assets in production mode --- tests/Pest/Expectations/ToHaveCorrectHeaderValues.php | 1 - tests/Pest/Expectations/ToHaveCorrectHtmlBody.php | 2 +- tests/Pest/Expectations/ToHaveCorrectHtmlHead.php | 6 ------ 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/Pest/Expectations/ToHaveCorrectHeaderValues.php b/tests/Pest/Expectations/ToHaveCorrectHeaderValues.php index 423930c6..51a80faf 100644 --- a/tests/Pest/Expectations/ToHaveCorrectHeaderValues.php +++ b/tests/Pest/Expectations/ToHaveCorrectHeaderValues.php @@ -25,7 +25,6 @@ $this ->toHaveKebabCaseKeys() - ->toHaveCount(5) ->toHaveKeys([ 'cache-control', 'date', diff --git a/tests/Pest/Expectations/ToHaveCorrectHtmlBody.php b/tests/Pest/Expectations/ToHaveCorrectHtmlBody.php index 323b4a74..75d1bc89 100644 --- a/tests/Pest/Expectations/ToHaveCorrectHtmlBody.php +++ b/tests/Pest/Expectations/ToHaveCorrectHtmlBody.php @@ -24,7 +24,7 @@ ->assertSeeInOrder([ '', '
', + '>', '', '', ], false); diff --git a/tests/Pest/Expectations/ToHaveCorrectHtmlHead.php b/tests/Pest/Expectations/ToHaveCorrectHtmlHead.php index 1cea11e5..1a3dab6d 100644 --- a/tests/Pest/Expectations/ToHaveCorrectHtmlHead.php +++ b/tests/Pest/Expectations/ToHaveCorrectHtmlHead.php @@ -43,12 +43,6 @@ '', - '', - '', - '', '', ], false); From e4284c39c8813f9cfadb4404f0fcfa4c3d757381 Mon Sep 17 00:00:00 2001 From: Graham Aitken Date: Fri, 22 Mar 2024 22:19:46 +0000 Subject: [PATCH 6/6] Updated GitHub action config to use latest dependency versions --- .github/workflows/laravel.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 3c518fea..861c2d32 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e + - uses: shivammathur/setup-php@v2 with: php-version: '8.2' - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Node.js 20.x uses: actions/setup-node@v4 with: