Skip to content

Commit c429008

Browse files
committed
🧪 Generalize cibuildwheel config w/ env vars
1 parent 4c50d92 commit c429008

2 files changed

Lines changed: 50 additions & 29 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
uses: ./.github/workflows/reusable-cibuildwheel.yml
142142
with:
143143
check-name: >-
144-
Build ${{ matrix.tag }} wheels on ${{ matrix.runner-vm-os }}
144+
Build ${{ matrix.tag }} wheels for ${{ matrix.qemu }}
145145
wheel-tags-to-skip: >-
146146
${{
147147
(github.event_name != 'push' || !contains(github.ref, 'refs/tags/'))
@@ -158,6 +158,21 @@ jobs:
158158
source-tarball-name: >-
159159
${{ needs.build-pure-python-dists.outputs.sdist-filename }}
160160
dists-artifact-name: ${{ needs.pre-setup.outputs.dists-artifact-name }}
161+
environment-variables: |-
162+
CIBW_ARCHS_MACOS=x86_64 arm64 universal2
163+
164+
CIBW_SKIP<<EOF
165+
${{
166+
(github.event_name != 'push' || !contains(github.ref, 'refs/tags/'))
167+
&& '*_i686
168+
*-macosx_universal2
169+
*-musllinux_*
170+
*-win32'
171+
|| (matrix.tag == 'musllinux') && '*-manylinux_*'
172+
|| '*-musllinux_*'
173+
}}
174+
pp*
175+
EOF
161176
162177
test:
163178
name: >-
@@ -564,7 +579,7 @@ jobs:
564579
uses: ./.github/workflows/reusable-cibuildwheel.yml
565580
with:
566581
check-name: >-
567-
Build ${{ matrix.tag }} wheels for ${{ matrix.qemu }}
582+
Build ${{ matrix.tag }} wheels on ${{ matrix.runner-vm-os }}
568583
qemu: ${{ matrix.qemu }}
569584
wheel-tags-to-skip: >-
570585
${{
@@ -576,6 +591,17 @@ jobs:
576591
source-tarball-name: >-
577592
${{ needs.build-pure-python-dists.outputs.sdist-filename }}
578593
dists-artifact-name: ${{ needs.pre-setup.outputs.dists-artifact-name }}
594+
# CIBW_ARCHS_LINUX: Build emulated architectures if QEMU, else "auto"
595+
environment-variables: |-
596+
CIBW_ARCHS_LINUX=${{ matrix.qemu }}
597+
598+
CIBW_ARCHS_MACOS=x86_64 arm64 universal2
599+
600+
CIBW_SKIP=${{
601+
(matrix.tag == 'musllinux')
602+
&& '*-manylinux_*'
603+
|| '*-musllinux_*'
604+
}} pp*
579605
580606
deploy:
581607
name: Deploy

.github/workflows/reusable-cibuildwheel.yml

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@ on: # yamllint disable-line rule:truthy
1313
description: A custom name for the Checks API-reported status
1414
required: false
1515
type: string
16+
environment-variables:
17+
description: >-
18+
A newline-delimited blob of text with environment variables
19+
to be set using `${GITHUB_ENV}`
20+
required: false
21+
type: string
1622
qemu:
17-
description: Emulated QEMU architecture
18-
default: ''
23+
default: >-
24+
false
25+
description: >-
26+
Whether this job is needs to configure QEMU to emulate a foreign
27+
architecture before running `cibuildwheel`. Defaults to "false".
1928
required: false
2029
type: string
2130
runner-vm-os:
@@ -31,11 +40,6 @@ on: # yamllint disable-line rule:truthy
3140
description: Deadline for the job to complete
3241
required: true
3342
type: string
34-
wheel-tags-to-skip:
35-
description: Wheel tags to skip building
36-
default: ''
37-
required: false
38-
type: string
3943

4044
env:
4145
FORCE_COLOR: "1" # Make tools pretty.
@@ -50,14 +54,21 @@ jobs:
5054
inputs.check-name
5155
&& inputs.check-name
5256
|| format(
53-
'Build wheels on {0} {1}',
57+
'Build wheels on {0}{1}',
5458
inputs.runner-vm-os,
55-
inputs.qemu
59+
fromJSON(inputs.qemu) && ' under QEMU' || ''
5660
)
5761
}}
5862
runs-on: ${{ inputs.runner-vm-os }}
5963
timeout-minutes: ${{ fromJSON(inputs.timeout-minutes) }}
6064
steps:
65+
- name: Export requested job-global environment variables
66+
if: inputs.environment-variables != ''
67+
env:
68+
INPUT_ENVIRONMENT_VARIABLES: ${{ inputs.environment-variables }}
69+
run: echo "${INPUT_ENVIRONMENT_VARIABLES}" >> "${GITHUB_ENV}"
70+
shell: bash
71+
6172
- name: Compute GHA artifact name ending
6273
id: gha-artifact-name
6374
run: |
@@ -84,36 +95,20 @@ jobs:
8495
workflow-artifact-name: ${{ inputs.dists-artifact-name }}
8596

8697
- name: Set up QEMU
87-
if: inputs.qemu
98+
if: fromJSON(inputs.qemu)
8899
uses: docker/setup-qemu-action@v3
89100
with:
90101
platforms: all
91-
id: qemu
92-
- name: Prepare emulation
93-
if: inputs.qemu
94-
run: |
95-
# Build emulated architectures only if QEMU is set,
96-
# use default "auto" otherwise
97-
echo "CIBW_ARCHS_LINUX=${{ inputs.qemu }}" >> "${GITHUB_ENV}"
98-
shell: bash
99-
100-
- name: Skip building some wheel tags
101-
if: inputs.wheel-tags-to-skip
102-
run: |
103-
echo "CIBW_SKIP=${{ inputs.wheel-tags-to-skip }}" >> "${GITHUB_ENV}"
104-
shell: bash
105102

106103
- name: Build wheels
107104
uses: pypa/cibuildwheel@v3.0.0
108-
env:
109-
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
110105

111106
- name: Upload built artifacts for testing and publishing
112107
uses: actions/upload-artifact@v4
113108
with:
114109
name: ${{ inputs.dists-artifact-name }}-
115110
${{ inputs.runner-vm-os }}-
116-
${{ inputs.qemu }}-
111+
${{ fromJSON(inputs.qemu) && 'qemu-' || '' }}
117112
${{ steps.gha-artifact-name.outputs.hash }}
118113
path: ./wheelhouse/*.whl
119114

0 commit comments

Comments
 (0)