Skip to content

Commit d2b42be

Browse files
authored
Use a consistent default Python version for profiling (#938)
1 parent 877d619 commit d2b42be

File tree

3 files changed

+72
-12
lines changed

3 files changed

+72
-12
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Latest Supported Python
2+
description: Fetch the highest minor version of Python with a wheel in the latest release on PyPI
3+
inputs:
4+
github-token:
5+
description: The token to use for the GitHub API
6+
required: true
7+
outputs:
8+
version:
9+
description: The highest minor version of Python with a wheel
10+
value: ${{ steps.python-version.outputs.version }}
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Fetch latest release on GitHub
16+
id: latest-release
17+
env:
18+
GH_TOKEN: ${{ inputs.github-token }}
19+
shell: bash
20+
run: |-
21+
latest_release=$(
22+
gh api "repos/${{ github.repository }}/releases/latest" \
23+
--jq '.tag_name'
24+
)
25+
echo "Latest release: $latest_release"
26+
echo "tag=$latest_release" >> $GITHUB_OUTPUT
27+
28+
- name: Fetch latest release on PyPI
29+
id: python-version
30+
shell: bash
31+
run: |-
32+
python_version=$(
33+
curl -s "https://pypi.org/pypi/msgspec/${{ steps.latest-release.outputs.tag }}/json" \
34+
| jq -r '
35+
[ .urls[]
36+
| select(.packagetype == "bdist_wheel")
37+
| .filename
38+
| capture("cp(?<cp>[0-9]+)").cp
39+
| tonumber
40+
]
41+
| max
42+
| "3.\(tostring | .[1:])"
43+
'
44+
)
45+
echo "Python version: $python_version"
46+
echo "version=$python_version" >> $GITHUB_OUTPUT

.github/workflows/ci.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ on:
3131
- published
3232

3333
jobs:
34-
validate:
34+
prepare:
3535
name: Run static analysis and prepare build
3636
runs-on: ubuntu-latest
3737

3838
outputs:
3939
sdist-name: "${{ steps.build-sdist.outputs.file-name }}"
40+
latest-supported-python: "${{ steps.latest-supported-python.outputs.version }}"
4041

4142
steps:
4243
- name: Checkout code
@@ -81,10 +82,16 @@ jobs:
8182
path: dist/${{ steps.build-sdist.outputs.file-name }}
8283
if-no-files-found: error
8384

85+
- name: Fetch latest supported Python
86+
id: latest-supported-python
87+
uses: ./.github/actions/latest-supported-python
88+
with:
89+
github-token: "${{ github.token }}"
90+
8491
test:
8592
name: Test Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
8693
needs:
87-
- validate
94+
- prepare
8895
runs-on: "${{ matrix.os }}"
8996
strategy:
9097
fail-fast: false
@@ -214,7 +221,7 @@ jobs:
214221
name: Build wheels on ${{ matrix.os }} for ${{ matrix.archs }}
215222
needs:
216223
- test
217-
- validate
224+
- prepare
218225
runs-on: "${{ matrix.os }}"
219226
strategy:
220227
fail-fast: false
@@ -256,7 +263,7 @@ jobs:
256263
uses: pypa/cibuildwheel@v3.2.1
257264
with:
258265
config-file: .cibuildwheel.toml
259-
package-dir: dist/${{ needs.validate.outputs.sdist-name }}
266+
package-dir: dist/${{ needs.prepare.outputs.sdist-name }}
260267
env:
261268
CIBW_ARCHS: "${{ matrix.archs }}"
262269

@@ -268,18 +275,20 @@ jobs:
268275
if-no-files-found: error
269276

270277
profile:
271-
name: Run profiling tests
278+
name: Run profiling tests on Python ${{ needs.prepare.outputs.latest-supported-python }}
272279
needs:
280+
- prepare
273281
- build-wheels
274282
uses: ./.github/workflows/profile.yml
275283
with:
276284
version: dev
285+
python: "${{ needs.prepare.outputs.latest-supported-python }}"
277286

278287
upload-pypi:
279288
name: Upload artifacts to PyPI
280289
if: github.event_name == 'release' && github.event.action == 'published'
281290
needs:
282-
- validate
291+
- prepare
283292
- build-wheels
284293
runs-on: ubuntu-latest
285294
permissions:

.github/workflows/profile.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
python:
1111
description: Minor version of Python to use for profiling
1212
type: string
13-
default: latest
1413
workflow_call:
1514
inputs:
1615
version:
@@ -20,7 +19,6 @@ on:
2019
python:
2120
description: Minor version of Python to use for profiling
2221
type: string
23-
default: latest
2422

2523
jobs:
2624
profile:
@@ -61,14 +59,21 @@ jobs:
6159
- name: Install command runner
6260
run: uv tool install rust-just
6361

62+
- name: Fetch latest supported Python
63+
if: inputs.python == ''
64+
id: latest-supported-python
65+
uses: ./.github/actions/latest-supported-python
66+
with:
67+
github-token: "${{ github.token }}"
68+
6469
- name: Set profiling environment metadata
6570
id: metadata
6671
shell: bash
6772
run: |-
73+
python_version="${{ inputs.python || steps.latest-supported-python.outputs.version }}"
74+
echo "UV_PYTHON=$python_version" >> $GITHUB_ENV
75+
echo "python-version=$python_version" >> $GITHUB_OUTPUT
6876
echo "env-path=$(just env-path prof)" >> $GITHUB_OUTPUT
69-
if [[ "${{ inputs.python }}" != "latest" ]]; then
70-
echo "UV_PYTHON=${{ inputs.python }}" >> $GITHUB_ENV
71-
fi
7277
7378
- name: Install profiling dependencies
7479
env:
@@ -91,5 +96,5 @@ jobs:
9196
${{ format('msgspec{0}{1}', inputs.version != 'dev' && '==' || '', inputs.version != 'dev' && inputs.version || '') }}
9297
9398
# TODO: set up infra to commit results after each merge and then make tests compare
94-
- name: Run profiling tests
99+
- name: Run profiling tests on Python ${{ steps.metadata.outputs.python-version }}
95100
run: just test-perf all --calibrate --rounds 10000

0 commit comments

Comments
 (0)