Skip to content

Commit 5f89ec0

Browse files
committed
ci: Merge sdist and wheel building workflows
This allows verifying that wheels can be installed after building, and that the sdist can be built into a wheel without a second workflow. Also simplify some of the checking scripts.
1 parent 78bf53c commit 5f89ec0

File tree

6 files changed

+100
-118
lines changed

6 files changed

+100
-118
lines changed

.github/workflows/cibuildsdist.yml

Lines changed: 0 additions & 74 deletions
This file was deleted.

.github/workflows/cibuildwheel.yml

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,59 @@ permissions:
2222
contents: read
2323

2424
jobs:
25+
build_sdist:
26+
if: |
27+
github.event_name == 'push' ||
28+
github.event_name == 'pull_request' && (
29+
(
30+
github.event.action == 'labeled' &&
31+
github.event.label.name == 'CI: Run cibuildwheel'
32+
) ||
33+
contains(github.event.pull_request.labels.*.name,
34+
'CI: Run cibuildwheel')
35+
)
36+
name: Build sdist
37+
runs-on: ubuntu-20.04
38+
outputs:
39+
SDIST_NAME: ${{ steps.sdist.outputs.SDIST_NAME }}
40+
41+
steps:
42+
- uses: actions/checkout@v3
43+
with:
44+
fetch-depth: 0
45+
46+
- uses: actions/setup-python@v4
47+
name: Install Python
48+
with:
49+
python-version: 3.9
50+
51+
# Something changed somewhere that prevents the downloaded-at-build-time
52+
# licenses from being included in built wheels, so pre-download them so
53+
# that they exist before the build and are included.
54+
- name: Pre-download bundled licenses
55+
run: >
56+
curl -Lo LICENSE/LICENSE_QHULL
57+
https://github.com/qhull/qhull/raw/2020.2/COPYING.txt
58+
59+
- name: Install dependencies
60+
run: python -m pip install build twine
61+
62+
- name: Build sdist
63+
id: sdist
64+
run: |
65+
python -m build --sdist
66+
python ci/determine_sdist_name.py
67+
68+
- name: Check README rendering for PyPI
69+
run: twine check dist/*
70+
71+
- name: Upload sdist result
72+
uses: actions/upload-artifact@v3
73+
with:
74+
name: sdist
75+
path: dist/*.tar.gz
76+
if-no-files-found: error
77+
2578
build_wheels:
2679
if: |
2780
github.event_name == 'push' ||
@@ -30,21 +83,27 @@ jobs:
3083
github.event.action == 'labeled' &&
3184
github.event.label.name == 'CI: Run cibuildwheel'
3285
) ||
33-
contains(github.event.pull_request.labels.*.name, 'CI: Run cibuildwheel')
86+
contains(github.event.pull_request.labels.*.name,
87+
'CI: Run cibuildwheel')
3488
)
89+
needs: build_sdist
3590
name: Build wheels on ${{ matrix.os }}
3691
runs-on: ${{ matrix.os }}
3792
env:
3893
CIBW_BEFORE_BUILD: >-
3994
pip install certifi oldest-supported-numpy &&
40-
git clean -fxd build
95+
rm -rf {package}/build
4196
CIBW_BEFORE_BUILD_WINDOWS: >-
4297
pip install certifi delvewheel oldest-supported-numpy &&
43-
git clean -fxd build
98+
rm -rf {package}/build
4499
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: >-
45100
delvewheel repair -w {dest_dir} {wheel}
101+
CIBW_AFTER_BUILD: twine check {wheel}
46102
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
47103
CIBW_SKIP: "*-musllinux*"
104+
CIBW_TEST_COMMAND: >-
105+
python {package}/ci/check_version_number.py &&
106+
python {package}/ci/check_wheel_licenses.py
48107
MACOSX_DEPLOYMENT_TARGET: "10.12"
49108
MPL_DISABLE_FH4: "yes"
50109
strategy:
@@ -66,47 +125,45 @@ jobs:
66125
with:
67126
platforms: arm64
68127

69-
- uses: actions/checkout@v3
128+
- name: Download sdist
129+
uses: actions/download-artifact@v3
70130
with:
71-
fetch-depth: 0
72-
73-
# Something changed somewhere that prevents the downloaded-at-build-time
74-
# licenses from being included in built wheels, so pre-download them so
75-
# that they exist before the build and are included.
76-
- name: Pre-download bundled licenses
77-
run: >
78-
curl -Lo LICENSE/LICENSE_QHULL
79-
https://github.com/qhull/qhull/raw/2020.2/COPYING.txt
131+
name: sdist
132+
path: dist/
80133

81134
- name: Build wheels for CPython 3.11
82135
uses: pypa/cibuildwheel@v2.12.1
136+
with:
137+
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
83138
env:
84139
CIBW_BUILD: "cp311-*"
85140
CIBW_ARCHS: ${{ matrix.cibw_archs }}
86141

87142
- name: Build wheels for CPython 3.10
88143
uses: pypa/cibuildwheel@v2.12.1
144+
with:
145+
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
89146
env:
90147
CIBW_BUILD: "cp310-*"
91148
CIBW_ARCHS: ${{ matrix.cibw_archs }}
92149

93150
- name: Build wheels for CPython 3.9
94151
uses: pypa/cibuildwheel@v2.12.1
152+
with:
153+
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
95154
env:
96155
CIBW_BUILD: "cp39-*"
97156
CIBW_ARCHS: ${{ matrix.cibw_archs }}
98157

99158
- name: Build wheels for PyPy
100159
uses: pypa/cibuildwheel@v2.12.1
160+
with:
161+
package-dir: dist/${{ needs.build_sdist.outputs.SDIST_NAME }}
101162
env:
102163
CIBW_BUILD: "pp39-*"
103164
CIBW_ARCHS: ${{ matrix.cibw_archs }}
104165
if: matrix.cibw_archs != 'aarch64'
105166

106-
- name: Validate that LICENSE files are included in wheels
107-
run: |
108-
python3 ./ci/check_wheel_licenses.py
109-
110167
- uses: actions/upload-artifact@v3
111168
with:
112169
name: wheels

ci/check_version_number.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
$ pip install dist/matplotlib*.whl for wheel
1010
$ ./ci/check_version_number.py
1111
"""
12-
import matplotlib
13-
1412
import sys
1513

16-
EXIT_SUCCESS = 0
17-
EXIT_FAILURE = 1
14+
import matplotlib
1815

1916

2017
print(f"Version {matplotlib.__version__} installed")
2118
if matplotlib.__version__[0] == "0":
22-
sys.exit(EXIT_FAILURE)
23-
sys.exit(EXIT_SUCCESS)
19+
sys.exit("Version incorrectly starts with 0")

ci/check_wheel_licenses.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import sys
1414
import zipfile
1515

16-
EXIT_SUCCESS = 0
17-
EXIT_FAILURE = 1
1816

1917
project_dir = Path(__file__).parent.resolve().parent
2018
dist_dir = project_dir / 'dist'
@@ -29,8 +27,6 @@
2927
if '.dist-info/LICENSE' in path}
3028
if not (len(wheel_license_file_names) and
3129
wheel_license_file_names.issuperset(license_file_names)):
32-
print(f'LICENSE file(s) missing:\n'
33-
f'{wheel_license_file_names} !=\n'
34-
f'{license_file_names}')
35-
sys.exit(EXIT_FAILURE)
36-
sys.exit(EXIT_SUCCESS)
30+
sys.exit(f'LICENSE file(s) missing:\n'
31+
f'{wheel_license_file_names} !=\n'
32+
f'{license_file_names}')

ci/determine_sdist_name.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Determine the name of the sdist and export to GitHub output named SDIST_NAME.
5+
6+
To run:
7+
$ python3 -m build --sdist
8+
$ ./ci/determine_sdist_name.py
9+
"""
10+
import os
11+
from pathlib import Path
12+
import sys
13+
14+
15+
paths = [p.name for p in Path("dist").glob("*.tar.gz")]
16+
if len(paths) != 1:
17+
sys.exit(f"Only a single sdist is supported, but found: {paths}")
18+
19+
print(paths[0])
20+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
21+
f.write(f"SDIST_NAME={paths[0]}\n")

ci/silence

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)