Skip to content

Commit ef8dab6

Browse files
committed
ci: derive Python versions from pyproject.toml requires-python
Replace hardcoded Python version matrix with a resolve-python job that reads requires-python from pyproject.toml. Tests run on min (from pyproject.toml) and max (runner's latest CPython). Lint runs on max only.
1 parent 2a3b234 commit ef8dab6

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,36 @@ permissions:
1010
contents: read
1111

1212
jobs:
13+
resolve-python:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
min-version: ${{ steps.resolve.outputs.min }}
17+
max-version: ${{ steps.resolve.outputs.max }}
18+
matrix: ${{ steps.resolve.outputs.matrix }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- id: resolve
23+
run: |
24+
MIN=$(python3 -c "
25+
import re
26+
with open('pyproject.toml') as f:
27+
m = re.search(r'requires-python\s*=\s*\">=(\d+\.\d+)\"', f.read())
28+
print(m.group(1) if m else '3.9')
29+
")
30+
# Latest stable CPython minor version
31+
MAX=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
32+
if [ "$MIN" = "$MAX" ]; then
33+
MATRIX="[\"$MIN\"]"
34+
else
35+
MATRIX="[\"$MIN\", \"$MAX\"]"
36+
fi
37+
echo "min=$MIN" >> "$GITHUB_OUTPUT"
38+
echo "max=$MAX" >> "$GITHUB_OUTPUT"
39+
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
40+
1341
lint:
42+
needs: resolve-python
1443
runs-on: ubuntu-latest
1544
steps:
1645
- uses: actions/checkout@v4
@@ -21,7 +50,7 @@ jobs:
2150

2251
- uses: actions/setup-python@v5
2352
with:
24-
python-version: "3.11"
53+
python-version: ${{ needs.resolve-python.outputs.max-version }}
2554

2655
- run: uv sync --frozen --extra dev
2756

@@ -30,11 +59,11 @@ jobs:
3059
- run: uv run ruff format --check .
3160

3261
test:
33-
needs: lint
62+
needs: [resolve-python, lint]
3463
runs-on: ubuntu-latest
3564
strategy:
3665
matrix:
37-
python-version: ["3.9", "3.11"]
66+
python-version: ${{ fromJson(needs.resolve-python.outputs.matrix) }}
3867
steps:
3968
- uses: actions/checkout@v4
4069

0 commit comments

Comments
 (0)