-
-
Notifications
You must be signed in to change notification settings - Fork 47
201 lines (186 loc) · 6.7 KB
/
Copy pathe2e-tests.yml
File metadata and controls
201 lines (186 loc) · 6.7 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
name: E2E Tests
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
concurrency:
group: e2e-tests-${{ github.head_ref || github.ref }}
cancel-in-progress: true
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
changes:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
pull-requests: read
outputs:
skip: ${{ steps.decide.outputs.skip }}
projects: ${{ steps.decide.outputs.projects }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
list-files: json
filters: |
framework:
- 'packages/**'
- 'package.json'
- 'package-lock.json'
- 'tsconfig*.json'
- 'tests/e2e/**'
examples:
- 'examples/**'
shared:
- 'examples/shared/**'
website:
- 'website/**'
- name: Decide which projects to test
id: decide
env:
EXAMPLES_FILES: ${{ steps.filter.outputs.examples_files }}
run: |
# If framework, test infra, or shared example code changed, run all
if [ "${{ steps.filter.outputs.framework }}" == "true" ] || \
[ "${{ steps.filter.outputs.shared }}" == "true" ]; then
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "projects=all" >> "$GITHUB_OUTPUT"
exit 0
fi
# If website changed, include playground
website_projects="[]"
if [ "${{ steps.filter.outputs.website }}" == "true" ]; then
website_projects='["playground"]'
fi
# If examples changed, extract unique example directory names
example_projects="[]"
if [ "${{ steps.filter.outputs.examples }}" == "true" ]; then
example_projects=$(echo "$EXAMPLES_FILES" \
| jq -r '.[]' \
| sed -n 's|^examples/\([^/]*\)/.*|\1|p' \
| grep -v '^shared$' \
| sort -u \
| jq -R -s -c 'split("\n") | map(select(. != ""))')
fi
# Merge website + example projects
projects=$(jq -n -c --argjson a "$website_projects" --argjson b "$example_projects" '$a + $b | unique')
if [ "$projects" == "[]" ]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "projects=[]" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "projects=$projects" >> "$GITHUB_OUTPUT"
fi
discover:
needs: [changes]
if: |
always() &&
!(needs.changes.result == 'success' && needs.changes.outputs.skip == 'true')
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.find.outputs.projects }}
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: tests/e2e
sparse-checkout-cone-mode: false
- name: Find e2e test projects
id: find
run: |
# Get project names defined in the Playwright config (source of truth)
config_projects=$(grep -oP "name:\s*'[^']+'" tests/e2e/playwright.config.ts \
| sed "s/name: *'//;s/'$//" \
| jq -R -s -c 'split("\n") | map(select(. != ""))')
# Get all available spec files, then intersect with config projects
# This prevents orphan spec files from creating impossible matrix jobs
all_projects=$(find tests/e2e -maxdepth 1 -name '*.spec.ts' -printf '%f\n' \
| sed 's/\.spec\.ts$//' \
| jq -R -s -c 'split("\n") | map(select(. != ""))' \
| jq -c --argjson cfg "$config_projects" \
'[.[] | select(. as $s | $cfg | index($s))]')
requested='${{ needs.changes.outputs.projects }}'
# Push/dispatch (changes job skipped) or framework change → run all
if [ -z "$requested" ] || [ "$requested" == "all" ]; then
echo "projects=$all_projects" >> "$GITHUB_OUTPUT"
else
# Normalize underscores to hyphens, then intersect with available specs
projects=$(jq -n -c \
--argjson all "$all_projects" \
--argjson req "$requested" \
'$req | map(gsub("_"; "-")) | map(select(. as $r | $all | index($r))) | unique')
if [ "$projects" == "[]" ]; then
echo "projects=[]" >> "$GITHUB_OUTPUT"
else
echo "projects=$projects" >> "$GITHUB_OUTPUT"
fi
fi
echo "Will test: $(cat "$GITHUB_OUTPUT" | grep projects)"
build:
needs: [discover]
if: needs.discover.outputs.projects != '[]'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-dist
path: packages/*/dist
retention-days: 1
e2e-tests:
needs: [discover, build]
if: needs.discover.outputs.projects != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.discover.outputs.projects) }}
name: E2E — ${{ matrix.project }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-dist
path: packages
- name: Get Playwright version
id: pw-version
run: echo "version=$(npx playwright --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"
- name: Cache Playwright browsers
id: pw-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: playwright-${{ steps.pw-version.outputs.version }}-chromium
- name: Install Playwright browsers
if: steps.pw-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps chromium
- name: Install Playwright system deps
if: steps.pw-cache.outputs.cache-hit == 'true'
run: npx playwright install-deps chromium
- name: Run Playwright tests
run: npx playwright test --config=tests/e2e/playwright.config.ts --project=${{ matrix.project }}
env:
CI: true
E2E_PROJECT: ${{ matrix.project }}
- name: Upload test report
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report-${{ matrix.project }}
path: test-results/
retention-days: 7