Skip to content

Commit b83e652

Browse files
committed
Introduce reusable Python build workflow
Add a reusable workflow (.github/workflows/build-python-version.yml) that builds Python packages for Darwin, Android, Linux, and Windows and publishes release assets. Update build-python.yml to expose a workflow_dispatch input for selecting versions and to run the new workflow as a matrix over supported Python versions (3.12.12, 3.13.12, 3.14.3), inheriting secrets. This DRYs up per-version build logic and enables reuse via workflow_call.
1 parent 0a05ec7 commit b83e652

File tree

2 files changed

+205
-165
lines changed

2 files changed

+205
-165
lines changed
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
name: Build Python Packages (Reusable)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
python_version:
7+
description: Full Python version (e.g. 3.13.12)
8+
required: true
9+
type: string
10+
11+
env:
12+
PYTHON_VERSION: ${{ inputs.python_version }}
13+
PYTHON_DIST_RELEASE: 20260203 # https://github.com/astral-sh/python-build-standalone/releases
14+
15+
jobs:
16+
build-darwin:
17+
name: Build Python for iOS and macOS
18+
runs-on: macos-15
19+
permissions:
20+
contents: write
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
- name: Derive short Python version
26+
shell: bash
27+
run: |
28+
echo "PYTHON_VERSION_SHORT=$(echo "$PYTHON_VERSION" | cut -d. -f1,2)" >> "$GITHUB_ENV"
29+
30+
- name: Setup Python
31+
uses: actions/setup-python@v6
32+
with:
33+
python-version: ${{ env.PYTHON_VERSION_SHORT }}
34+
35+
- name: Show Python version
36+
run: python --version
37+
38+
- name: Build Python for iOS and macOS
39+
working-directory: darwin
40+
shell: bash
41+
run: |
42+
git clone --branch="$PYTHON_VERSION_SHORT" https://github.com/beeware/Python-Apple-support.git
43+
mkdir -p dist
44+
45+
pushd Python-Apple-support
46+
make iOS
47+
tar -czf ../dist/python-ios-mobile-forge-$PYTHON_VERSION_SHORT.tar.gz install support -C .
48+
make macOS
49+
popd
50+
51+
bash ./package-ios-for-dart.sh Python-Apple-support "$PYTHON_VERSION_SHORT"
52+
bash ./package-macos-for-dart.sh Python-Apple-support "$PYTHON_VERSION_SHORT"
53+
54+
- name: Upload Darwin build artifacts
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: python-darwin-${{ env.PYTHON_VERSION_SHORT }}
58+
path: darwin/dist/python-*.tar.gz
59+
if-no-files-found: error
60+
61+
build-android:
62+
name: Build Python for Android
63+
runs-on: ubuntu-latest
64+
permissions:
65+
contents: write
66+
steps:
67+
- uses: actions/checkout@v4
68+
- name: Derive short Python version
69+
shell: bash
70+
run: |
71+
echo "PYTHON_VERSION_SHORT=$(echo "$PYTHON_VERSION" | cut -d. -f1,2)" >> "$GITHUB_ENV"
72+
- uses: actions/setup-python@v5
73+
with:
74+
python-version: ${{ env.PYTHON_VERSION }}
75+
- run: python --version
76+
- working-directory: android
77+
shell: bash
78+
run: |
79+
bash ./build-all.sh "$PYTHON_VERSION"
80+
mkdir -p dist
81+
tar -czf dist/python-android-mobile-forge-$PYTHON_VERSION_SHORT.tar.gz install support
82+
bash ./package-for-dart.sh install "$PYTHON_VERSION" arm64-v8a
83+
bash ./package-for-dart.sh install "$PYTHON_VERSION" x86_64
84+
read version_major version_minor < <(echo "$PYTHON_VERSION" | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/')
85+
version_int=$((version_major * 100 + version_minor))
86+
if [ $version_int -lt 313 ]; then
87+
bash ./package-for-dart.sh install "$PYTHON_VERSION" armeabi-v7a
88+
fi
89+
- uses: actions/upload-artifact@v4
90+
with:
91+
name: python-android-${{ env.PYTHON_VERSION_SHORT }}
92+
path: android/dist/python-android-*.tar.gz
93+
if-no-files-found: error
94+
95+
build-linux:
96+
name: Build Python for Linux
97+
runs-on: ubuntu-latest
98+
permissions:
99+
contents: write
100+
steps:
101+
- uses: actions/checkout@v4
102+
- name: Derive short Python version
103+
shell: bash
104+
run: |
105+
echo "PYTHON_VERSION_SHORT=$(echo "$PYTHON_VERSION" | cut -d. -f1,2)" >> "$GITHUB_ENV"
106+
- working-directory: linux
107+
shell: bash
108+
run: |
109+
bash ./package-for-linux.sh x86_64 "_v2"
110+
bash ./package-for-linux.sh aarch64 ""
111+
- uses: actions/upload-artifact@v4
112+
with:
113+
name: python-linux-${{ env.PYTHON_VERSION_SHORT }}
114+
path: linux/python-linux-dart-*.tar.gz
115+
if-no-files-found: error
116+
117+
build-windows:
118+
name: Build Python for Windows
119+
runs-on: windows-2022
120+
permissions:
121+
contents: write
122+
steps:
123+
- uses: actions/checkout@v4
124+
- name: Derive short Python version
125+
shell: pwsh
126+
run: |
127+
$parts = "${{ env.PYTHON_VERSION }}".Split(".")
128+
"PYTHON_VERSION_SHORT=$($parts[0]).$($parts[1])" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
129+
- name: Setup Python
130+
uses: actions/setup-python@v6
131+
with:
132+
python-version: ${{ env.PYTHON_VERSION_SHORT }}
133+
- name: Show Python version
134+
shell: pwsh
135+
run: |
136+
python --version
137+
python -c "import sys; print(sys.executable)"
138+
- name: Build CPython from sources and package for Dart
139+
shell: pwsh
140+
run: |
141+
.\windows\package-for-dart.ps1 `
142+
-PythonVersion "${{ env.PYTHON_VERSION }}" `
143+
-PythonVersionShort "${{ env.PYTHON_VERSION_SHORT }}"
144+
- uses: actions/upload-artifact@v4
145+
with:
146+
name: python-windows-${{ env.PYTHON_VERSION_SHORT }}
147+
path: windows/python-windows-for-dart-*.zip
148+
if-no-files-found: error
149+
150+
publish-release:
151+
name: Publish Release Assets
152+
runs-on: ubuntu-latest
153+
needs:
154+
- build-darwin
155+
- build-android
156+
- build-linux
157+
- build-windows
158+
permissions:
159+
contents: write
160+
steps:
161+
- name: Derive short Python version
162+
shell: bash
163+
run: |
164+
echo "PYTHON_VERSION_SHORT=$(echo "$PYTHON_VERSION" | cut -d. -f1,2)" >> "$GITHUB_ENV"
165+
- name: Download all build artifacts
166+
uses: actions/download-artifact@v4
167+
with:
168+
pattern: python-*-${{ env.PYTHON_VERSION_SHORT }}
169+
path: release-artifacts
170+
merge-multiple: true
171+
172+
- name: Publish all artifacts to release
173+
uses: softprops/action-gh-release@v2
174+
with:
175+
tag_name: v${{ env.PYTHON_VERSION_SHORT }}
176+
files: release-artifacts/*
177+
fail_on_unmatched_files: true
178+
generate_release_notes: false
179+
draft: false
180+
prerelease: false

.github/workflows/build-python.yml

Lines changed: 25 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -5,170 +5,30 @@ on:
55
branches:
66
- '**'
77
workflow_dispatch:
8-
9-
env:
10-
PYTHON_VERSION: 3.12.12
11-
PYTHON_DIST_RELEASE: 20260203 # https://github.com/astral-sh/python-build-standalone/releases
8+
inputs:
9+
python_version:
10+
description: 'Version to build (all, 3.12.12, 3.13.12, 3.14.3)'
11+
required: true
12+
default: all
13+
type: choice
14+
options:
15+
- all
16+
- 3.12.12
17+
- 3.13.12
18+
- 3.14.3
1219

1320
jobs:
14-
build-darwin:
15-
name: Build Python for iOS and macOS
16-
runs-on: macos-15
17-
permissions:
18-
contents: write
19-
20-
steps:
21-
- name: Checkout
22-
uses: actions/checkout@v4
23-
- name: Derive short Python version
24-
shell: bash
25-
run: |
26-
echo "PYTHON_VERSION_SHORT=$(echo "$PYTHON_VERSION" | cut -d. -f1,2)" >> "$GITHUB_ENV"
27-
28-
- name: Setup Python
29-
uses: actions/setup-python@v6
30-
with:
31-
python-version: ${{ env.PYTHON_VERSION_SHORT }}
32-
33-
- name: Show Python version
34-
run: python --version
35-
36-
- name: Build Python for iOS and macOS
37-
working-directory: darwin
38-
shell: bash
39-
run: |
40-
git clone --branch="$PYTHON_VERSION_SHORT" https://github.com/beeware/Python-Apple-support.git
41-
mkdir -p dist
42-
43-
pushd Python-Apple-support
44-
make iOS
45-
tar -czf ../dist/python-ios-mobile-forge-$PYTHON_VERSION_SHORT.tar.gz install support -C .
46-
make macOS
47-
popd
48-
49-
bash ./package-ios-for-dart.sh Python-Apple-support "$PYTHON_VERSION_SHORT"
50-
bash ./package-macos-for-dart.sh Python-Apple-support "$PYTHON_VERSION_SHORT"
51-
52-
- name: Upload Darwin build artifacts
53-
uses: actions/upload-artifact@v4
54-
with:
55-
name: python-darwin
56-
path: darwin/dist/python-*.tar.gz
57-
if-no-files-found: error
58-
59-
build-android:
60-
name: Build Python for Android
61-
runs-on: ubuntu-latest
62-
permissions:
63-
contents: write
64-
steps:
65-
- uses: actions/checkout@v4
66-
- name: Derive short Python version
67-
shell: bash
68-
run: |
69-
echo "PYTHON_VERSION_SHORT=$(echo "$PYTHON_VERSION" | cut -d. -f1,2)" >> "$GITHUB_ENV"
70-
- uses: actions/setup-python@v5
71-
with:
72-
python-version: ${{ env.PYTHON_VERSION }}
73-
- run: python --version
74-
- working-directory: android
75-
shell: bash
76-
run: |
77-
bash ./build-all.sh "$PYTHON_VERSION"
78-
mkdir -p dist
79-
tar -czf dist/python-android-mobile-forge-$PYTHON_VERSION_SHORT.tar.gz install support
80-
bash ./package-for-dart.sh install "$PYTHON_VERSION" arm64-v8a
81-
bash ./package-for-dart.sh install "$PYTHON_VERSION" x86_64
82-
read version_major version_minor < <(echo "$PYTHON_VERSION" | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/')
83-
version_int=$((version_major * 100 + version_minor))
84-
if [ $version_int -lt 313 ]; then
85-
bash ./package-for-dart.sh install "$PYTHON_VERSION" armeabi-v7a
86-
fi
87-
- uses: actions/upload-artifact@v4
88-
with:
89-
name: python-android
90-
path: android/dist/python-android-*.tar.gz
91-
if-no-files-found: error
92-
93-
build-linux:
94-
name: Build Python for Linux
95-
runs-on: ubuntu-latest
96-
permissions:
97-
contents: write
98-
steps:
99-
- uses: actions/checkout@v4
100-
- working-directory: linux
101-
shell: bash
102-
run: |
103-
bash ./package-for-linux.sh x86_64 "_v2"
104-
bash ./package-for-linux.sh aarch64 ""
105-
- uses: actions/upload-artifact@v4
106-
with:
107-
name: python-linux
108-
path: linux/python-linux-dart-*.tar.gz
109-
if-no-files-found: error
110-
111-
build-windows:
112-
name: Build Python for Windows
113-
runs-on: windows-2022
114-
permissions:
115-
contents: write
116-
steps:
117-
- uses: actions/checkout@v4
118-
- name: Derive short Python version
119-
shell: pwsh
120-
run: |
121-
$parts = "${{ env.PYTHON_VERSION }}".Split(".")
122-
"PYTHON_VERSION_SHORT=$($parts[0]).$($parts[1])" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
123-
- name: Setup Python
124-
uses: actions/setup-python@v6
125-
with:
126-
python-version: ${{ env.PYTHON_VERSION_SHORT }}
127-
- name: Show Python version
128-
shell: pwsh
129-
run: |
130-
python --version
131-
python -c "import sys; print(sys.executable)"
132-
- name: Build CPython from sources and package for Dart
133-
shell: pwsh
134-
run: |
135-
.\windows\package-for-dart.ps1 `
136-
-PythonVersion "${{ env.PYTHON_VERSION }}" `
137-
-PythonVersionShort "${{ env.PYTHON_VERSION_SHORT }}"
138-
- uses: actions/upload-artifact@v4
139-
with:
140-
name: python-windows
141-
path: windows/python-windows-for-dart-*.zip
142-
if-no-files-found: error
143-
144-
publish-release:
145-
name: Publish Release Assets
146-
runs-on: ubuntu-latest
147-
needs:
148-
- build-darwin
149-
- build-android
150-
- build-linux
151-
- build-windows
152-
permissions:
153-
contents: write
154-
steps:
155-
- name: Derive short Python version
156-
shell: bash
157-
run: |
158-
echo "PYTHON_VERSION_SHORT=$(echo "$PYTHON_VERSION" | cut -d. -f1,2)" >> "$GITHUB_ENV"
159-
- name: Download all build artifacts
160-
uses: actions/download-artifact@v4
161-
with:
162-
pattern: python-*
163-
path: release-artifacts
164-
merge-multiple: true
165-
166-
- name: Publish all artifacts to release
167-
uses: softprops/action-gh-release@v2
168-
with:
169-
tag_name: v${{ env.PYTHON_VERSION_SHORT }}
170-
files: release-artifacts/*
171-
fail_on_unmatched_files: true
172-
generate_release_notes: false
173-
draft: false
174-
prerelease: false
21+
build-matrix:
22+
name: Build Python ${{ matrix.python_version }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
python_version:
27+
- 3.12.12
28+
- 3.13.12
29+
- 3.14.3
30+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.python_version == 'all' || github.event.inputs.python_version == matrix.python_version }}
31+
uses: ./.github/workflows/build-python-version.yml
32+
with:
33+
python_version: ${{ matrix.python_version }}
34+
secrets: inherit

0 commit comments

Comments
 (0)