Skip to content

Commit 3390b15

Browse files
committed
Merge branch 'maintenance/generic-gha-cibuildwheel'
PR #668
2 parents aa193a5 + ace0efe commit 3390b15

File tree

3 files changed

+112
-76
lines changed

3 files changed

+112
-76
lines changed

.github/workflows/ci-cd.yml

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -134,52 +134,63 @@ jobs:
134134
- pre-setup # transitive, for accessing settings
135135
strategy:
136136
matrix:
137-
os:
138-
- ubuntu
139-
- windows
140-
- macos
137+
runner-vm-os:
138+
- ubuntu-latest
139+
- windows-latest
140+
- macos-latest
141141
tag:
142142
- ''
143143
- 'musllinux'
144144
exclude:
145-
- os: windows
145+
- runner-vm-os: windows-latest
146146
tag: 'musllinux'
147-
- os: macos
147+
- runner-vm-os: macos-latest
148148
tag: 'musllinux'
149-
- os: ubuntu
149+
- runner-vm-os: ubuntu-latest
150150
tag: >-
151151
${{
152152
(github.event_name != 'push' || github.ref_type != 'tag')
153153
&& 'musllinux' || 'none'
154154
}}
155-
uses: ./.github/workflows/reusable-build-wheel.yml
155+
uses: ./.github/workflows/reusable-cibuildwheel.yml
156156
with:
157-
os: ${{ matrix.os }}
158-
tag: ${{ matrix.tag }}
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-
}}
157+
check-name: >-
158+
Build ${{ matrix.tag }} wheels on ${{ matrix.runner-vm-os }}
159+
runner-vm-os: ${{ matrix.runner-vm-os }}
160+
timeout-minutes: 11
171161
source-tarball-name: >-
172162
${{ needs.build-pure-python-dists.outputs.sdist-filename }}
173163
dists-artifact-name: ${{ needs.pre-setup.outputs.dists-artifact-name }}
174-
cython-tracing: >- # Cython line tracing for coverage collection
175-
${{
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=${{
176172
(
177173
github.event_name == 'push'
178174
&& contains(github.ref, 'refs/tags/')
179175
)
180176
&& 'false'
181177
|| 'true'
182178
}}
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
183194
184195
test:
185196
name: Test
@@ -412,19 +423,40 @@ jobs:
412423
tag:
413424
- ''
414425
- musllinux
415-
uses: ./.github/workflows/reusable-build-wheel.yml
426+
uses: ./.github/workflows/reusable-cibuildwheel.yml
416427
with:
417-
qemu: ${{ matrix.qemu }}
418-
tag: ${{ matrix.tag }}
419-
wheel-tags-to-skip: >-
420-
${{
421-
(matrix.tag == 'musllinux')
422-
&& '*-manylinux_* pp*'
423-
|| '*-musllinux_* pp*'
424-
}}
428+
check-name: >-
429+
Build ${{ matrix.tag }} wheels for ${{ matrix.qemu }}
430+
qemu: true
431+
timeout-minutes: 25
425432
source-tarball-name: >-
426433
${{ needs.build-pure-python-dists.outputs.sdist-filename }}
427434
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*
428460
429461
deploy:
430462
name: Deploy

.github/workflows/reusable-build-wheel.yml renamed to .github/workflows/reusable-cibuildwheel.yml

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,43 @@
22

33
name: Build wheel
44

5-
on:
5+
on: # yamllint disable-line rule:truthy
66
workflow_call:
77
inputs:
88
dists-artifact-name:
99
description: Workflow artifact name containing dists
1010
required: true
1111
type: string
12-
cython-tracing:
13-
description: Whether to build Cython modules with line tracing
14-
default: '0'
12+
check-name:
13+
description: A custom name for the Checks API-reported status
1514
required: false
1615
type: string
17-
os:
18-
description: VM OS to use, without version suffix
19-
default: ubuntu
16+
environment-variables:
17+
description: >-
18+
A newline-delimited blob of text with environment variables
19+
to be set using `${GITHUB_ENV}`
2020
required: false
2121
type: string
2222
qemu:
23-
description: Emulated QEMU architecture
24-
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".
2527
required: false
26-
type: string
27-
tag:
28-
description: Build platform tag wheels
29-
default: ''
28+
type: boolean
29+
runner-vm-os:
30+
description: VM OS to use
31+
default: ubuntu-latest
3032
required: false
3133
type: string
3234
source-tarball-name:
3335
description: Sdist filename wildcard
3436
required: true
3537
type: string
36-
wheel-tags-to-skip:
37-
description: Wheel tags to skip building
38-
default: ''
39-
required: false
40-
type: string
38+
timeout-minutes:
39+
description: Deadline for the job to complete
40+
required: true
41+
type: number
4142

4243
env:
4344
FORCE_COLOR: "1" # Make tools pretty.
@@ -48,24 +49,44 @@ jobs:
4849

4950
build-wheel:
5051
name: >-
51-
Build ${{ inputs.tag }} wheels on ${{ inputs.os }} ${{ inputs.qemu }}
52-
runs-on: ${{ inputs.os }}-latest
53-
timeout-minutes: ${{ inputs.qemu && 25 || 11 }}
52+
${{
53+
inputs.check-name
54+
&& inputs.check-name
55+
|| format(
56+
'Build wheels on {0}{1}',
57+
inputs.runner-vm-os,
58+
inputs.qemu && ' under QEMU' || ''
59+
)
60+
}}
61+
runs-on: ${{ inputs.runner-vm-os }}
62+
timeout-minutes: ${{ fromJSON(inputs.timeout-minutes) }}
5463
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+
5571
- name: Compute GHA artifact name ending
5672
id: gha-artifact-name
5773
run: |
5874
from hashlib import sha512
5975
from os import environ
6076
from pathlib import Path
77+
6178
FILE_APPEND_MODE = 'a'
79+
6280
inputs_json_str = """${{ toJSON(inputs) }}"""
81+
6382
hash = sha512(inputs_json_str.encode()).hexdigest()
83+
6484
with Path(environ['GITHUB_OUTPUT']).open(
6585
mode=FILE_APPEND_MODE,
6686
) as outputs_file:
6787
print(f'hash={hash}', file=outputs_file)
6888
shell: python
89+
6990
- name: Retrieve the project source from an sdist inside the GHA artifact
7091
uses: re-actors/checkout-python-sdist@release/v2
7192
with:
@@ -77,36 +98,16 @@ jobs:
7798
uses: docker/setup-qemu-action@v3
7899
with:
79100
platforms: all
80-
id: qemu
81-
- name: Prepare emulation
82-
if: inputs.qemu
83-
run: |
84-
# Build emulated architectures only if QEMU is set,
85-
# use default "auto" otherwise
86-
echo "CIBW_ARCHS_LINUX=${{ inputs.qemu }}" >> "${GITHUB_ENV}"
87-
shell: bash
88-
89-
- name: Skip building some wheel tags
90-
if: inputs.wheel-tags-to-skip
91-
run: |
92-
echo "CIBW_SKIP=${{ inputs.wheel-tags-to-skip }}" >> "${GITHUB_ENV}"
93-
shell: bash
94101

95102
- name: Build wheels
96103
uses: pypa/[email protected]
97-
env:
98-
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
99-
CIBW_CONFIG_SETTINGS: >- # Cython line tracing for coverage collection
100-
pure-python=false
101-
with-cython-tracing=${{ inputs.cython-tracing }}
102104

103105
- name: Upload built artifacts for testing and publishing
104106
uses: actions/upload-artifact@v4
105107
with:
106108
name: ${{ inputs.dists-artifact-name }}-
107-
${{ inputs.os }}-
108-
${{ inputs.qemu }}-
109-
${{ inputs.tag }}-
109+
${{ inputs.runner-vm-os }}-
110+
${{ inputs.qemu && 'qemu-' || '' }}
110111
${{ steps.gha-artifact-name.outputs.hash }}
111112
path: ./wheelhouse/*.whl
112113

CHANGES/668.contrib.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :file:`reusable-cibuildwheel.yml` workflow has been refactored to
2+
be more generic and :file:`ci-cd.yml` now holds all the configuration
3+
toggles -- by :user:`webknjaz`.

0 commit comments

Comments
 (0)