-
Notifications
You must be signed in to change notification settings - Fork 0
206 lines (180 loc) · 7.54 KB
/
Copy pathpublish-python.yml
File metadata and controls
206 lines (180 loc) · 7.54 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
name: publish-python
on:
push:
tags:
- "v*"
- "py-aikernel-cuda13-libtorch2-12-win-x64-*"
workflow_dispatch:
inputs:
channel:
description: Publish channel
required: true
default: stable
type: choice
options:
- stable
- dev
version:
description: Python package version
required: true
default: 0.1.0
managed_package_version:
description: AIKernel managed dependency version
required: true
default: 0.1.0
release_tag:
description: GitHub Release tag for dev wheels
required: false
default: v0.1.0-python-dev
libtorch_path:
description: Path to LibTorch 2.12.0 + CUDA 13.0 on the self-hosted Windows runner
required: true
default: runtime/win-x64/libtorch
permissions:
contents: write
jobs:
build-python:
name: Build Python wheel
runs-on: [self-hosted, Windows, X64, CUDA13]
outputs:
channel: ${{ steps.meta.outputs.channel }}
defaults:
run:
working-directory: python
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve publish metadata
id: meta
shell: pwsh
run: |
$channel = "${{ github.event.inputs.channel }}"
if ([string]::IsNullOrWhiteSpace($channel)) {
$channel = "stable"
}
$version = "${{ github.event.inputs.version }}"
if ([string]::IsNullOrWhiteSpace($version)) {
$tag = "${{ github.ref_name }}"
if ($tag.StartsWith("v")) {
$version = $tag.Substring(1)
} elseif ($tag -match "(\d+\.\d+\.\d+(?:[A-Za-z0-9.\-]*)?)$") {
$version = $Matches[1]
} else {
throw "Unable to resolve Python package version from tag '$tag'."
}
}
$managedPackageVersion = "${{ github.event.inputs.managed_package_version }}"
if ([string]::IsNullOrWhiteSpace($managedPackageVersion)) {
$managedPackageVersion = $version
}
$releaseTag = "${{ github.event.inputs.release_tag }}"
if ([string]::IsNullOrWhiteSpace($releaseTag)) {
$releaseTag = "${{ github.ref_name }}"
}
$libtorchPath = "${{ github.event.inputs.libtorch_path }}"
if ([string]::IsNullOrWhiteSpace($libtorchPath)) {
$libtorchPath = "runtime/win-x64/libtorch"
}
"channel=$channel" >> $env:GITHUB_OUTPUT
"version=$version" >> $env:GITHUB_OUTPUT
"managed_package_version=$managedPackageVersion" >> $env:GITHUB_OUTPUT
"release_tag=$releaseTag" >> $env:GITHUB_OUTPUT
"libtorch_path=$libtorchPath" >> $env:GITHUB_OUTPUT
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build tools
run: py -m pip install --upgrade build twine pytest
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Configure native bridge
working-directory: ..
env:
AIKERNEL_LIBTORCH_PATH: ${{ steps.meta.outputs.libtorch_path }}
run: cmake -S native -B native/build/win-x64 -A x64
- name: Build native bridge
working-directory: ..
env:
AIKERNEL_LIBTORCH_PATH: ${{ steps.meta.outputs.libtorch_path }}
run: cmake --build native/build/win-x64 --config Release
- name: Restore managed capability
working-directory: ..
run: dotnet restore AIKernel.Cuda13.0.Libtorch2.12.win-x64.slnx -p:AIKernelPackageVersion=${{ steps.meta.outputs.managed_package_version }}
- name: Build managed capability
working-directory: ..
run: dotnet build AIKernel.Cuda13.0.Libtorch2.12.win-x64.slnx -c Release --no-restore -p:Version=${{ steps.meta.outputs.managed_package_version }} -p:AIKernelPackageVersion=${{ steps.meta.outputs.managed_package_version }}
- name: Stage lightweight binaries
shell: pwsh
run: |
New-Item -ItemType Directory -Force src/aikernel_cuda13_libtorch2_12_win_x64/managed | Out-Null
New-Item -ItemType Directory -Force src/aikernel_cuda13_libtorch2_12_win_x64/native/win-x64 | Out-Null
Copy-Item ../src/AIKernel.Cuda13.0.Libtorch2.12.win-x64/bin/Release/net10.0/AIKernel.Cuda13.0.Libtorch2.12.win-x64.dll src/aikernel_cuda13_libtorch2_12_win_x64/managed/
Copy-Item ../native/build/win-x64/Release/libtorch_bridge.dll src/aikernel_cuda13_libtorch2_12_win_x64/native/win-x64/
- name: Apply package channel and version
shell: pwsh
run: |
$pyproject = Get-Content pyproject.toml -Raw
$init = Get-Content src/aikernel_cuda13_libtorch2_12_win_x64/__init__.py -Raw
if ("${{ steps.meta.outputs.channel }}" -eq "dev") {
$pyproject = $pyproject -replace 'name = "aikernel-cuda13-libtorch2-12-win-x64"', 'name = "aikernel-cuda13-libtorch2-12-win-x64-dev"'
$init = $init -replace 'PACKAGE_NAME = "aikernel-cuda13-libtorch2-12-win-x64"', 'PACKAGE_NAME = "aikernel-cuda13-libtorch2-12-win-x64-dev"'
}
$pyproject = $pyproject -replace 'version = "[^"]+"', 'version = "${{ steps.meta.outputs.version }}"'
$init = $init -replace '__version__ = "[^"]+"', '__version__ = "${{ steps.meta.outputs.version }}"'
Set-Content pyproject.toml -Value $pyproject -NoNewline
Set-Content src/aikernel_cuda13_libtorch2_12_win_x64/__init__.py -Value $init -NoNewline
- name: Test Python package
run: py -m pytest
- name: Build wheel
run: py -m build --wheel
- name: Check wheel
run: py -m twine check dist/*
- name: Upload stable wheel artifact
if: steps.meta.outputs.channel == 'stable'
uses: actions/upload-artifact@v4
with:
name: pypi-dist-aikernel-cuda13-libtorch2-12-win-x64
path: python/dist/*
if-no-files-found: error
- name: Upload development wheel to GitHub Release
if: steps.meta.outputs.channel == 'dev'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.meta.outputs.release_tag }}
prerelease: true
files: python/dist/*
body: |
Development Python wheel for AIKernel CUDA Capability tooling.
Stable Python packages are published to PyPI. This GitHub Release
asset is intended for CI/CD and compatibility testing.
publish-stable-python:
name: Publish stable wheel to PyPI
runs-on: ubuntu-latest
needs: build-python
if: needs.build-python.outputs.channel == 'stable'
environment:
name: pypi
permissions:
contents: read
id-token: write
steps:
- name: Download stable wheel artifact
uses: actions/download-artifact@v4
with:
name: pypi-dist-aikernel-cuda13-libtorch2-12-win-x64
path: dist
- name: Show trusted publisher claims
run: |
echo "PyPI project: aikernel-cuda13-libtorch2-12-win-x64"
echo "Expected owner: AIKernel-NET"
echo "Expected repository: AIKernel.Cuda13.0"
echo "Expected workflow: publish-python.yml"
echo "Expected environment: pypi"
echo "Actual repository: ${GITHUB_REPOSITORY}"
echo "Actual workflow ref: ${GITHUB_WORKFLOW_REF}"
echo "Actual ref: ${GITHUB_REF}"
- name: Publish distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1