-
Notifications
You must be signed in to change notification settings - Fork 1.3k
390 lines (337 loc) · 12.5 KB
/
ux-tests.yml
File metadata and controls
390 lines (337 loc) · 12.5 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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
name: Tests
# Two test tiers:
#
# 1. unit-tests — Fast (~30s), no infrastructure. Runs test/unit/ and test/cmd/
# on every push. Catches logic bugs in decorators, CLI, parsers, etc.
#
# 2. ux-tests — Full integration across 4 backends (local, argo, airflow, sfn).
# Needs devstack (minikube + tilt). Catches orchestrator/deployer bugs.
#
# Both tiers auto-discover tests by directory — new test files are picked up
# automatically without editing this workflow.
#
# Coverage is collected from each job, then combined in a final report.
on:
push:
branches:
- master
- "npow/**" # run on this dev branch during development
pull_request:
branches:
- master
workflow_dispatch:
jobs:
unit-tests:
name: "Unit Tests"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-py3.9-${{ hashFiles('setup.py', 'setup.cfg') }}
restore-keys: pip-py3.9-
- name: Install Metaflow and test dependencies
run: |
pip install --upgrade pip
pip install -e ".[dev]" pytest-timeout pytest-cov
- name: Run unit and command tests
run: |
python -m pytest \
test/unit/ test/cmd/ test/plugins/ \
--ignore=test/unit/spin \
-v \
--tb=short \
--timeout=120 \
--cov=metaflow \
--cov-report=term-missing \
--cov-report=xml:coverage.xml \
--cov-branch \
--junit-xml=junit-unit.xml
- name: Upload coverage data
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-unit
path: |
.coverage
coverage.xml
if-no-files-found: ignore
include-hidden-files: true
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: junit-unit
path: junit-unit.xml
if-no-files-found: ignore
- name: Publish test results
if: always()
continue-on-error: true
uses: dorny/test-reporter@d61b558e8df85cb60d09ca3e5b09653b4477cea7 # v1
with:
name: "Test Results — Unit"
path: junit-unit.xml
reporter: java-junit
fail-on-error: false
ux-tests:
name: "${{ matrix.backend }}"
strategy:
fail-fast: false
matrix:
include:
- backend: local
services: "minio,postgresql,metadata-service"
workers: 4
- backend: argo-kubernetes
services: "minio,postgresql,metadata-service,argo-workflows"
workers: 1
- backend: airflow-kubernetes
services: "minio,postgresql,metadata-service,airflow"
workers: 1
- backend: sfn-batch
services: "minio,postgresql,metadata-service,localbatch,ddb-local,sfn-local"
workers: 2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-py3.9-${{ hashFiles('setup.py', 'setup.cfg') }}
restore-keys: pip-py3.9-
- name: Install Metaflow and test dependencies
run: |
pip install --upgrade pip
pip install -e ".[dev]" pytest-xdist pytest-timeout pytest-cov pytest-rerunfailures
pip install "git+https://github.com/npow/localbatch.git@main#egg=localbatch"
- name: Set up minikube
uses: medyagh/setup-minikube@aba8d5ff1666c72adf94ccd078b2ca12e7756382
with:
driver: docker
cpus: 2
memory: 4096
- name: Restore minikube image cache
id: image-cache
uses: actions/cache/restore@v4
with:
path: /tmp/minikube-image-cache
key: minikube-images-${{ matrix.backend }}-${{ hashFiles('devtools/Tiltfile') }}
restore-keys: minikube-images-${{ matrix.backend }}-
- name: Pre-load cached images into minikube
if: steps.image-cache.outputs.cache-hit == 'true'
run: devtools/ci/load-minikube-images.sh
- name: Cache Helm repos and charts
uses: actions/cache@v4
with:
path: |
~/.cache/helm
~/.local/share/tilt-dev/.helm
key: helm-charts-${{ matrix.backend }}-${{ hashFiles('devtools/Tiltfile', 'devtools/tilt/*.tiltfile') }}
restore-keys: |
helm-charts-${{ matrix.backend }}-
helm-charts-
- name: Set up Helm
uses: azure/setup-helm@v4
- name: Cache Tilt binary
id: tilt-cache
uses: actions/cache@v4
with:
path: /usr/local/bin/tilt
key: tilt-v0.33.11
- name: Install Tilt
if: steps.tilt-cache.outputs.cache-hit != 'true'
run: |
for attempt in 1 2 3; do
curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh \
| VERSION=v0.33.11 bash && break
echo "Tilt install attempt $attempt failed, retrying in 10s..."
sleep 10
done
tilt version
- name: Pre-pull Helm repos (with retry)
run: |
retry() {
local cmd="$*" attempt=1
until $cmd; do
attempt=$((attempt + 1))
if [ $attempt -gt 3 ]; then echo "Failed after 3 attempts: $cmd"; return 1; fi
echo "Retry $attempt for: $cmd"
sleep $((attempt * 5))
done
}
retry helm repo add bitnami https://charts.bitnami.com/bitnami 2>/dev/null || true
retry helm repo add argo https://argoproj.github.io/argo-helm 2>/dev/null || true
retry helm repo add apache-airflow https://airflow.apache.org 2>/dev/null || true
retry helm repo add metaflow-tools https://outerbounds.github.io/metaflow-tools 2>/dev/null || true
retry helm repo update || true
- name: Start devstack
working-directory: devtools
run: ci/start-devstack.sh
env:
SERVICES: ${{ matrix.services }}
- name: Wait for test image to be loaded into minikube
if: matrix.backend != 'local' && matrix.backend != 'sfn-batch'
run: |
tilt wait --for=condition=Ready uiresource/build-test-image --timeout=300s
- name: Save minikube images to cache
if: steps.image-cache.outputs.cache-hit != 'true'
run: devtools/ci/save-minikube-images.sh
- name: Store minikube image cache
if: steps.image-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: /tmp/minikube-image-cache
key: minikube-images-${{ matrix.backend }}-${{ hashFiles('devtools/Tiltfile') }}
- name: Start minikube tunnel
run: |
sudo minikube tunnel &
sleep 5
- name: Forward devstack ports to Docker bridge (sfn-batch only)
if: matrix.backend == 'sfn-batch'
run: devtools/ci/forward-bridge-ports.sh
- name: Wait for Airflow REST API
if: matrix.backend == 'airflow-kubernetes'
run: devtools/ci/wait-airflow-api.sh
- name: Clean up completed pods and start background cleanup
if: matrix.backend == 'argo-kubernetes' || matrix.backend == 'airflow-kubernetes'
run: |
kubectl delete pods --field-selector=status.phase=Succeeded --all-namespaces 2>/dev/null || true
kubectl delete pods --field-selector=status.phase=Failed --all-namespaces 2>/dev/null || true
# Periodically clean up completed pods during test runs to free cluster resources
while true; do
sleep 60
kubectl delete pods --field-selector=status.phase=Succeeded --all-namespaces 2>/dev/null || true
kubectl delete pods --field-selector=status.phase=Failed --all-namespaces 2>/dev/null || true
done &
- name: Run UX tests — ${{ matrix.backend }}
run: |
AWS_SHARED_CREDENTIALS_FILE="" \
PYTHONPATH=$PWD \
python -m pytest \
test/ux/core/ \
--only-backend "${{ matrix.backend }}" \
-n ${{ matrix.workers }} \
-v \
--tb=short \
--timeout=1800 \
--reruns 1 \
--reruns-delay 10 \
--cov=metaflow \
--cov-report=term-missing \
--cov-report=xml:coverage.xml \
--cov-report=html:htmlcov \
--cov-branch \
--junit-xml=junit-${{ matrix.backend }}.xml
- name: Upload coverage data
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.backend }}
path: |
.coverage
coverage.xml
htmlcov/
if-no-files-found: ignore
include-hidden-files: true
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: junit-${{ matrix.backend }}
path: junit-${{ matrix.backend }}.xml
if-no-files-found: ignore
- name: Publish test results
if: always()
continue-on-error: true
uses: dorny/test-reporter@d61b558e8df85cb60d09ca3e5b09653b4477cea7 # v1
with:
name: "Test Results — ${{ matrix.backend }}"
path: junit-${{ matrix.backend }}.xml
reporter: java-junit
fail-on-error: false
- name: Dump sfn-batch diagnostics on failure
if: failure() && matrix.backend == 'sfn-batch'
run: devtools/ci/dump-sfn-diagnostics.sh
- name: Dump Airflow diagnostics on failure
if: failure() && matrix.backend == 'airflow-kubernetes'
run: devtools/ci/dump-airflow-diagnostics.sh
- name: Show Tilt logs on failure
if: failure()
run: cat /tmp/tilt.log | tail -200 || true
- name: Upload Tilt logs
if: always()
uses: actions/upload-artifact@v4
with:
name: tilt-logs-${{ matrix.backend }}
path: /tmp/tilt.log
if-no-files-found: ignore
coverage-report:
name: "Coverage Report"
needs: [unit-tests, ux-tests]
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install coverage
run: pip install coverage[toml]
- name: Download coverage data from all backends
uses: actions/download-artifact@v4
with:
pattern: coverage-*
path: coverage-artifacts/
- name: Download test results from all backends
uses: actions/download-artifact@v4
with:
pattern: junit-*
path: junit-artifacts/
- name: Publish combined test results
continue-on-error: true
uses: dorny/test-reporter@d61b558e8df85cb60d09ca3e5b09653b4477cea7 # v1
with:
name: "Test Results — All Backends"
path: "junit-artifacts/**/*.xml"
reporter: java-junit
fail-on-error: false
- name: Combine coverage data
run: devtools/ci/combine-coverage.sh
- name: Generate combined HTML report
run: |
coverage html -d combined-htmlcov/ --title="Metaflow UX Test Coverage"
coverage xml -o combined-coverage.xml
- name: Post coverage summary
run: |
echo "## Test Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
coverage report --sort=miss >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
total=$(coverage report | tail -1 | awk '{print $NF}')
echo "**Total coverage: $total**" >> $GITHUB_STEP_SUMMARY
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: combined-coverage.xml
name: ux-combined
- name: Upload combined coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-combined
path: |
combined-htmlcov/
combined-coverage.xml