Skip to content

Commit ad27123

Browse files
committed
🧪 Generalize cibuildwheel config w/ env vars
1 parent a661c84 commit ad27123

File tree

2 files changed

+68
-54
lines changed

2 files changed

+68
-54
lines changed

.github/workflows/ci-cd.yml

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,32 +156,41 @@ jobs:
156156
with:
157157
check-name: >-
158158
Build ${{ matrix.tag }} wheels on ${{ matrix.runner-vm-os }}
159-
wheel-tags-to-skip: >-
160-
${{
161-
(github.event_name != 'push' || !contains(github.ref, 'refs/tags/'))
162-
&& '*_i686
163-
*-macosx_universal2
164-
*-musllinux_*
165-
*-win32
166-
*_arm64
167-
pp*'
168-
|| (matrix.tag == 'musllinux') && '*-manylinux_* pp*'
169-
|| '*-musllinux_* pp*'
170-
}}
171159
runner-vm-os: ${{ matrix.runner-vm-os }}
172160
timeout-minutes: 11
173161
source-tarball-name: >-
174162
${{ needs.build-pure-python-dists.outputs.sdist-filename }}
175163
dists-artifact-name: ${{ needs.pre-setup.outputs.dists-artifact-name }}
176-
cython-tracing: >- # Cython line tracing for coverage collection
177-
${{
164+
# CIBW_CONFIG_SETTINGS: `with-cython-tracing` — for coverage collection
165+
# CIBW_CONFIG_SETTINGS: `pure-python` — force C-extensions
166+
environment-variables: |-
167+
CIBW_ARCHS_MACOS=x86_64 arm64 universal2
168+
169+
CIBW_CONFIG_SETTINGS<<EOF
170+
pure-python=false
171+
with-cython-tracing=${{
178172
(
179173
github.event_name == 'push'
180174
&& contains(github.ref, 'refs/tags/')
181175
)
182176
&& 'false'
183177
|| 'true'
184178
}}
179+
EOF
180+
181+
CIBW_SKIP<<EOF
182+
${{
183+
(github.event_name != 'push' || !contains(github.ref, 'refs/tags/'))
184+
&& '*_i686
185+
*-macosx_universal2
186+
*-musllinux_*
187+
*-win32
188+
*_arm64'
189+
|| (matrix.tag == 'musllinux') && '*-manylinux_*'
190+
|| '*-musllinux_*'
191+
}}
192+
pp*
193+
EOF
185194
186195
test:
187196
name: Test
@@ -418,17 +427,36 @@ jobs:
418427
with:
419428
check-name: >-
420429
Build ${{ matrix.tag }} wheels for ${{ matrix.qemu }}
421-
qemu: ${{ matrix.qemu }}
422-
wheel-tags-to-skip: >-
423-
${{
424-
(matrix.tag == 'musllinux')
425-
&& '*-manylinux_* pp*'
426-
|| '*-musllinux_* pp*'
427-
}}
430+
qemu: true
428431
timeout-minutes: 25
429432
source-tarball-name: >-
430433
${{ needs.build-pure-python-dists.outputs.sdist-filename }}
431434
dists-artifact-name: ${{ needs.pre-setup.outputs.dists-artifact-name }}
435+
# CIBW_ARCHS_LINUX: Build emulated architectures if QEMU, else "auto"
436+
# CIBW_CONFIG_SETTINGS: `with-cython-tracing` — for coverage collection
437+
# CIBW_CONFIG_SETTINGS: `pure-python` — force C-extensions
438+
environment-variables: |-
439+
CIBW_ARCHS_LINUX=${{ matrix.qemu }}
440+
441+
CIBW_ARCHS_MACOS=x86_64 arm64 universal2
442+
443+
CIBW_CONFIG_SETTINGS<<EOF
444+
pure-python=false
445+
with-cython-tracing=${{
446+
(
447+
github.event_name == 'push'
448+
&& contains(github.ref, 'refs/tags/')
449+
)
450+
&& 'false'
451+
|| 'true'
452+
}}
453+
EOF
454+
455+
CIBW_SKIP=${{
456+
(matrix.tag == 'musllinux')
457+
&& '*-manylinux_*'
458+
|| '*-musllinux_*'
459+
}} pp*
432460
433461
deploy:
434462
name: Deploy

.github/workflows/reusable-cibuildwheel.yml

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ on: # yamllint disable-line rule:truthy
1313
description: A custom name for the Checks API-reported status
1414
required: false
1515
type: string
16-
cython-tracing:
17-
description: Whether to build Cython modules with line tracing
18-
default: '0'
16+
environment-variables:
17+
description: >-
18+
A newline-delimited blob of text with environment variables
19+
to be set using `${GITHUB_ENV}`
1920
required: false
2021
type: string
2122
qemu:
22-
description: Emulated QEMU architecture
23-
default: ''
23+
default: false
24+
description: >-
25+
Whether this job needs to configure QEMU to emulate a foreign
26+
architecture before running `cibuildwheel`. Defaults to "false".
2427
required: false
25-
type: string
28+
type: boolean
2629
runner-vm-os:
2730
description: VM OS to use
2831
default: ubuntu-latest
@@ -36,11 +39,6 @@ on: # yamllint disable-line rule:truthy
3639
description: Deadline for the job to complete
3740
required: true
3841
type: number
39-
wheel-tags-to-skip:
40-
description: Wheel tags to skip building
41-
default: ''
42-
required: false
43-
type: string
4442

4543
env:
4644
FORCE_COLOR: "1" # Make tools pretty.
@@ -55,14 +53,21 @@ jobs:
5553
inputs.check-name
5654
&& inputs.check-name
5755
|| format(
58-
'Build wheels on {0} {1}',
56+
'Build wheels on {0}{1}',
5957
inputs.runner-vm-os,
60-
inputs.qemu
58+
inputs.qemu && ' under QEMU' || ''
6159
)
6260
}}
6361
runs-on: ${{ inputs.runner-vm-os }}
6462
timeout-minutes: ${{ fromJSON(inputs.timeout-minutes) }}
6563
steps:
64+
- name: Export requested job-global environment variables
65+
if: inputs.environment-variables != ''
66+
env:
67+
INPUT_ENVIRONMENT_VARIABLES: ${{ inputs.environment-variables }}
68+
run: echo "${INPUT_ENVIRONMENT_VARIABLES}" >> "${GITHUB_ENV}"
69+
shell: bash
70+
6671
- name: Compute GHA artifact name ending
6772
id: gha-artifact-name
6873
run: |
@@ -93,35 +98,16 @@ jobs:
9398
uses: docker/setup-qemu-action@v3
9499
with:
95100
platforms: all
96-
id: qemu
97-
- name: Prepare emulation
98-
if: inputs.qemu
99-
run: |
100-
# Build emulated architectures only if QEMU is set,
101-
# use default "auto" otherwise
102-
echo "CIBW_ARCHS_LINUX=${{ inputs.qemu }}" >> "${GITHUB_ENV}"
103-
shell: bash
104-
105-
- name: Skip building some wheel tags
106-
if: inputs.wheel-tags-to-skip
107-
run: |
108-
echo "CIBW_SKIP=${{ inputs.wheel-tags-to-skip }}" >> "${GITHUB_ENV}"
109-
shell: bash
110101

111102
- name: Build wheels
112103
uses: pypa/[email protected]
113-
env:
114-
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
115-
CIBW_CONFIG_SETTINGS: >- # Cython line tracing for coverage collection
116-
pure-python=false
117-
with-cython-tracing=${{ inputs.cython-tracing }}
118104

119105
- name: Upload built artifacts for testing and publishing
120106
uses: actions/upload-artifact@v4
121107
with:
122108
name: ${{ inputs.dists-artifact-name }}-
123109
${{ inputs.runner-vm-os }}-
124-
${{ inputs.qemu }}-
110+
${{ inputs.qemu && 'qemu-' || '' }}
125111
${{ steps.gha-artifact-name.outputs.hash }}
126112
path: ./wheelhouse/*.whl
127113

0 commit comments

Comments
 (0)