-
Notifications
You must be signed in to change notification settings - Fork 1
232 lines (199 loc) · 8.25 KB
/
Copy pathe2e.yml
File metadata and controls
232 lines (199 loc) · 8.25 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: E2E Tests
on:
push:
branches:
- main
- '[0-9]+.[0-9]+*'
pull_request: ~
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
BACKEND_REPOSITORY: ${{ vars.BACKEND_REPOSITORY || 'Narvik-app/backend' }}
jobs:
determine-backend:
name: Determine Backend Branch
runs-on: ubuntu-latest
outputs:
backend_ref: ${{ steps.determine-backend.outputs.backend_ref }}
steps:
- name: Determine Backend Branch
id: determine-backend
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GH_PAT || github.token }}
script: |
// Pick the backend ref to test against, in order:
// 1. main, if that's the branch being built
// 2. a backend branch with the same name (stacked cross-repo PR)
// 3. the PR's base branch, if it's a version branch that exists on backend (e.g. backport into 3.22)
// 4. main
const headBranch = context.eventName === 'pull_request'
? context.payload.pull_request.head.ref
: context.ref.replace('refs/heads/', '');
const baseBranch = context.eventName === 'pull_request'
? context.payload.pull_request.base.ref
: headBranch;
const backendRepoStr = process.env.BACKEND_REPOSITORY;
const [owner, repo] = backendRepoStr.split('/');
async function backendBranchExists(branch) {
try {
await github.rest.repos.getBranch({ owner, repo, branch });
return true;
} catch (error) {
if (error.status !== 404) {
core.warning(`⚠️ Error checking backend branch '${branch}' on ${owner}/${repo} (${error.message}).`);
}
return false;
}
}
let backendRef = 'main';
let reason = `No backend branch named '${headBranch}' found - falling back to main.`;
if (headBranch === 'main') {
backendRef = 'main';
reason = 'Branch is main, checking out main on backend.';
} else if (await backendBranchExists(headBranch)) {
backendRef = headBranch;
reason = `A branch named '${headBranch}' exists on backend (${owner}/${repo}) - checking it out.`;
} else if (/^[0-9]+\.[0-9]+/.test(baseBranch) && await backendBranchExists(baseBranch)) {
backendRef = baseBranch;
reason = `No matching '${headBranch}' branch on backend, but PR targets version branch (${baseBranch}) which does exist there - checking it out.`;
} else {
core.warning(reason);
}
const summaryTable = `
| Property | Value |
| --- | --- |
| Frontend Branch | \`${headBranch}\` |
| Backend Checkout Ref | \`${backendRef}\` |
| Event | \`${context.eventName}\` |
| Reason | ${reason} |
`;
await core.summary
.addHeading('🔗 Backend Repository Details', 3)
.addRaw(summaryTable)
.write();
core.setOutput('backend_ref', backendRef);
e2e:
name: Playwright E2E Tests
needs: determine-backend
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Checkout Backend
uses: actions/checkout@v7
with:
repository: ${{ env.BACKEND_REPOSITORY }}
ref: ${{ needs.determine-backend.outputs.backend_ref }}
path: backend
token: ${{ secrets.GH_PAT }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Backend (Cached)
working-directory: backend
run: |
docker buildx build \
--target frankenphp_dev \
--cache-from type=gha,scope=${{ github.ref }} \
--cache-from type=gha,scope=refs/heads/main \
--cache-to type=gha,scope=${{ github.ref }},mode=max \
--tag narvik-php:latest \
--load \
.
- name: Generate JWT Keys
working-directory: backend
run: |
mkdir -p config/jwt
openssl genrsa -passout pass:changeme -out config/jwt/private.pem -aes256 4096
openssl rsa -in config/jwt/private.pem -passin pass:changeme -pubout -out config/jwt/public.pem
- name: Start Backend (Dev Mode)
working-directory: backend
run: |
# Create an override to map ports and set E2E secrets
cat > compose.e2e.override.yaml << 'EOF'
services:
php:
ports:
- "80:80"
environment:
APP_SECRET: ChangeMeTheSecretForE2E
# Ensure we use dev env
APP_ENV: dev
# Caddy config for HTTP
SERVER_NAME: :80
# CORS for frontend
CORS_ALLOW_ORIGIN: "^https?://localhost(:[0-9]+)?$"
TRUSTED_HOSTS: ^localhost|php$$
OAUTH_PASSPHRASE: changeme
ENCRYPTION_KEY: Cf6W9EQOk9ft8VQ04By2VCW55dQVJ4VWEfwTPqHIcL8=
MERCURE_JWT_SECRET: '!ChangeThisMercureHubJWTSecretKey!'
MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
EOF
# Start using pre-built image from cache
# compose.yaml (base) + .github/compose.ci.yaml (dev build + mounts) + override (ports)
docker compose -f compose.yaml -f .github/compose.ci.yaml -f compose.e2e.override.yaml up -d --wait --no-build
- name: Setup database and fixtures
working-directory: backend
run: |
docker compose exec -T php composer reload-fixture
- name: Install pnpm
uses: pnpm/action-setup@v6
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: '26'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Get Playwright Version
id: playwright-version
run: echo "VERSION=$(pnpm exec playwright --version | awk '{print $2}')" >> $GITHUB_OUTPUT
- name: Cache Playwright Browsers
uses: actions/cache@v6
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.VERSION }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: pnpm exec playwright install --with-deps chromium
- name: Generate SSL Certificates
run: |
openssl req -x509 -newkey rsa:4096 -keyout localhost-key.pem -out localhost.pem -days 365 -nodes -subj '/CN=localhost'
- name: Build Nuxt application
run: pnpm build
- name: Setup Environment
run: cp .env.ci .env
- name: Verify Backend Accessibility
run: |
# Wait up to 30s for the backend to respond with something (even if 4xx/5xx)
timeout 30s bash -c "until curl -s http://127.0.0.1:80 > /dev/null; do sleep 1; done" || (echo 'Backend unreachable at http://127.0.0.1:80'; exit 1)
# Check health endpoint if exists, or just root
curl -v http://127.0.0.1:80
- name: Run Playwright tests
run: pnpm test:e2e:ci --project=chromium
- name: Upload Playwright report
uses: actions/upload-artifact@v7
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 7
if-no-files-found: ignore
- name: Upload test results
uses: actions/upload-artifact@v7
if: ${{ !cancelled() }}
with:
name: test-results
path: test-results/
retention-days: 7
if-no-files-found: ignore
- name: Stop services
if: always()
working-directory: backend
run: docker compose -f compose.yaml -f .github/compose.ci.yaml -f compose.e2e.override.yaml down -v