-
Notifications
You must be signed in to change notification settings - Fork 0
349 lines (305 loc) · 13.2 KB
/
e2e-tests.yml
File metadata and controls
349 lines (305 loc) · 13.2 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# Copyright The Linux Foundation and each contributor to LFX.
# SPDX-License-Identifier: MIT
name: E2E Tests
permissions:
id-token: write
contents: read
issues: write
pull-requests: write
on:
workflow_call:
inputs:
node-version:
description: 'Node.js version to use'
required: false
default: '22'
type: string
test-command:
description: 'Test command to run'
required: false
default: 'e2e'
type: string
browser:
description: 'Browser to test (chromium, firefox, mobile-chrome, or all)'
required: false
default: 'all'
type: string
base-url:
description: 'Base URL for testing'
required: false
default: 'http://localhost:4200'
type: string
skip-build:
description: 'Skip building the application (use existing build)'
required: false
default: false
type: boolean
secrets:
TEST_USERNAME:
description: 'Username for test authentication'
required: false
TEST_PASSWORD:
description: 'Password for test authentication'
required: false
outputs:
test-results:
description: 'Test results summary'
value: ${{ jobs.e2e-tests.outputs.test-results }}
report-url:
description: 'URL to the test report artifact'
value: ${{ jobs.e2e-tests.outputs.report-url }}
jobs:
e2e-tests:
name: Playwright E2E Tests
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
test-results: ${{ steps.test-results.outputs.results }}
report-url: ${{ steps.upload-report.outputs.artifact-url }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: 'yarn'
- name: Install dependencies
run: yarn install --immutable
- name: OIDC Auth
uses: aws-actions/configure-aws-credentials@v4
id: oidc-auth
with:
audience: sts.amazonaws.com
role-to-assume: arn:aws:iam::788942260905:role/github-actions-deploy
aws-region: us-west-2
- name: Read secrets from AWS Secrets Manager into environment variables
id: get_secrets
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
SUPABASE, /cloudops/managed-secrets/cloud/supabase/api_key
AUTH0, /cloudops/managed-secrets/auth0/LFX_V2_PCC
- name: Setup Turborepo cache
uses: actions/cache@v4
with:
path: |
.turbo
node_modules/.cache/turbo
key: ${{ runner.os }}-turbo-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/*', '!**/node_modules/**', '!**/.turbo/**') }}
restore-keys: |
${{ runner.os }}-turbo-${{ hashFiles('**/yarn.lock') }}-
${{ runner.os }}-turbo-
- name: Validate required secrets for E2E testing
id: validate-secrets
run: |
missing_secrets=""
# Check AWS Secrets Manager secrets (masked environment variables)
if [ -z "$AUTH0" ]; then
missing_secrets="$missing_secrets AUTH0 (from AWS Secrets Manager)"
fi
if [ -z "$SUPABASE" ]; then
missing_secrets="$missing_secrets SUPABASE (from AWS Secrets Manager)"
fi
# Check GitHub secrets (fallback)
if [ -z "${{ secrets.TEST_USERNAME }}" ]; then
missing_secrets="$missing_secrets TEST_USERNAME"
fi
if [ -z "${{ secrets.TEST_PASSWORD }}" ]; then
missing_secrets="$missing_secrets TEST_PASSWORD"
fi
if [ -n "$missing_secrets" ]; then
echo "❌ Missing required secrets for E2E testing:$missing_secrets"
echo "Please configure these secrets to enable E2E tests."
echo "can_run_tests=false" >> $GITHUB_OUTPUT
else
echo "✅ All required secrets are configured"
echo "can_run_tests=true" >> $GITHUB_OUTPUT
fi
- name: Set up non-sensitive environment variables
if: steps.validate-secrets.outputs.can_run_tests == 'true'
run: |
echo "ENV=development" >> $GITHUB_ENV
echo "PCC_BASE_URL=http://localhost:4200" >> $GITHUB_ENV
echo "PCC_AUTH0_ISSUER_BASE_URL=https://linuxfoundation-dev.auth0.com/" >> $GITHUB_ENV
echo "PCC_AUTH0_AUDIENCE=https://api-gw.dev.platform.linuxfoundation.org/" >> $GITHUB_ENV
echo "LFX_V2_SERVICE=http://lfx-api.dev.v2.cluster.linuxfound.info" >> $GITHUB_ENV
echo "CI=true" >> $GITHUB_ENV
- name: Set up sensitive environment variables
if: steps.validate-secrets.outputs.can_run_tests == 'true'
run: |
# Parse and set AUTH0 secrets with explicit masking
if [ -n "$AUTH0" ]; then
AUTH0_CLIENT_ID=$(echo "$AUTH0" | jq -r '.client_id // empty')
AUTH0_CLIENT_SECRET=$(echo "$AUTH0" | jq -r '.client_secret // empty')
# Explicitly mask the values
echo "::add-mask::$AUTH0_CLIENT_ID"
echo "::add-mask::$AUTH0_CLIENT_SECRET"
# Set as environment variables
echo "PCC_AUTH0_CLIENT_ID=$AUTH0_CLIENT_ID" >> $GITHUB_ENV
echo "PCC_AUTH0_CLIENT_SECRET=$AUTH0_CLIENT_SECRET" >> $GITHUB_ENV
echo "✅ AUTH0 secrets set as masked environment variables"
fi
# Parse and set SUPABASE secrets
if [ -n "$SUPABASE" ]; then
SUPABASE_URL=$(echo "$SUPABASE" | jq -r '.url // empty')
SUPABASE_API_KEY=$(echo "$SUPABASE" | jq -r '.api_key // empty')
# Explicitly mask the values
echo "::add-mask::$SUPABASE_URL"
echo "::add-mask::$SUPABASE_API_KEY"
# Set as environment variables
echo "SUPABASE_URL=$SUPABASE_URL" >> $GITHUB_ENV
echo "POSTGRES_API_KEY=$SUPABASE_API_KEY" >> $GITHUB_ENV
echo "✅ SUPABASE secrets set as masked environment variables"
fi
# Set test credentials
echo "::add-mask::${{ secrets.TEST_USERNAME }}"
echo "::add-mask::${{ secrets.TEST_PASSWORD }}"
echo "TEST_USERNAME=${{ secrets.TEST_USERNAME }}" >> $GITHUB_ENV
echo "TEST_PASSWORD=${{ secrets.TEST_PASSWORD }}" >> $GITHUB_ENV
- name: Install Playwright browsers
if: steps.validate-secrets.outputs.can_run_tests == 'true'
working-directory: apps/lfx-pcc
run: npx playwright install --with-deps
- name: Create Playwright auth directory
if: steps.validate-secrets.outputs.can_run_tests == 'true'
working-directory: apps/lfx-pcc
run: mkdir -p playwright/.auth
- name: Build the application
if: steps.validate-secrets.outputs.can_run_tests == 'true'
run: yarn build
- name: Run E2E tests (All browsers)
if: ${{ inputs.browser == 'all' && steps.validate-secrets.outputs.can_run_tests == 'true' }}
working-directory: apps/lfx-pcc
run: |
if [ -n "$TEST_USERNAME" ] && [ -n "$TEST_PASSWORD" ]; then
echo "🔐 Running authenticated E2E tests on all browsers"
echo "🚀 Playwright will automatically start the dev server on localhost:4200"
echo "📋 Using secrets from AWS Secrets Manager"
yarn ${{ inputs.test-command }} --reporter=list
else
echo "⚠️ No test credentials provided. Skipping E2E tests."
echo "Set TEST_USERNAME and TEST_PASSWORD secrets to enable E2E tests."
exit 0
fi
- name: Run E2E tests (Specific browser)
if: ${{ inputs.browser != 'all' && steps.validate-secrets.outputs.can_run_tests == 'true' }}
working-directory: apps/lfx-pcc
run: |
if [ -n "$TEST_USERNAME" ] && [ -n "$TEST_PASSWORD" ]; then
echo "🔐 Running authenticated E2E tests on ${{ inputs.browser }}"
echo "🚀 Playwright will automatically start the dev server on localhost:4200"
echo "📋 Using secrets from AWS Secrets Manager"
yarn ${{ inputs.test-command }} --project=${{ inputs.browser }} --reporter=list
else
echo "⚠️ No test credentials provided. Skipping E2E tests."
echo "Set TEST_USERNAME and TEST_PASSWORD secrets to enable E2E tests."
exit 0
fi
- name: E2E tests skipped
if: ${{ steps.validate-secrets.outputs.can_run_tests == 'false' }}
run: |
echo "⏭️ E2E tests skipped due to missing required secrets"
echo "Configure the following secrets to enable E2E testing:"
echo ""
echo "AWS Secrets Manager (required):"
echo " - /cloudops/managed-secrets/auth0/LFX_V2_PCC (AUTH0 configuration)"
echo " - /cloudops/managed-secrets/cloud/supabase/api_key (SUPABASE configuration)"
echo ""
echo "GitHub Secrets (required for authenticated tests):"
echo " - TEST_USERNAME"
echo " - TEST_PASSWORD"
- name: Generate test results summary
id: test-results
if: always()
working-directory: apps/lfx-pcc
run: |
if [ "${{ steps.validate-secrets.outputs.can_run_tests }}" == "false" ]; then
echo "⏭️ E2E tests skipped (missing required secrets)"
echo "results=skipped" >> $GITHUB_OUTPUT
elif [ -z "$TEST_USERNAME" ] || [ -z "$TEST_PASSWORD" ]; then
echo "⏭️ E2E tests skipped (no test credentials)"
echo "results=skipped" >> $GITHUB_OUTPUT
elif [ -f "test-results/.last-run.json" ]; then
echo "✅ E2E tests completed successfully"
echo "results=success" >> $GITHUB_OUTPUT
else
echo "❌ E2E tests failed"
echo "results=failure" >> $GITHUB_OUTPUT
fi
- name: Upload Playwright report
id: upload-report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report-${{ inputs.browser }}-${{ github.run_id }}
path: |
apps/lfx-pcc/playwright-report/
retention-days: 7
- name: Comment test results on PR
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v7
with:
script: |
const results = '${{ steps.test-results.outputs.results }}';
const browser = '${{ inputs.browser }}';
const runId = '${{ github.run_id }}';
let emoji, status, details;
if (results === 'success') {
emoji = '✅';
status = 'passed';
details = 'All E2E tests passed successfully.';
} else if (results === 'failure') {
emoji = '❌';
status = 'failed';
details = 'Some E2E tests failed. Check the [test report](https://github.com/${{ github.repository }}/actions/runs/' + runId + ') for details.';
} else {
emoji = '⏭️';
status = 'skipped';
details = 'E2E tests were skipped (no test credentials provided).';
}
const comment = `## ${emoji} E2E Tests ${status.charAt(0).toUpperCase() + status.slice(1)}
**Browser:** ${browser}
**Status:** ${status}
${details}
<details>
<summary>Test Configuration</summary>
- **Node.js:** ${{ inputs.node-version }}
- **Command:** \`${{ inputs.test-command }}\`
- **Browser:** ${browser}
- **Base URL:** ${{ inputs.base-url }}
</details>`;
// Look for existing E2E test comment by this bot
const existingComments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const botComment = existingComments.data.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('## ') &&
comment.body.includes('E2E Tests')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
console.log('Updated existing E2E test comment');
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
console.log('Created new E2E test comment');
}