-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (184 loc) · 6.25 KB
/
Copy pathpublish-witwin.yml
File metadata and controls
210 lines (184 loc) · 6.25 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
name: Build and publish witwin
on:
push:
branches:
- main
- "codex/**"
pull_request:
release:
types: [published]
workflow_dispatch:
jobs:
validate_release:
if: github.event_name != 'release' || (startsWith(github.event.release.tag_name, 'witwin-v') && !github.event.release.prerelease)
name: Validate release
runs-on: ubuntu-latest
outputs:
package_dir: ${{ steps.package_dir.outputs.path }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Resolve package directory
id: package_dir
shell: bash
run: |
if [ -f pyproject.toml ]; then
echo "path=." >> "$GITHUB_OUTPUT"
elif [ -f core/pyproject.toml ]; then
echo "path=core" >> "$GITHUB_OUTPUT"
else
echo "Unable to find pyproject.toml for the witwin package." >&2
exit 1
fi
- name: Validate release tag and package version
if: github.event_name == 'release'
shell: bash
env:
PACKAGE_DIR: ${{ steps.package_dir.outputs.path }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
python - <<'PY'
import os
import re
import sys
import tomllib
from pathlib import Path
tag = os.environ["RELEASE_TAG"]
match = re.fullmatch(r"witwin-v(?P<version>[0-9A-Za-z.+_-]+)", tag)
if match is None:
print(f"Release tag '{tag}' must match 'witwin-v<version>'.", file=sys.stderr)
raise SystemExit(1)
expected_version = match.group("version")
pyproject_path = Path(os.environ["PACKAGE_DIR"]) / "pyproject.toml"
project = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))["project"]
if project["name"] != "witwin":
print(f"Expected package name 'witwin', found '{project['name']}'.", file=sys.stderr)
raise SystemExit(1)
if project["version"] != expected_version:
print(
f"Release tag version '{expected_version}' does not match "
f"pyproject version '{project['version']}'.",
file=sys.stderr,
)
raise SystemExit(1)
PY
build_wheel:
name: Build pure Python wheel
needs: validate_release
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Build wheel
shell: bash
env:
PACKAGE_DIR: ${{ needs.validate_release.outputs.package_dir }}
run: |
python -m pip install --upgrade pip build
python -m build --wheel "$PACKAGE_DIR"
- name: Verify pure Python wheel
shell: bash
env:
PACKAGE_DIR: ${{ needs.validate_release.outputs.package_dir }}
run: |
python - <<'PY'
import os
import zipfile
from pathlib import Path
wheels = list((Path(os.environ["PACKAGE_DIR"]) / "dist").glob("*.whl"))
assert len(wheels) == 1, wheels
wheel = wheels[0]
assert wheel.name.endswith("-py3-none-any.whl"), wheel.name
native_suffixes = (".c", ".cc", ".cpp", ".cxx", ".cu", ".cuh", ".h", ".hpp", ".so", ".pyd", ".dll")
native = [
name for name in zipfile.ZipFile(wheel).namelist()
if name.lower().endswith(native_suffixes)
]
assert not native, native
PY
- name: Upload wheel artifact
uses: actions/upload-artifact@v4
with:
name: wheel
path: ${{ needs.validate_release.outputs.package_dir }}/dist/*.whl
if-no-files-found: error
build_sdist:
name: Build source distribution
needs: validate_release
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Build source distribution
shell: bash
env:
PACKAGE_DIR: ${{ needs.validate_release.outputs.package_dir }}
run: |
python -m pip install --upgrade pip build
python -m build --sdist "$PACKAGE_DIR"
- name: Verify pure Python source distribution
shell: bash
env:
PACKAGE_DIR: ${{ needs.validate_release.outputs.package_dir }}
run: |
python - <<'PY'
import os
import tarfile
from pathlib import Path
archives = list((Path(os.environ["PACKAGE_DIR"]) / "dist").glob("*.tar.gz"))
assert len(archives) == 1, archives
native_suffixes = (".c", ".cc", ".cpp", ".cxx", ".cu", ".cuh", ".h", ".hpp")
with tarfile.open(archives[0]) as archive:
native = [
member.name for member in archive.getmembers()
if member.isfile() and member.name.lower().endswith(native_suffixes)
]
assert not native, native
PY
- name: Upload source distribution artifact
uses: actions/upload-artifact@v4
with:
name: sdist
path: ${{ needs.validate_release.outputs.package_dir }}/dist/*.tar.gz
if-no-files-found: error
publish:
name: Publish to PyPI
if: github.event_name == 'release'
needs:
- build_wheel
- build_sdist
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
environment:
name: pypi
url: https://pypi.org/project/witwin/
steps:
- name: Download wheel artifact
uses: actions/download-artifact@v4
with:
name: wheel
path: dist
- name: Download source distribution artifact
uses: actions/download-artifact@v4
with:
name: sdist
path: dist
- name: Publish distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
skip-existing: true