-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
164 lines (143 loc) · 6.91 KB
/
integration-test.yaml
File metadata and controls
164 lines (143 loc) · 6.91 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Integration test
on:
schedule:
- cron: "0 5 * * *" # Run daily at 05:00 UTC
workflow_dispatch: # Allow manual execution
permissions:
contents: read
issues: write
jobs:
e2e-integration:
name: Full Symfony + EasyAdmin integration
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
coverage: none
extensions: mbstring, intl, pdo, pdo_sqlite, sqlite3
ini-values: date.timezone=UTC
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -y sqlite3 expect wget gpg
wget https://get.symfony.com/cli/installer -O - | bash
mv ~/.symfony*/bin/symfony /usr/local/bin/symfony
symfony version
- name: Create fresh Symfony app
run: |
composer create-project symfony/skeleton:"^7.3" e2e-app
cd e2e-app
composer config extra.symfony.require "7.3.*"
composer require symfony/orm-pack symfony/twig-pack symfony/runtime
composer require easycorp/easyadmin-bundle
composer require --dev symfony/maker-bundle doctrine/doctrine-fixtures-bundle zenstruck/foundry symfony/test-pack fakerphp/faker
- name: Configure SQLite
working-directory: e2e-app
run: |
sed -i 's|^#\? *DATABASE_URL=.*$|DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"|' .env
mkdir -p var
- name: Create Product entity
working-directory: e2e-app
run: |
expect <<'EOD'
spawn php bin/console make:entity Product
expect "New property name" { send "name\r" }
expect "Field type" { send "string\r" }
expect "Field length" { send "\r" }
expect "nullable" { send "no\r" }
expect "Add another property" { send "price\r" }
expect "Field type" { send "integer\r" }
expect "nullable" { send "no\r" }
expect "Add another property" { send "\r" }
expect eof
EOD
- name: Create DB schema
working-directory: e2e-app
run: |
# Ensure DB file exists for SQLite, ignore if already present
touch var/data.db
php bin/console doctrine:schema:create -q
- name: Generate Dashboard and CRUD
working-directory: e2e-app
run: |
php bin/console make:admin:dashboard --no-interaction
# Run make:admin:crud interactively with expect
mkdir -p src/Controller/Admin/
expect <<'EOD'
spawn php bin/console make:admin:crud
expect "Which Doctrine entity" { send "0\r" }
expect "Which directory" { send "\r" }
expect "Namespace of the generated CRUD controller" { send "\r" }
expect eof
EOD
# Add MenuItem::linkToCrud() entry if missing
file="src/Controller/Admin/DashboardController.php"
if ! grep -q "linkToCrud" "$file"; then
sed -i '/yield MenuItem::linkToDashboard/a\
yield MenuItem::linkToCrud("Products", "fa fa-box", App\\Entity\\Product::class);' "$file"
fi
- name: Create factory and fixtures
working-directory: e2e-app
run: |
expect <<'EOD'
spawn php bin/console make:factory
expect "Entity, Document or class" { send "0\r" }
expect eof
EOD
if [ ! -f src/DataFixtures/AppFixtures.php ]; then
php bin/console make:fixtures AppFixtures
else
echo "AppFixtures.php already exists, skipping creation."
fi
sed -i 's|use Doctrine\\Persistence\\ObjectManager;|use Doctrine\\Persistence\\ObjectManager;\nuse App\\Factory\\ProductFactory;|' src/DataFixtures/AppFixtures.php
sed -i 's|// \$product = new Product();|ProductFactory::createMany(10);|' src/DataFixtures/AppFixtures.php
- name: Load fixtures
working-directory: e2e-app
run: php bin/console doctrine:fixtures:load --no-interaction -q
- name: Start Symfony server
working-directory: e2e-app
run: |
symfony server:start --no-tls --port=8000 --daemon --no-humanize
for i in {1..20}; do
if curl -sSf http://127.0.0.1:8000/ > /dev/null; then break; fi
sleep 0.5
done
- name: Functional smoke test
id: smoke
working-directory: e2e-app
run: |
set -e
status=$(curl -sS -o /tmp/page.html -w "%{http_code}" http://127.0.0.1:8000/admin)
echo "HTTP_STATUS=$status" >> $GITHUB_OUTPUT
test "$status" = "200"
grep -q "Products" /tmp/page.html
grep -qi "Dashboard" /tmp/page.html
grep -qi "Product" /tmp/page.html || (echo "No product content found" && exit 1)
- name: Stop Symfony server
if: always()
working-directory: e2e-app
run: symfony server:stop || true
- name: Create issue on failure
if: failure()
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
let body = 'Integration test failed.\n\n';
try {
const page = fs.readFileSync('/tmp/page.html', 'utf8');
body += 'Last page HTML (truncated):\n\n```\n' + page.slice(0, 4000) + '\n```\n';
} catch (e) {
body += 'Could not attach page HTML.\n';
}
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
body += `\nRun: ${runUrl}`;
#await github.rest.issues.create({
# owner: context.repo.owner,
# repo: context.repo.repo,
# title: `Integration test failed: ${new Date().toISOString().slice(0,10)}`,
# body
#});