Skip to content

Commit 863473e

Browse files
committed
cicd/lib-build-and-push: isolate CIBW_BUILD logic
1 parent 15078fb commit 863473e

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

.github/workflows/lib-build-and-push.yml

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ on:
2525
required: false
2626
default: 'cp2* cp35* cp36* cp37* *i686 *musllinux*'
2727

28+
target-wheels-python-versions:
29+
type: string
30+
description: "List of python version to build wheels for, to be translated to CIBW_BUILD env"
31+
required: false
32+
default: 3.8 3.9 3.10 3.11 3.12 3.13
33+
2834
env:
2935
CIBW_TEST_COMMAND_LINUX: >
3036
pytest {project}/tests/unit &&
@@ -139,33 +145,68 @@ jobs:
139145
run: |
140146
brew install libev
141147
142-
- name: Overwrite for Linux 64
143-
if: runner.os == 'Linux' && matrix.platform == 'x86_64'
148+
- name: Prepare CIBW_BUILD for Linux and MacOS
149+
if: runner.os == 'Linux' || runner.os == 'MacOS'
150+
run: |
151+
pre=""
152+
post=""
153+
154+
if [[ "${{ matrix.platform }}" == "PyPy" ]]; then
155+
# Will convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `pp311* pp312* pp313*`
156+
pre="pp"
157+
post="*"
158+
elif [[ "${{ matrix.platform }}" == "all" ]]; then
159+
# Convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `cp311* cp312* cp313*`
160+
pre="cp"
161+
post="*"
162+
elif [[ "${{ matrix.platform }}" == "x86_64" ]]; then
163+
# Convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `cp311*x86_64 cp312*x86_64 cp313*x86_64`
164+
pre="cp"
165+
post="*x86_64"
166+
else
167+
echo "Unknown target platfor '${{ matrix.platform }}'"
168+
exit 1
169+
fi
170+
171+
CIBW_BUILD=""
172+
for item in `echo "${{ inputs.target-wheels-python-versions }}" | tr " " "\n"`; do
173+
CIBW_BUILD="${CIBW_BUILD} ${pre}${item//.}${post}"
174+
done
175+
echo "Resulted CIBW_BUILD: $CIBW_BUILD"
176+
echo "CIBW_BUILD=$CIBW_BUILD" >> $GITHUB_ENV
177+
178+
179+
- name: Prepare CIBW_BUILD for Windows
180+
if: runner.os == 'Windows'
144181
run: |
145-
echo "CIBW_BUILD=cp3*_x86_64" >> $GITHUB_ENV
182+
if ("${{ matrix.platform }}" -match "PyPy") {
183+
# Convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `pp311* pp312* pp313*`
184+
$cibw_build_patterns = (("${{ inputs.target-wheels-python-versions }}" -replace '\.') -split " " | ForEach-Object { "pp${_}*" }) -join " "
185+
echo "CIBW_BUILD=$cibw_build_patterns" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
186+
} else {
187+
# Convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `cp311*amd64 cp312*amd64 cp313*amd64`
188+
$cibw_build_patterns = (("${{ inputs.target-wheels-python-versions }}" -replace '\.') -split " " | ForEach-Object { "cp${_}*amd64" }) -join " "
189+
echo "CIBW_BUILD=$cibw_build_patterns" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
190+
}
146191
147192
- name: Overwrite for Linux PyPy
148193
if: runner.os == 'Linux' && matrix.platform == 'PyPy'
149194
run: |
150-
echo "CIBW_BUILD=pp*" >> $GITHUB_ENV
151195
echo "CIBW_TEST_COMMAND_LINUX=" >> $GITHUB_ENV
152196
153197
- name: Overwrite for Windows 64
154198
if: runner.os == 'Windows' && matrix.platform == 'win64'
155199
run: |
156-
echo "CIBW_BUILD=cp*win_amd64" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
157200
echo "CIBW_ENVIRONMENT_WINDOWS= CC=clang CXX=clang++" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
158201
159202
- name: Overwrite for Windows PyPY
160203
if: runner.os == 'Windows' && matrix.platform == 'PyPy'
161204
run: |
162-
echo "CIBW_BUILD=pp*" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
163205
echo "CIBW_TEST_COMMAND_WINDOWS=" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
164206
165207
- name: Overwrite for MacOs
166208
if: runner.os == 'MacOs' && matrix.platform == 'all'
167209
run: |
168-
echo "CIBW_BUILD=cp39* cp310* cp311* cp312* cp313*" >> $GITHUB_ENV
169210
echo "CIBW_BEFORE_TEST_MACOS=pip install -r {project}/test-requirements.txt pytest" >> $GITHUB_ENV
170211
if [ "${{ matrix.os }}" == "macos-13" ]; then
171212
echo "MACOSX_DEPLOYMENT_TARGET=13.0" >> $GITHUB_ENV;
@@ -180,7 +221,6 @@ jobs:
180221
- name: Overwrite for MacOs PyPy
181222
if: runner.os == 'MacOs' && matrix.platform == 'PyPy'
182223
run: |
183-
echo "CIBW_BUILD=pp*" >> $GITHUB_ENV
184224
echo "CIBW_BEFORE_TEST_MACOS=pip install -r {project}/test-requirements.txt pytest" >> $GITHUB_ENV
185225
echo "CIBW_TEST_COMMAND_MACOS=" >> $GITHUB_ENV
186226

0 commit comments

Comments
 (0)