branch #64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Laravel | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
laravel-tests: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: ankane/pgvector:latest | |
env: | |
POSTGRES_USER: root | |
POSTGRES_PASSWORD: password | |
POSTGRES_DB: laravel_test | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e | |
with: | |
php-version: '8.1' | |
extensions: pdo_pgsql | |
- uses: actions/checkout@v3 | |
- name: Copy .env | |
run: php -r "file_exists('.env') || copy('.env.example', '.env');" | |
- name: Install Dependencies | |
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist | |
- name: Generate key | |
run: php artisan key:generate | |
- name: Directory Permissions | |
run: chmod -R 777 storage bootstrap/cache | |
- name: Install pgvector extension | |
run: PGPASSWORD=password psql -h localhost -U root -d laravel_test -c "CREATE EXTENSION IF NOT EXISTS vector;" | |
- name: Install Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Install Front-End Dependencies with npm ci | |
run: npm ci | |
- name: Build Front-End Assets | |
run: npm run build | |
- name: Remove node_modules | |
run: rm -rf node_modules | |
- name: Execute tests (Unit and Feature tests) via PHPUnit | |
id: test_step | |
env: | |
DB_CONNECTION: pgsql | |
DB_HOST: localhost | |
DB_PORT: 5432 | |
DB_DATABASE: laravel_test | |
DB_USERNAME: root | |
DB_PASSWORD: password | |
run: | | |
vendor/bin/pest --testdox > test-summary.txt | |
echo "TEST_EXIT_CODE=$?" >> $GITHUB_ENV | |
- name: Comment PR on Test Result | |
if: always() && github.event_name == 'pull_request' | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const fs = require('fs'); | |
const prNumber = context.issue.number; | |
let message = ''; | |
if (process.env.TEST_EXIT_CODE !== '0') { | |
message = "❌ Tests failed to complete successfully."; | |
} else if (fs.existsSync('test-summary.txt')) { | |
const testSummary = fs.readFileSync('test-summary.txt', { encoding: 'utf8' }); | |
if (testSummary.trim() === '') { | |
message = "⚠️ Test summary file is empty."; | |
} else { | |
const testSummaryLines = testSummary.split('\n'); | |
const failingTests = []; | |
let captureTrace = false; | |
let currentTest = []; | |
for (const line of testSummaryLines) { | |
if (line.startsWith('/home/runner/work/')) { | |
captureTrace = false; | |
if (currentTest.length > 0) { | |
failingTests.push(currentTest.join('\n')); | |
currentTest = []; | |
} | |
} | |
if (line.startsWith(' ✘')) { | |
captureTrace = true; | |
currentTest.push(line); | |
continue; | |
} | |
if (captureTrace) { | |
if (line.trim() === '') { | |
captureTrace = false; | |
failingTests.push(currentTest.join('\n')); | |
currentTest = []; | |
} else { | |
currentTest.push(line); | |
} | |
} | |
} | |
if (currentTest.length > 0) { | |
failingTests.push(currentTest.join('\n')); | |
} | |
if (failingTests.length > 0) { | |
message = `❌ Tests failed. Below are the details:\n\`\`\`\n${failingTests.join('\n\n')}\n\`\`\``; | |
} else { | |
message = "✅ All tests passed!"; | |
} | |
} | |
} else { | |
message = "⚠️ No test summary file found."; | |
} | |
// Create the PR comment | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
body: message | |
}); | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set job outcome based on test results | |
if: always() | |
run: | | |
if [ "$TEST_EXIT_CODE" != "0" ]; then | |
exit $TEST_EXIT_CODE | |
fi | |
env: | |
TEST_EXIT_CODE: ${{ env.TEST_EXIT_CODE }} |