-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (98 loc) · 3.7 KB
/
publish-testpypi.yml
File metadata and controls
118 lines (98 loc) · 3.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
name: Publish to TestPyPI
on:
workflow_dispatch:
push:
tags:
- 'v*'
jobs:
build:
name: Build distributions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install build tools
run: pip install --upgrade build
- name: Build and collect distributions
run: |
mkdir -p dist-all
for pkg_dir in packages/*/; do
pkg=$(basename "$pkg_dir")
echo "Building $pkg..."
cd "$pkg_dir"
python -m build --wheel --sdist
cp dist/* ../../dist-all/
cd ../..
done
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: distributions
path: dist-all/
publish-testpypi:
name: Publish to TestPyPI
needs: build
runs-on: ubuntu-latest
environment: testpypi
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: distributions
path: dist/
- name: Check for version changes vs TestPyPI
run: |
pip install requests packaging
python << 'EOF'
import os
import json
import requests
from pathlib import Path
from packaging import version
dist_dir = Path('dist')
errors = []
print("=" * 70)
print("CHECKING: Built versions vs TestPyPI published versions")
print("=" * 70)
for wheel in dist_dir.glob('*.whl'):
parts = wheel.name.split('-')
pkg_name = parts[0].replace('_', '-').lower()
pkg_version = parts[1]
print(f"\nChecking {pkg_name} (built: {pkg_version})...")
try:
response = requests.get(
f'https://test.pypi.org/pypi/{pkg_name}/json',
timeout=10
)
if response.status_code == 404:
print(f" [NEW] Not on TestPyPI yet (will publish)")
continue
elif response.status_code != 200:
print(f" [WARN] TestPyPI API error: {response.status_code}")
continue
pypi_data = response.json()
pypi_versions = list(pypi_data['releases'].keys())
latest_pypi = max(pypi_versions, key=version.parse) if pypi_versions else None
if pkg_version in pypi_versions:
print(f" [EXISTS] Version {pkg_version} already on TestPyPI")
print(f" [INFO] TestPyPI: Allowing re-publish for testing")
else:
print(f" [NEW VERSION] {pkg_version} (will publish)")
if latest_pypi:
print(f" Latest on TestPyPI: {latest_pypi}")
except requests.RequestException as e:
print(f" [WARN] Could not check TestPyPI: {e}")
print("\n" + "=" * 70)
print("[PASSED] TESTPYPI CHECK PASSED (proceeding with publication)")
print("Note: TestPyPI allows re-publishing same versions for testing")
EOF
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true