-
Notifications
You must be signed in to change notification settings - Fork 3
192 lines (166 loc) · 6.94 KB
/
build_wheels_test_deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Build, test, and upload to PyPI
name: Publish
on:
workflow_dispatch:
push:
# The workflow is triggered if either of the 2 conditions below is satisfied
branches: [ "main" ]
tags: ['v*'] # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:
branches: [ "main" ]
jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# macos-13 uses intel runner, macos-14 is apple silicon, no runners for macos-14 with intel x86-64
os: [ubuntu-22.04, macos-13, macos-14, windows-2019, windows-2022]
# Uncomment the following line for faster testing of the workflow
# os: [ubuntu-22.04]
steps:
- name: Checkout the repository to the GitHub runner
uses: actions/checkout@v4
- name: Setup GNU Fortran
if: false == contains( matrix.os, 'windows')
uses: awvwgk/setup-fortran@v1
- name: Install mingw-w64 as Fortran compiler on Windows
if: contains( matrix.os, 'windows')
uses: msys2/setup-msys2@v2
with:
path-type: inherit
install: |
mingw-w64-x86_64-gcc
mingw-w64-x86_64-gcc-fortran
# - name: Install rtools (mingw-w64) on Windows
# if: contains( matrix.os, 'windows')
# run: |
# choco install rtools -y --no-progress --force --version=4.0.0.20220206
# echo "c:\rtools40\ucrt64\bin;" >> $env:GITHUB_PATH
- name: Build macos-13 wheels
if: contains( matrix.os, 'macos-13')
uses: pypa/cibuildwheel@v2.18.1
env:
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET="13.0"
- name: Build macos-14 wheels
if: contains( matrix.os, 'macos-14')
uses: pypa/cibuildwheel@v2.18.1
env:
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET="14.0"
# Warning: While cibuildwheel can build CPython 3.8 universal2/arm64 wheels,
# we cannot test the arm64 part of them, even when running on an Apple Silicon machine.
# This is because we use the x86_64 installer of CPython 3.8.
# See the discussion in https://github.com/pypa/cibuildwheel/pull/1169 for the details.
# To silence this warning: set `CIBW_TEST_SKIP: "cp38-macosx_*:arm64"`
CIBW_TEST_SKIP: "cp38-macosx_arm64"
- name: Build linux wheels
if: contains( matrix.os, 'ubuntu')
uses: pypa/cibuildwheel@v2.18.1
# Uncomment the following 2 lines for faster testing of the workflow
# env:
# CIBW_BUILD: "cp38-* cp312-*"
- name: Build Windows wheels # only for python>=3.9
if: contains( matrix.os, 'windows')
uses: pypa/cibuildwheel@v2.18.1
# env:
# CIBW_SKIP: "cp38-* *-win32" # win32 needs to be specified since this overrides skip specified in pyproject.toml
# # Now handled in pyproject.toml windows subsection
- uses: actions/upload-artifact@v4
with:
# Name of the artifact to upload.
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
# A file, directory or wildcard pattern that describes what to upload. Required.
path: ./wheelhouse/*.whl
build_sdist:
name: Build source distribution
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Build sdist
# run: pipx run build --sdist
run: |
python -m pip install --upgrade pip
python -m pip install build
python -m build --sdist --outdir dist/
- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: ./dist/*.tar.gz
# sdists are not tested by cibuildwheel so we test them manually for v* tags
# We only run a limited number of configurations here to save actions minutes
manual_test_of_sdist:
name: Manual test of sdist
needs: [build_sdist]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, macos-13, macos-14, windows-2019, windows-2022]
python-version: ["3.9", "3.12"]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Setup GNU Fortran
if: false == contains( matrix.os, 'windows')
uses: awvwgk/setup-fortran@v1
- name: Install mingw-w64 as Fortran compiler on Windows
if: contains( matrix.os, 'windows')
uses: msys2/setup-msys2@v2
with:
path-type: inherit
install: |
mingw-w64-x86_64-gcc
mingw-w64-x86_64-gcc-fortran
# - name: Install rtools (mingw-w64) on Windows
# if: contains( matrix.os, 'windows')
# run: |
# choco install rtools -y --no-progress --force --version=4.0.0.20220206
# echo "c:\rtools40\ucrt64\bin;" >> $env:GITHUB_PATH
- name: Checkout the repository to the GitHub runner
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
update-environment: true
- uses: actions/download-artifact@v4
with:
name: cibw-sdist
# destination path
path: dist
- name: Install the sdist
run: |
python -m pip install --upgrade pip
# python -m pip install ./dist/*.tar.gz # This wildcard expansion does not work on Windows
# Use Python’s glob module to explicitly handle the wildcard in a platform-independent way:
python -m pip install $(python -c "import glob; print(glob.glob('./dist/*.tar.gz')[0])")
python -m pip install pytest
- name: Run tests
run: |
pytest
# Upload built wheels and sdist to PyPI. Runs only when a v* tag is pushed.
upload_pypi:
name: Upload to PyPI
needs: [build_wheels, build_sdist, manual_test_of_sdist]
runs-on: ubuntu-22.04
# environment: testpypi
environment: pypi
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v4
# unpacks all CIBW artifacts into dist/
with:
# A glob pattern to the artifacts that should be downloaded.
# If unspecified, all artifacts for the run are downloaded.
pattern: cibw-*
# destination path
path: dist
# If true, the downloaded artifacts will be in the same directory specified by path.
# If false, the downloaded artifacts will be extracted into individual named directories within the specified path.
merge-multiple: true
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# with:
# repository-url: https://test.pypi.org/legacy/