-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease-rust-python-package.yaml
More file actions
312 lines (281 loc) · 11.7 KB
/
release-rust-python-package.yaml
File metadata and controls
312 lines (281 loc) · 11.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
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
name: Release Rust Python Package Plugin
on:
push:
tags:
- "*-v*"
workflow_call:
inputs:
tag:
description: "Release tag in the form <slug>-v<version>"
required: true
type: string
repository:
description: "Target package repository"
required: true
type: string
publish_enabled:
description: "Whether to run the publish job"
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
tag:
description: "Release tag in the form <slug>-v<version>"
required: true
type: string
repository:
description: "Target package repository"
required: true
default: testpypi
type: choice
options:
- testpypi
- pypi
permissions:
contents: read
jobs:
resolve:
runs-on: ubuntu-latest
outputs:
plugin: ${{ steps.resolve.outputs.plugin }}
slug: ${{ steps.resolve.outputs.plugin }}
plugin_path: ${{ steps.resolve.outputs.plugin_path }}
wheel_matrix: ${{ steps.resolve.outputs.wheel_matrix }}
publish_env: ${{ steps.resolve.outputs.publish_env }}
publish_enabled: ${{ steps.resolve.outputs.publish_enabled }}
checkout_ref: ${{ steps.resolve.outputs.checkout_ref }}
tag_on_main: ${{ steps.resolve.outputs.tag_on_main }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
with:
python-version: "3.12"
- name: Validate plugin catalog
run: python3 tools/plugin_catalog.py validate .
- id: resolve
shell: bash
env:
TAG_INPUT: ${{ inputs.tag }}
REPOSITORY_INPUT: ${{ inputs.repository }}
PUBLISH_ENABLED: ${{ inputs.publish_enabled }}
run: |
set -euo pipefail
git fetch --force origin "refs/heads/main:refs/remotes/origin/main"
if [[ -n "${TAG_INPUT}" ]]; then
tag="${TAG_INPUT}"
repository="${REPOSITORY_INPUT}"
if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null 2>&1; then
git fetch --force origin "refs/tags/${tag}:refs/tags/${tag}"
git show-ref --verify --quiet "refs/tags/${tag}"
checkout_ref="refs/tags/${tag}"
tag_ref="refs/tags/${tag}"
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" && "${PUBLISH_ENABLED}" == "false" ]]; then
checkout_ref="${GITHUB_SHA}"
tag_ref="${GITHUB_SHA}"
else
echo "Release tag ${tag} does not exist" >&2
exit 1
fi
else
tag="${GITHUB_REF_NAME}"
repository="pypi"
checkout_ref="${GITHUB_REF}"
tag_ref="${GITHUB_REF}"
fi
if git merge-base --is-ancestor "${tag_ref}" "refs/remotes/origin/main"; then
tag_on_main=true
else
tag_on_main=false
fi
release_info="$(python3 tools/plugin_catalog.py release-info . "${tag}")"
plugin="$(printf '%s' "${release_info}" | python3 -c 'import json, sys; print(json.load(sys.stdin)["slug"])')"
plugin_path="$(printf '%s' "${release_info}" | python3 -c 'import json, sys; print(json.load(sys.stdin)["path"])')"
if [[ -n "${TAG_INPUT}" ]]; then
wheel_matrix="$(python3 -c 'import json; print(json.dumps([{"runner":"ubuntu-latest","platform":"linux-x86_64"},{"runner":"ubuntu-24.04-arm","platform":"linux-aarch64"},{"runner":"ubuntu-24.04-s390x","platform":"linux-s390x"},{"runner":"ubuntu-24.04-ppc64le","platform":"linux-ppc64le"},{"runner":"macos-latest","platform":"macos-arm64"},{"runner":"windows-latest","platform":"windows-x86_64"}]))')"
else
wheel_matrix="$(printf '%s' "${release_info}" | python3 -c 'import json, sys; print(json.dumps(json.load(sys.stdin)["release_wheel_matrix"]))')"
fi
{
echo "plugin=${plugin}"
echo "plugin_path=${plugin_path}"
echo "wheel_matrix=${wheel_matrix}"
echo "checkout_ref=${checkout_ref}"
echo "tag_on_main=${tag_on_main}"
if [[ "${PUBLISH_ENABLED}" == "false" ]]; then
echo "publish_enabled=false"
else
echo "publish_enabled=true"
fi
if [[ "${repository}" == "testpypi" ]]; then
echo "publish_env=testpypi"
else
echo "publish_env=pypi"
fi
} >> "$GITHUB_OUTPUT"
preflight:
needs: resolve
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
ref: ${{ needs.resolve.outputs.checkout_ref }}
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
with:
python-version: "3.12"
- name: Verify Rust toolchain
run: |
rustc --version
cargo --version
- name: Generate stubs
working-directory: ${{ needs.resolve.outputs.plugin_path }}
run: cargo run --bin stub_gen
- name: Verify generated stubs are checked in
working-directory: ${{ needs.resolve.outputs.plugin_path }}
run: git diff --exit-code
build-wheel:
needs: [resolve, preflight]
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.resolve.outputs.wheel_matrix) }}
runs-on: ${{ matrix.runner }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
ref: ${{ needs.resolve.outputs.checkout_ref }}
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
if: ${{ matrix.runner != 'ubuntu-24.04-s390x' && matrix.runner != 'ubuntu-24.04-ppc64le' }}
with:
python-version: "3.12"
- name: Install system Python on partner runners
if: ${{ matrix.runner == 'ubuntu-24.04-s390x' || matrix.runner == 'ubuntu-24.04-ppc64le' }}
run: |
sudo apt-get update
sudo apt-get install -y python3.12 python3.12-dev python3.12-venv python3-pip
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
python_bin_dir="${RUNNER_TEMP}/python-bin"
mkdir -p "${python_bin_dir}"
ln -sf "$(which python3.12)" "${python_bin_dir}/python"
export PATH="${python_bin_dir}:$PATH"
echo "${python_bin_dir}" >> "$GITHUB_PATH"
python --version
python -m pip --version
- name: Verify Rust toolchain
run: |
rustc --version
cargo --version
- name: Install uv
run: python -m pip install uv==0.9.30 maturin==1.12.6
- name: Build wheel
working-directory: ${{ needs.resolve.outputs.plugin_path }}
run: uv run maturin build --release --out dist
- name: Upload wheel artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f
with:
name: wheel-${{ matrix.platform }}
path: ${{ needs.resolve.outputs.plugin_path }}/dist/*.whl
- name: Test built wheel in isolated virtualenv
working-directory: ${{ needs.resolve.outputs.plugin_path }}
run: |
tmpdir="$(mktemp -d)"
python -m venv "${tmpdir}/venv"
venv_python="${tmpdir}/venv/bin/python"
if [[ ! -f "${venv_python}" ]]; then
venv_python="${tmpdir}/venv/Scripts/python.exe"
fi
uv pip install --python "${venv_python}" --group dev PyYAML
"${venv_python}" -m pip install dist/*.whl
if [[ -d "${GITHUB_WORKSPACE}/plugins/tests/${{ needs.resolve.outputs.slug }}" ]]; then
mkdir -p "${tmpdir}/tests"
cp -R "${GITHUB_WORKSPACE}/plugins/tests/${{ needs.resolve.outputs.slug }}" "${tmpdir}/tests/${{ needs.resolve.outputs.slug }}"
cp "${GITHUB_WORKSPACE}/plugins/tests/conftest.py" "${tmpdir}/tests/conftest.py"
cp "${GITHUB_WORKSPACE}/plugins/tests/plugin_hooks.py" "${tmpdir}/tests/plugin_hooks.py"
cp "${GITHUB_WORKSPACE}/plugins/tests/pytest.ini" "${tmpdir}/pytest.ini"
cd "${tmpdir}"
export CPEX_TEST_PLUGIN_HOOKS=1
export PYTHONPATH="${tmpdir}/tests"
"${venv_python}" -m pytest \
-c "${tmpdir}/pytest.ini" \
"${tmpdir}/tests/${{ needs.resolve.outputs.slug }}" -v
fi
build-sdist:
needs: [resolve, preflight]
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
ref: ${{ needs.resolve.outputs.checkout_ref }}
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
with:
python-version: "3.12"
- name: Install uv
run: python -m pip install uv==0.9.30 maturin==1.12.6
- name: Build sdist
working-directory: ${{ needs.resolve.outputs.plugin_path }}
run: uv run maturin sdist --out dist
- name: Upload sdist artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f
with:
name: sdist
path: ${{ needs.resolve.outputs.plugin_path }}/dist/*.tar.gz
- name: Test built sdist in isolated virtualenv
working-directory: ${{ needs.resolve.outputs.plugin_path }}
run: |
tmpdir="$(mktemp -d)"
python -m venv "${tmpdir}/venv"
venv_python="${tmpdir}/venv/bin/python"
if [[ ! -f "${venv_python}" ]]; then
venv_python="${tmpdir}/venv/Scripts/python.exe"
fi
uv pip install --python "${venv_python}" --group dev PyYAML
"${venv_python}" -m pip install dist/*.tar.gz
if [[ -d "${GITHUB_WORKSPACE}/plugins/tests/${{ needs.resolve.outputs.slug }}" ]]; then
mkdir -p "${tmpdir}/tests"
cp -R "${GITHUB_WORKSPACE}/plugins/tests/${{ needs.resolve.outputs.slug }}" "${tmpdir}/tests/${{ needs.resolve.outputs.slug }}"
cp "${GITHUB_WORKSPACE}/plugins/tests/conftest.py" "${tmpdir}/tests/conftest.py"
cp "${GITHUB_WORKSPACE}/plugins/tests/plugin_hooks.py" "${tmpdir}/tests/plugin_hooks.py"
cp "${GITHUB_WORKSPACE}/plugins/tests/pytest.ini" "${tmpdir}/pytest.ini"
cd "${tmpdir}"
export CPEX_TEST_PLUGIN_HOOKS=1
export PYTHONPATH="${tmpdir}/tests"
"${venv_python}" -m pytest \
-c "${tmpdir}/pytest.ini" \
"${tmpdir}/tests/${{ needs.resolve.outputs.slug }}" -v
fi
publish:
if: ${{ needs.resolve.outputs.publish_enabled == 'true' && (needs.resolve.outputs.publish_env != 'pypi' || needs.resolve.outputs.tag_on_main == 'true') }}
needs: [resolve, build-wheel, build-sdist]
runs-on: ubuntu-latest
environment: ${{ needs.resolve.outputs.publish_env }}
permissions:
id-token: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131
with:
path: dist
merge-multiple: true
- name: Publish distributions to TestPyPI
if: needs.resolve.outputs.publish_env == 'testpypi'
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e
with:
packages-dir: dist/
repository-url: https://test.pypi.org/legacy/
skip-existing: true
- name: Publish distributions to PyPI
if: needs.resolve.outputs.publish_env == 'pypi'
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e
with:
packages-dir: dist/
skip-existing: true