-
Notifications
You must be signed in to change notification settings - Fork 0
665 lines (561 loc) · 19.4 KB
/
Copy pathtest-python-setup-uv.yml
File metadata and controls
665 lines (561 loc) · 19.4 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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
name: Test python-setup/uv
on:
push:
branches: [main]
jobs:
test-uv-basic:
name: Test uv action - defaults (core only)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project with uv
run: |
# Create pyproject.toml
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-basic"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[dependency-groups]
dev = ["httpx"]
EOF
# Initialize uv and create lock file
pip install uv
uv lock
- name: Test uv action with defaults (no groups)
uses: ./actions/python-setup/uv
- name: Verify installations
shell: bash
run: |
python --version
uv --version
uv pip list
# Verify core dependency is installed
python -c "import requests; print('[OK] Core dependency installed')"
# Verify dev group is NOT installed (default is now empty)
if python -c "import httpx" 2>/dev/null; then
echo "[ERROR] httpx should not be installed"
exit 1
else
echo "[OK] Dev group not installed with default empty install-groups"
fi
test-uv-custom-groups:
name: Test uv action - Custom install groups
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project with multiple groups
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-groups"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[dependency-groups]
dev = ["httpx"]
test = ["pytest-cov", "pytest-mock"]
docs = ["mkdocs"]
EOF
pip install uv
uv lock
- name: Test uv action with custom groups
uses: ./actions/python-setup/uv
with:
install-groups: 'groups: test docs'
- name: Verify custom groups installed
shell: bash
run: |
uv pip list
# Verify core dependencies are installed
python -c "import requests; print('[OK] Core dependencies installed')"
# Verify test and docs groups are installed
python -c "import pytest_cov; import pytest_mock; print('[OK] Test dependencies installed')"
python -c "import mkdocs; print('[OK] Docs dependencies installed')"
# Verify dev group is NOT installed
if python -c "import httpx" 2>/dev/null; then
echo "[ERROR] httpx should not be installed"
exit 1
else
echo "[OK] Dev group not installed as expected"
fi
test-uv-no-groups:
name: Test uv action - No groups (core only)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-no-groups"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[dependency-groups]
dev = ["httpx"]
EOF
pip install uv
uv lock
- name: Test uv action with empty groups
uses: ./actions/python-setup/uv
with:
install-groups: ''
- name: Verify only core dependencies
shell: bash
run: |
uv pip list
# Verify core dependency is installed
python -c "import requests; print('[OK] Core dependency installed')"
# Verify dev group is NOT installed
if python -c "import httpx" 2>/dev/null; then
echo "[ERROR] httpx should not be installed"
exit 1
else
echo "[OK] No optional groups installed"
fi
test-uv-lock-verification:
name: Test uv action - Lock file verification
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project with up-to-date lock
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-lock"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[dependency-groups]
dev = ["httpx"]
EOF
pip install uv
uv lock
- name: Test uv action with lock verification enabled (default)
uses: ./actions/python-setup/uv
- name: Verify lock check passed
shell: bash
run: |
echo "[OK] Lock verification passed"
test-uv-lock-verification-disabled:
name: Test uv action - Lock verification disabled
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project with potentially outdated lock
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-no-verify"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[dependency-groups]
dev = ["httpx"]
EOF
pip install uv
uv lock
- name: Test uv action with lock verification disabled
uses: ./actions/python-setup/uv
with:
verify-lock: 'false'
- name: Verify installation succeeded
shell: bash
run: |
uv pip list
python -c "import requests; print('[OK] Dependencies installed without lock verification')"
test-uv-lock-verification-fail:
name: Test uv action - Lock verification failure
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project with outdated lock
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-lock-fail"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests==2.28.0"]
[dependency-groups]
dev = ["httpx"]
EOF
pip install uv
uv lock
# Modify pyproject.toml to make lock outdated
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-lock-fail"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests==2.31.0"]
[dependency-groups]
dev = ["httpx"]
EOF
- name: Test uv action with outdated lock (should fail)
id: test-lock-fail
continue-on-error: true
uses: ./actions/python-setup/uv
- name: Verify action failed as expected
shell: bash
run: |
if [ "${{ steps.test-lock-fail.outcome }}" != "failure" ]; then
echo "::error::Expected action to fail when lock file is outdated"
exit 1
fi
echo "[OK] Action correctly failed when lock file is outdated"
test-uv-matrix:
name: Test uv action - Matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.10', '3.11', '3.12']
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project
shell: bash
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-matrix"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = ["requests"]
[dependency-groups]
dev = ["httpx"]
EOF
pip install uv
uv lock
- name: Test uv action with Python ${{ matrix.python-version }}
uses: ./actions/python-setup/uv
with:
python-version: ${{ matrix.python-version }}
install-groups: 'groups: dev'
- name: Verify Python version
shell: bash
run: |
python --version
python -c "import sys; assert sys.version_info[:2] == tuple(map(int, '${{ matrix.python-version }}'.split('.')[:2]))"
uv pip list
- name: Test uv functionality
shell: bash
run: |
python -c "import requests; import httpx; print(f'[OK] Python ${{ matrix.python-version }} working on ${{ matrix.os }}')"
test-uv-cache:
name: Test uv action - Cache functionality
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-cache"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests", "numpy"]
[dependency-groups]
dev = ["httpx", "mypy"]
EOF
pip install uv
uv lock
- name: First run - populate cache
uses: ./actions/python-setup/uv
- name: Verify cache populated
shell: bash
run: |
uv pip list
echo "[OK] Cache should be populated for subsequent runs"
test-uv-multiple-groups:
name: Test uv action - Multiple dependency groups
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-multiple"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[dependency-groups]
dev = ["httpx"]
test = ["pytest-cov"]
docs = ["mkdocs"]
EOF
pip install uv
uv lock
- name: Test uv action with multiple dependency groups
uses: ./actions/python-setup/uv
with:
install-groups: 'groups: dev test docs'
- name: Verify all groups installed
shell: bash
run: |
python -c "import httpx; import pytest_cov; import mkdocs; print('[OK] All multiple groups installed')"
test-uv-no-dependency-groups-section:
name: Test uv action - No dependency-groups section
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project without dependency-groups
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-no-groups-section"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
EOF
pip install uv
uv lock
- name: Test uv action with defaults (should work - no groups)
uses: ./actions/python-setup/uv
- name: Verify action succeeded with core dependencies only
shell: bash
run: |
python -c "import requests; print('[OK] Core dependencies installed without dependency-groups section')"
uv pip list
echo "[OK] Action succeeded without dependency-groups section"
test-uv-explicit-dev-group:
name: Test uv action - Explicit dev group
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-explicit-dev"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[dependency-groups]
dev = ["httpx"]
EOF
pip install uv
uv lock
- name: Test uv action with explicit dev group
uses: ./actions/python-setup/uv
with:
install-groups: 'groups: dev'
- name: Verify dev group installed
shell: bash
run: |
python -c "import httpx; print('[OK] Dev group explicitly installed')"
test-uv-empty-sections:
name: Test uv action - Empty groups/extras sections
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-empty"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[project.optional-dependencies]
aws = ["boto3"]
[dependency-groups]
dev = ["httpx"]
EOF
pip install uv
uv lock
- name: Test uv action with empty groups section
uses: ./actions/python-setup/uv
with:
install-groups: 'groups: , extras: aws'
- name: Verify empty groups handling
shell: bash
run: |
uv pip list
python -c "import requests; print('[OK] Core dependencies installed')"
python -c "import boto3; print('[OK] AWS extra installed')"
test-uv-invalid-format:
name: Test uv action - Invalid format handling
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-invalid"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
EOF
pip install uv
uv lock
- name: Test uv action with invalid format (should show warning)
uses: ./actions/python-setup/uv
with:
install-groups: 'invalid format without colons'
- name: Verify warning shown and core dependencies installed
shell: bash
run: |
uv pip list
python -c "import requests; print('[OK] Core dependencies installed despite invalid format')"
test-uv-optional-dependencies:
name: Test uv action - Optional dependencies (extras)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project with optional dependencies
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-extras"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[project.optional-dependencies]
aws = ["boto3", "s3fs"]
viz = ["matplotlib", "seaborn"]
[dependency-groups]
dev = ["httpx"]
test = ["pytest"]
EOF
pip install uv
uv lock
- name: Test uv action with optional dependencies only
uses: ./actions/python-setup/uv
with:
install-groups: 'extras: aws viz'
- name: Verify optional dependencies installed
shell: bash
run: |
uv pip list
# Verify core dependencies are installed
python -c "import requests; print('[OK] Core dependencies installed')"
# Verify optional dependencies are installed
python -c "import boto3; import s3fs; print('[OK] AWS extras installed')"
python -c "import matplotlib; import seaborn; print('[OK] Viz extras installed')"
# Verify dev group is NOT installed
if python -c "import httpx" 2>/dev/null; then
echo "[ERROR] httpx should not be installed"
exit 1
else
echo "[OK] Dev group not installed as expected"
fi
test-uv-mixed-groups-and-extras:
name: Test uv action - Mixed groups and extras
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Create test project
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-mixed"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[project.optional-dependencies]
aws = ["boto3"]
viz = ["matplotlib"]
[dependency-groups]
dev = ["httpx"]
test = ["pytest"]
EOF
pip install uv
uv lock
- name: Test uv action with mixed groups and extras
uses: ./actions/python-setup/uv
with:
install-groups: 'groups: dev test, extras: aws viz'
- name: Verify mixed installation
shell: bash
run: |
uv pip list
# Verify all requested dependencies are installed
python -c "import requests; print('[OK] Core dependencies installed')"
python -c "import httpx; print('[OK] Dev group installed')"
python -c "import pytest; print('[OK] Test group installed')"
python -c "import boto3; print('[OK] AWS extra installed')"
python -c "import matplotlib; print('[OK] Viz extra installed')"
test-uv-custom-version:
name: Test uv action - Custom uv version input
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
# Pin to the PREVIOUS published uv release (one below latest), resolved at
# runtime so the test never goes stale. It must differ from what the action
# installs by default ('latest'); otherwise the assertion would pass even if
# the version input were silently dropped. The lock is generated with the
# same pinned uv, guaranteeing --frozen / uv lock --check compatibility.
- name: Resolve the previous (non-latest) uv release to pin
id: pin
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ver=""
for attempt in 1 2 3; do
ver="$(gh api 'repos/astral-sh/uv/releases?per_page=20' \
--jq 'map(select(.prerelease == false and .draft == false)) | .[1].tag_name' \
2>/dev/null | sed 's/^v//')"
if [ -n "$ver" ] && [ "$ver" != "null" ]; then break; fi
echo "gh api attempt $attempt returned no version; retrying in 5s..."
sleep 5
done
if [ -z "$ver" ] || [ "$ver" = "null" ]; then
echo "::error::Could not resolve the previous uv release from GitHub after retries"
exit 1
fi
echo "Pinning uv version (previous release, != latest): $ver"
echo "uv_version=$ver" >> "$GITHUB_OUTPUT"
- name: Create test project and lock with the pinned uv
run: |
cat > pyproject.toml << 'EOF'
[project]
name = "test-uv-version"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["requests"]
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
[tool.setuptools]
py-modules = []
EOF
pip install "uv==${{ steps.pin.outputs.uv_version }}"
uv lock
- name: Test uv action pinned to a specific version
uses: ./actions/python-setup/uv
with:
version: ${{ steps.pin.outputs.uv_version }}
- name: Verify the requested uv version was installed
shell: bash
run: |
installed="$(uv --version | awk '{print $2}')"
expected="${{ steps.pin.outputs.uv_version }}"
echo "Installed uv: $installed (expected $expected)"
if [ "$installed" != "$expected" ]; then
echo "::error::version input not honored: expected uv $expected, got $installed"
exit 1
fi
echo "[OK] version input honored: uv $installed installed"