Skip to content

Commit 0b080a0

Browse files
committed
Move job selection to an external script
1 parent fc09b3d commit 0b080a0

File tree

5 files changed

+83
-12
lines changed

5 files changed

+83
-12
lines changed

.github/workflows/build-release.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ permissions: {}
4242
# Set from inputs for workflow_dispatch, or set defaults to test push/PR events
4343
env:
4444
GIT_REMOTE: ${{ github.event.inputs.git_remote || 'mhsmith' }}
45-
GIT_COMMIT: ${{ github.event.inputs.git_commit || 'c9700e47b6bf98f6ca2e60ecdbee15ba228dcc7c' }}
46-
CPYTHON_RELEASE: ${{ github.event.inputs.cpython_release || '3.15.992' }}
45+
GIT_COMMIT: ${{ github.event.inputs.git_commit || '7e87375eeff06e03a66209e506ce83c3f70ec57f' }}
46+
CPYTHON_RELEASE: ${{ github.event.inputs.cpython_release || '3.15.0b991' }}
4747

4848
jobs:
4949
verify-input:
5050
runs-on: ubuntu-24.04
5151
timeout-minutes: 5
5252
outputs:
53-
# Needed because env vars are not available in "if" conditions
54-
cpython_release: ${{ env.CPYTHON_RELEASE }}
55-
cpython_branch: ${{ steps.get-branch.outputs.branch }}
53+
build-docs: ${{ steps.select-jobs.outputs.docs }}
54+
build-android: ${{ steps.select-jobs.outputs.android }}
5655
steps:
5756
- name: "Workflow run information"
5857
run: |
@@ -75,10 +74,18 @@ jobs:
7574
exit 1
7675
fi
7776
78-
- name: "Get CPython branch"
79-
id: get-branch
77+
- name: "Setup Python"
78+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
79+
with:
80+
python-version: 3.12
81+
82+
- name: "Install dependencies"
83+
run: python -m pip install --no-deps -r requirements.txt
84+
85+
- name: "Select jobs"
86+
id: select-jobs
8087
run: |
81-
echo "branch=$(echo "$CPYTHON_RELEASE" | cut -d . -f 1-2)" >> "$GITHUB_OUTPUT"
88+
./select-jobs.py "$CPYTHON_RELEASE" >> "$GITHUB_OUTPUT"
8289
8390
build-source:
8491
runs-on: ubuntu-24.04
@@ -126,9 +133,7 @@ jobs:
126133
timeout-minutes: 45
127134
needs:
128135
- verify-input
129-
130-
# Docs aren't built for alpha or beta releases.
131-
if: (!(contains(needs.verify-input.outputs.cpython_release, 'a') || contains(needs.verify-input.outputs.cpython_release, 'b')))
136+
if: fromJSON(needs.verify-input.outputs.build-docs)
132137
steps:
133138
- name: "Checkout ${{ env.GIT_REMOTE }}/cpython"
134139
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -200,7 +205,7 @@ jobs:
200205
name: build-android (${{ matrix.arch }})
201206
needs:
202207
- verify-input
203-
if: fromJSON(needs.verify-input.outputs.cpython_branch) >= 3.14
208+
if: fromJSON(needs.verify-input.outputs.build-android)
204209

205210
strategy:
206211
matrix:

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ alive_progress>=3.3.0
55
python-gnupg
66
aiohttp
77
blurb>=1.2.1
8+
packaging
89
sigstore>=3

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ multidict==6.1.0 \
562562
# aiohttp
563563
# grpclib
564564
# yarl
565+
packaging==23.2 \
566+
--hash=sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7
567+
# via -r requirements.in
565568
paramiko==3.5.1 \
566569
--hash=sha256:43b9a0501fc2b5e70680388d9346cf252cfb7d00b0667c39e80eb43a408b8f61
567570
# via -r requirements.in

select_jobs.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
5+
from packaging.version import Version
6+
7+
8+
def output(key: str, value: bool) -> None:
9+
print(f"{key}={str(value).lower()}")
10+
11+
12+
def main() -> None:
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument("version", type=Version)
15+
args = parser.parse_args()
16+
version = args.version
17+
18+
# Docs are only built for stable releases or release candidates.
19+
output("docs", version.pre is None or version.pre[0] == "rc")
20+
21+
# Android binary releases began in Python 3.14.
22+
output("android", version.release >= (3, 14))
23+
24+
25+
if __name__ == "__main__":
26+
main()

tests/test_select_jobs.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sys
2+
from textwrap import dedent
3+
4+
import pytest
5+
6+
import select_jobs
7+
8+
9+
@pytest.mark.parametrize(
10+
("version", "docs", "android"),
11+
[
12+
("3.13.0a1", "false", "false"),
13+
("3.13.0rc1", "true", "false"),
14+
("3.13.0", "true", "false"),
15+
("3.13.1", "true", "false"),
16+
("3.14.0a1", "false", "true"),
17+
("3.14.0rc1", "true", "true"),
18+
("3.14.0", "true", "true"),
19+
("3.14.1", "true", "true"),
20+
],
21+
)
22+
def test_select_jobs(
23+
version: str,
24+
docs: str,
25+
android: str,
26+
monkeypatch: pytest.MonkeyPatch,
27+
capsys: pytest.CaptureFixture[str],
28+
) -> None:
29+
monkeypatch.setattr(sys, "argv", ["select_jobs.py", version])
30+
select_jobs.main()
31+
assert capsys.readouterr().out == dedent(
32+
f"""\
33+
docs={docs}
34+
android={android}
35+
"""
36+
)

0 commit comments

Comments
 (0)