Skip to content

Commit d5855f3

Browse files
committed
cicd/lib-build-and-push: isolate CIBW_BUILD logic
1 parent 2d9fb37 commit d5855f3

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

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

Lines changed: 34 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,54 @@ 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+
if [[ "${{ matrix.platform }}" == "PyPy" ]]; then
152+
# Convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `pp311* pp312* pp313*`
153+
echo "CIBW_BUILD=$(echo "${{ inputs.target-wheels-python-versions }}" | tr -d "." | sed 's/\w\+/pp&*/g' )" >> $GITHUB_ENV
154+
elif [[ "${{ matrix.platform }}" == "arm64" ]]; then
155+
# Convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `cp311*arm64 cp312*arm64 cp313*arm64`
156+
echo "CIBW_BUILD=$(echo "${{ inputs.target-wheels-python-versions }}" | tr -d "." | sed 's/\w\+/cp&*arm64/g' )" >> $GITHUB_ENV
157+
elif [[ "${{ matrix.platform }}" == "x86_64" ]]; then
158+
# Convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `cp311*x86_64 cp312*x86_64 cp313*x86_64`
159+
echo "CIBW_BUILD=$(echo "${{ inputs.target-wheels-python-versions }}" | tr -d "." | sed 's/\w\+/cp&*x86_64/g' )" >> $GITHUB_ENV
160+
else
161+
echo "Unknown target platfor '${{ matrix.platform }}'"
162+
exit 1
163+
fi
164+
165+
- name: Prepare CIBW_BUILD for Windows
166+
if: runner.os == 'Windows'
144167
run: |
145-
echo "CIBW_BUILD=cp3*_x86_64" >> $GITHUB_ENV
168+
if ("${{ matrix.platform }}" -match "PyPy") {
169+
# Convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `pp311* pp312* pp313*`
170+
$cibw_build_patterns = (("${{ inputs.target-wheels-python-versions }}" -replace '\.') -split " " | ForEach-Object { "pp${_}*" }) -join " "
171+
echo "CIBW_BUILD=$cibw_build_patterns" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
172+
} else {
173+
# Convert `inputs.target-wheels-python-versions` (3.11 3.12 3.13) into `cp311*amd64 cp312*amd64 cp313*amd64`
174+
$cibw_build_patterns = (("${{ inputs.target-wheels-python-versions }}" -replace '\.') -split " " | ForEach-Object { "cp${_}*amd64" }) -join " "
175+
echo "CIBW_BUILD=$cibw_build_patterns" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
176+
}
146177
147178
- name: Overwrite for Linux PyPy
148179
if: runner.os == 'Linux' && matrix.platform == 'PyPy'
149180
run: |
150-
echo "CIBW_BUILD=pp*" >> $GITHUB_ENV
151181
echo "CIBW_TEST_COMMAND_LINUX=" >> $GITHUB_ENV
152182
153183
- name: Overwrite for Windows 64
154184
if: runner.os == 'Windows' && matrix.platform == 'win64'
155185
run: |
156-
echo "CIBW_BUILD=cp*win_amd64" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
157186
echo "CIBW_ENVIRONMENT_WINDOWS= CC=clang CXX=clang++" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
158187
159188
- name: Overwrite for Windows PyPY
160189
if: runner.os == 'Windows' && matrix.platform == 'PyPy'
161190
run: |
162-
echo "CIBW_BUILD=pp*" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
163191
echo "CIBW_TEST_COMMAND_WINDOWS=" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
164192
165193
- name: Overwrite for MacOs
166194
if: runner.os == 'MacOs' && matrix.platform == 'arm64'
167195
run: |
168-
echo "CIBW_BUILD=cp39* cp310* cp311* cp312* cp313*" >> $GITHUB_ENV
169196
echo "CIBW_BEFORE_TEST_MACOS=pip install -r {project}/test-requirements.txt pytest" >> $GITHUB_ENV
170197
if [ "${{ matrix.os }}" == "macos-13" ]; then
171198
echo "MACOSX_DEPLOYMENT_TARGET=13.0" >> $GITHUB_ENV;
@@ -180,7 +207,6 @@ jobs:
180207
- name: Overwrite for MacOs PyPy
181208
if: runner.os == 'MacOs' && matrix.platform == 'PyPy'
182209
run: |
183-
echo "CIBW_BUILD=pp*" >> $GITHUB_ENV
184210
echo "CIBW_BEFORE_TEST_MACOS=pip install -r {project}/test-requirements.txt pytest" >> $GITHUB_ENV
185211
echo "CIBW_TEST_COMMAND_MACOS=" >> $GITHUB_ENV
186212

0 commit comments

Comments
 (0)