-
Notifications
You must be signed in to change notification settings - Fork 104
250 lines (248 loc) · 9.79 KB
/
wheels.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: Wheel builder and uploader
# Update on every push and PR to main, and upon release creation
on:
push:
branches:
- main
paths:
- '**'
- '!*'
- '*.py'
- '!tests/**'
- '!doc/**'
- '!.github/**'
- '.github/workflows/wheels.yml'
pull_request:
branches:
- main
paths-ignore:
- 'doc/**'
release:
types: [created]
jobs:
build_wheels:
name: Build wheel for ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}
runs-on: ${{ matrix.buildplat[0] }}
strategy:
# Ensure that a wheel builder finishes even if another fails
fail-fast: false
matrix:
# Following numpy's setup
buildplat:
- [ubuntu-22.04, manylinux, x86_64]
- [macos-13, macosx, x86_64]
- [macos-14, macosx, arm64]
- [windows-2019, win, amd64]
python:
- ["cp38","3.8"]
- ["cp39","3.9"]
- ["cp310","3.10"]
- ["cp311","3.11"]
- ["cp312","3.12"]
- ["cp313","3.13"]
steps:
- uses: actions/checkout@v4
- name: Install GSL (Windows / Mac OS x86_64)
uses: mamba-org/setup-micromamba@v2
if: matrix.buildplat[1] == 'win' || matrix.buildplat[1] == 'macosx'
with:
environment-name: gsl
condarc: |
channels:
- conda-forge
create-args: gsl
cache-environment: true
cache-environment-key: gsl-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}-${{ hashFiles('.github/workflows/wheels.yml') }}
- name: Set GSL environment variables (Windows)
if: matrix.buildplat[1] == 'win'
shell: bash -l {0}
run: |
echo "INCLUDE=$CONDA_PREFIX\\Library\\include" >> $GITHUB_ENV
echo "LIB=$CONDA_PREFIX\\Library\\lib" >> $GITHUB_ENV
echo "LIBPATH=$CONDA_PREFIX\\Library\\lib" >> $GITHUB_ENV
echo "$CONDA_PREFIX\\Library\\bin" >> $GITHUB_PATH # necessary when we don't activate the environment
- name: Set GSL environment variables (Mac OS)
if: matrix.buildplat[1] == 'macosx'
shell: bash -l {0}
run: |
echo "CFLAGS=-I$CONDA_PREFIX/include" >> $GITHUB_ENV
echo "LDFLAGS=-L$CONDA_PREFIX/lib" >> $GITHUB_ENV
echo "REPAIR_LIBRARY_PATH=$CONDA_PREFIX/lib" >> $GITHUB_ENV # https://github.com/pypa/cibuildwheel/issues/816#issuecomment-916197079
echo "$CONDA_PREFIX/bin" >> $GITHUB_PATH # necessary when we don't activate the environment
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}_${{ matrix.buildplat[2] }}
CIBW_BUILD_VERBOSITY: 1
CIBW_BEFORE_BUILD_LINUX: yum -y install gsl-devel
CIBW_ARCHS_MACOS: ${{ matrix.buildplat[2] }}
CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=10.13"
CIBW_REPAIR_WHEEL_COMMAND_MACOS: >
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} &&
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel -v --require-archs {delocate_archs} -w {dest_dir} {wheel}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}_${{ matrix.buildplat[2] }}
path: ./wheelhouse/*.whl
test_wheels:
name: Test Python ${{ matrix.python[1] }} wheels on ${{ matrix.buildplat[2] }} ${{ matrix.buildplat[0] }}
runs-on: ${{ matrix.buildplat[0] }}
needs: build_wheels
strategy:
# Ensure that tests finish even if another fails
fail-fast: false
matrix:
buildplat:
- [ubuntu-22.04, manylinux, x86_64]
- [macos-13, macosx, x86_64]
- [macos-14, macosx, arm64]
- [windows-2019, win, amd64]
python:
- ["cp38","3.8"]
- ["cp39","3.9"]
- ["cp310","3.10"]
- ["cp311","3.11"]
- ["cp312","3.12"]
- ["cp313","3.13"]
steps:
- uses: actions/checkout@v4
- run: mkdir wheelhouse
- uses: actions/download-artifact@v4
with:
name: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}_${{ matrix.buildplat[2] }}
path: wheelhouse/
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python[1] }}
allow-prereleases: true
- name: Install GSL (Windows)
uses: mamba-org/setup-micromamba@v2
if: matrix.buildplat[1] == 'win'
with:
environment-name: gsl
condarc: |
channels:
- conda-forge
create-args: gsl
cache-environment: true
cache-environment-key: gsl-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}-${{ hashFiles('.github/workflows/wheels.yml') }}
- name: Set GSL environment variables (Windows)
if: matrix.buildplat[1] == 'win'
shell: bash -l {0}
run: |
micromamba activate gsl
echo "LIBPATH=$CONDA_PREFIX\\Library\\lib" >> $GITHUB_ENV
echo "$CONDA_PREFIX\\Library\\bin" >> $GITHUB_PATH # necessary when we don't activate the environment
- name: Install wheel
shell: bash
run: python -m pip install `ls -d "$(pwd)"/wheelhouse/*.whl`
- name: Test built wheel in non-conda environment
shell: bash
working-directory: ${{ runner.temp }}
run: |
pip install astropy pytest
pytest -v $GITHUB_WORKSPACE/tests/test_orbit.py -k "test_energy_jacobi_conservation and NFW"
# Test that built wheels also work in a conda environment, setup environment, install wheel, and run test
- name: Setup test conda environment (Linux / Mac OS)
if: matrix.buildplat[1] != 'win'
uses: mamba-org/setup-micromamba@v2
with:
environment-name: test-wheel-conda
condarc: |
channels:
- conda-forge
create-args: python=${{ matrix.python[1] }} numpy scipy matplotlib astropy pytest
cache-environment: true
cache-environment-key: test-wheel-conda-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}-${{ hashFiles('.github/workflows/wheels.yml') }}
- name: Setup test conda environment (Windows)
if: matrix.buildplat[1] == 'win'
shell: bash -l {0}
run: |
micromamba create -n test-wheel-conda -c conda-forge python=${{ matrix.python[1] }} numpy scipy matplotlib astropy pytest gsl
micromamba activate test-wheel-conda
echo "LIBPATH=$CONDA_PREFIX\\Library\\lib" >> $GITHUB_ENV
- name: Install built wheel in conda environment
shell: bash -l {0}
run: |
micromamba activate test-wheel-conda
python -m pip install `ls -d "$(pwd)"/wheelhouse/*.whl`
- name: Test built wheel in conda environment
shell: bash -l {0}
working-directory: ${{ runner.temp }}
run: |
micromamba activate test-wheel-conda
pytest -v $GITHUB_WORKSPACE/tests/test_orbit.py -k "test_energy_jacobi_conservation and NFW"
build_sdist:
name: Build source directory for release
if: github.event_name == 'release' && github.event.action == 'created'
runs-on: ubuntu-latest
steps:
# check-out this repository
- uses: actions/checkout@v4
# Setup python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.x
# Install the GSL (necessary to properly include the C files)
- name: Install GSL
run: sudo apt-get install -y libgsl0-dev
- name: Build sdist
run: |
pip install build
python -m build --sdist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: ./dist/*.tar.gz
# Deploy wheels and sdist to PyPI (upon release creation)
deploy_pypi:
name: Deploy to PyPI
needs: [build_wheels, test_wheels, build_sdist]
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- uses: actions/checkout@v4
- run: |
mkdir tmp_wheelhouse
mkdir wheelhouse
- uses: actions/download-artifact@v4
with:
path: tmp_wheelhouse/
- run: find tmp_wheelhouse/ -mindepth 2 -type f -exec mv -i '{}' wheelhouse/ ';'
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages_dir: wheelhouse/
# Deploy wheels and sdist to AWS S3 (main)
deploy_s3:
name: Deploy to AWS S3
needs: [build_wheels, test_wheels]
runs-on: ubuntu-latest
if: github.event_name != 'release' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- run: |
mkdir tmp_wheelhouse
mkdir wheelhouse
- uses: actions/download-artifact@v4
with:
path: tmp_wheelhouse/
- run: find tmp_wheelhouse/ -mindepth 2 -type f -exec mv -i '{}' wheelhouse/ ';'
- name: Rename wheel to 'latest' version for AWS S3
run: |
GALPY_VERSION="$(awk '/^current_version/{print $NF}' .bumpversion.cfg)"
for f in wheelhouse/*$GALPY_VERSION*.whl; do mv -i -- "$f" "${f//$GALPY_VERSION/latest}"; done
- name: Upload to AWS S3
uses: jakejarvis/[email protected]
with:
args: --acl public-read --follow-symlinks --delete --exclude "*emscripten*"
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-east-2'
SOURCE_DIR: wheelhouse
DEST_DIR: wheelhouse