Repository navigation
Expand file tree
/
Copy pathrelease-rust-python-package.yaml
More file actions
329 lines (300 loc) · 12.7 KB
/
Copy pathrelease-rust-python-package.yaml
File metadata and controls
329 lines (300 loc) · 12.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
name: Release Rust Python Package Plugin
on:
push:
tags:
- "*-v*"
workflow_call:
inputs:
tag:
description: "Release tag <slug>-v<version> at the workflow commit"
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 <slug>-v<version> at the workflow commit; dispatch on this tag"
required: true
type: string
repository:
description: "Target package repository"
required: true
default: testpypi
type: choice
options:
- testpypi
- pypi
publish_enabled:
description: "Whether to run the publish job"
required: false
default: true
type: boolean
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 }}
tag_on_main: ${{ steps.resolve.outputs.tag_on_main }}
skip: ${{ steps.resolve.outputs.skip }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
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}"
git check-ref-format "refs/tags/${tag}"
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}"
tag_sha="$(git rev-parse --verify "refs/tags/${tag}^{commit}")"
if [[ "${tag_sha}" != "${GITHUB_SHA}" ]]; then
echo "Release tag ${tag} does not match workflow commit ${GITHUB_SHA}; dispatch on the release tag" >&2
exit 1
fi
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" && "${PUBLISH_ENABLED}" == "false" ]]; then
echo "Validating unreleased tag ${tag} at PR commit ${GITHUB_SHA}"
else
echo "Release tag ${tag} does not exist" >&2
exit 1
fi
else
tag="${GITHUB_REF_NAME}"
repository="pypi"
fi
if git merge-base --is-ancestor "${GITHUB_SHA}" "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"])')"
language="$(printf '%s' "${release_info}" | python3 -c 'import json, sys; print(json.load(sys.stdin)["language"])')"
if [[ "${language}" != "rust" ]]; then
skip=true
wheel_matrix="[]"
elif [[ -n "${TAG_INPUT}" ]]; then
skip=false
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
skip=false
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 "tag_on_main=${tag_on_main}"
if [[ "${skip}" == "true" ]]; then
echo "skip=true"
else
echo "skip=false"
fi
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
if: needs.resolve.outputs.skip != 'true'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.12"
- name: Verify Rust toolchain
run: |
rustc --version
cargo --version
- name: Verify stubs are checked in
working-directory: ${{ needs.resolve.outputs.plugin_path }}
run: test -n "$(find . -name '*.pyi' -print -quit)"
build-wheel:
needs: [resolve, preflight]
if: needs.resolve.outputs.skip != 'true'
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.resolve.outputs.wheel_matrix) }}
runs-on: ${{ matrix.runner }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
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@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
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/real_cpex_imports.py" "${tmpdir}/tests/real_cpex_imports.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]
if: needs.resolve.outputs.skip != 'true'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
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@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
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/real_cpex_imports.py" "${tmpdir}/tests/real_cpex_imports.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.skip != 'true' && 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@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: dist
merge-multiple: true
- name: Publish distributions to TestPyPI
if: needs.resolve.outputs.publish_env == 'testpypi'
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
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@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
with:
packages-dir: dist/
skip-existing: true