-
Notifications
You must be signed in to change notification settings - Fork 535
215 lines (182 loc) · 7.28 KB
/
build_wheel_on_windows.yml
File metadata and controls
215 lines (182 loc) · 7.28 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
name: Build and Test PyPi Wheels on Windows
on:
push:
branches: [ "main", "feat/win-compilation-test" ]
workflow_call:
inputs:
publish_target:
description: 'Publish Destination'
required: true
default: 'testpypi'
type: string
workflow_dispatch:
inputs:
publish_target:
description: 'Publish Destination'
required: true
default: 'testpypi'
type: choice
options:
- testpypi
- pypi
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || '' }}-${{ github.base_ref || '' }}-${{ github.ref != 'refs/heads/main' || github.sha }}
cancel-in-progress: true
permissions:
contents: read
jobs:
compute_matrix:
name: Determine matrix to run on
runs-on: linux_x64
outputs:
matrix: ${{ steps.main.outputs.matrix }}
steps:
- id: main
run: |
PLATFORMS=("windows-g9i" "windows-amd" "windows-2025" "windows-2022")
PYTHON_VERSIONS=("3.10" "3.11" "3.12" "3.13" "3.14")
JSON_ARRAY="["
for p in "${PLATFORMS[@]}"; do
for v in "${PYTHON_VERSIONS[@]}"; do
JSON_ARRAY+="{\"platform\":\"$p\",\"python-version\":\"$v\"},"
done
done
# Remove the trailing comma and close the bracket
JSON_ARRAY="${JSON_ARRAY%,}]"
# Wrap in the "include" key and send to GITHUB_OUTPUT
RESULT="{\"include\":$JSON_ARRAY}"
echo "matrix=$RESULT" >> "$GITHUB_OUTPUT"
build_wheels_windows_2025:
name: Build wheels on windows-2025 (x64)
runs-on: windows-g9i
steps:
- name: Show env info
run: |
Get-CimInstance -ClassName Win32_Processor
where cl
& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -all -products * -prerelease -format json
shell: powershell
- name: Checkout code
uses: actions/checkout@v6
with:
submodules: recursive
- name: Cleanup left marker files
run: |
git submodule foreach --recursive 'git reset --hard && git clean -ffdx'
- name: Set up Python (for cibuildwheel controller)
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install cibuildwheel
run: |
pip install --upgrade pip
pip install cibuildwheel==3.4.0
- name: Add Git bin to PATH
run: echo "C:\Program Files\Git\usr\bin" >> $GITHUB_PATH
shell: bash
# Cache the directory where cibuildwheel outputs the .whl files
- name: Cache built wheels
id: cache-wheels
uses: actions/cache@v4
with:
path: wheelhouse
# IMPORTANT: Update these file extensions/paths to match the source files
# that actually affect your compiled wheel (e.g., .c, .cpp, .rs, .py)
key: ${{ runner.os }}-wheels-${{ hashFiles('**/pyproject.toml', '**/setup.py', '**/*.py', '**/*.c', '**/*.cpp') }}
- name: Build wheels using cibuildwheel
if: steps.cache-wheels.outputs.cache-hit != 'true'
shell: powershell
run: |
python -m cibuildwheel --output-dir wheelhouse
# - name: Install and test wheel
# shell: powershell
# run: |
# # cp11
# $wheels = Get-ChildItem wheelhouse/*.whl | Select-Object -First 2
# $wheelPath = $wheels.FullName
#
# python -m venv test_env
# $venvPython = "test_env/Scripts/python.exe"
# & $venvPython -m pip install --upgrade pip
# & $venvPython -m pip install $wheelPath
# & $venvPython -c "import zvec; print('Import OK:', zvec.__version__)"
- name: Log wheel variables
shell: powershell
run: |
$wheels = Get-ChildItem wheelhouse/*.whl | Select-Object -ExpandProperty FullName
if ($env:GITHUB_STEP_SUMMARY) {
$wheels | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
}
"wheels=$($wheels -join ' ')" | Out-File -FilePath $env:GITHUB_ENV -Append
$wheels = Get-ChildItem wheelhouse/*.whl | Select-Object -ExpandProperty FullName
if ($env:GITHUB_STEP_SUMMARY) {
$wheels | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
}
"wheels=$($wheels -join ' ')" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Upload built wheels
uses: actions/upload-artifact@v4
with:
name: windows-wheels
path: wheelhouse/*.whl
publish_wheels:
name: Publish wheels
runs-on: windows-g9i
needs: build_wheels_windows_2025
steps:
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Publish to PyPI/TestPyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ inputs.publish_target == 'pypi' && secrets.PYPI_API_TOKEN || secrets.TEST_PYPI_API_TOKEN }}
TWINE_REPOSITORY_URL: ${{ inputs.publish_target == 'pypi' && 'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/' }}
run: |
pip install twine
twine upload --skip-existing --verbose wheelhouse/*.whl
smoke_test:
needs: [ publish_wheels, compute_matrix ]
strategy:
fail-fast: false
max-parallel: 4
matrix: ${{ fromJson(needs.compute_matrix.outputs.matrix) }}
runs-on: ${{ matrix.platform }}
steps:
- name: Smoke test from PyPI
shell: powershell
env:
PUBLISH_TARGET: ${{ inputs.publish_target || 'testpypi' }}
run: |
$wheel = (Get-ChildItem wheelhouse/zvec-*.whl)[1] # cp311
$filename = $wheel.Name
$version = [regex]::Match($filename, '^zvec-([^-]+)-').Groups[1].Value
if ($env:PUBLISH_TARGET -eq 'testpypi') {
$indexArgs = @("--index-url", "https://test.pypi.org/simple/", "--extra-index-url", "https://pypi.org/simple/")
Write-Host "Waiting for zvec==$version to become available on TestPyPI..."
} else {
$indexArgs = @()
Write-Host "Waiting for zvec==$version to become available on PyPI..."
}
$ErrorActionPreference = 'Continue'
$PSNativeCommandUseErrorActionPreference = $false
$found = $false
for ($i = 1; $i -le 30; $i++) {
python -m pip install @indexArgs --dry-run "zvec==$version" 1>$null 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "Version $version is available."
$found = $true
break
}
Write-Host "Attempt $i/30: not yet available, retrying in 10s..."
Start-Sleep -Seconds 10
}
if (-not $found) {
Write-Host "ERROR: Timed out waiting for zvec==$version."
exit 1
}
python -m venv test_env
$venvPython = "test_env/Scripts/python.exe"
& $venvPython -m pip install --upgrade pip
& $venvPython -m pip install @indexArgs "zvec==$version"
& $venvPython -c "import zvec; print('Import OK:', zvec.__version__)"