-
Notifications
You must be signed in to change notification settings - Fork 21
143 lines (133 loc) · 5.11 KB
/
laravel.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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.3'
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: sqlite
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: vendor/bin/pest --testdox > test-summary.txt
- name: Upload Test Result to artifacts
if: always()
uses: actions/upload-artifact@v2
with:
name: test-summary
path: test-summary.txt
- 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 = '';
// Read the test summary file if it exists
if (fs.existsSync('test-summary.txt')) {
const testSummary = fs.readFileSync('test-summary.txt', { encoding: 'utf8' });
const testSummaryLines = testSummary.split('\n');
// Initialize an array to hold our formatted failing test lines
const failingTests = [];
let captureTrace = false;
let currentTest = [];
let passingTests = 0;
// Iterate over each line of the test summary
for (const line of testSummaryLines) {
// Check if the line is a file path and reset capture if we hit a new file
if (line.startsWith('/home/runner/work/')) {
captureTrace = false;
if (currentTest.length > 0) {
failingTests.push(currentTest.join('\n'));
currentTest = [];
}
}
// If the line indicates a failing test, start capturing
if (line.startsWith(' ✘')) {
captureTrace = true;
currentTest.push(line);
continue;
}
// If the line indicates a passing test, increment the counter
if (line.startsWith(' ✔')) {
passingTests++;
continue;
}
// If capturing, add the stack trace lines
if (captureTrace) {
if (line.trim() === '') {
// Empty line might signal the end of the stack trace
captureTrace = false;
failingTests.push(currentTest.join('\n'));
currentTest = [];
} else {
// Continue capturing the stack trace
currentTest.push(line);
}
}
}
// Check if there's a leftover test case at the end of the file
if (currentTest.length > 0) {
failingTests.push(currentTest.join('\n'));
}
if (failingTests.length > 0) {
// Join the failing tests with two new lines and wrap in a code block for markdown
message = `❌ Tests failed. Below are the details:\n\`\`\`\n${failingTests.join('\n\n')}\n\`\`\``;
} else if (passingTests > 0) {
message = '';
} else {
message = "⚠️ Error running tests. Logs:\n```\n" + testSummary + "\n```";
}
} else {
message = "⚠️ No test summary file found.";
}
if (message) {
core.setFailed(message);
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}