-
Notifications
You must be signed in to change notification settings - Fork 18
387 lines (326 loc) · 11.6 KB
/
build.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
name: build
on:
push:
pull_request:
jobs:
# Quickly check with flake8 without having to go through the whole build:
flake8:
name: "Fast flake8"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Check on lowest supported python version to catch syntax errors:
- uses: actions/setup-python@v5
with: { python-version: "3.7" }
- run: pip install flake8
- run: flake8
build_linux:
name: "Build: Linux (x64)"
runs-on: ubuntu-latest
strategy:
matrix:
base:
- manylinux1_x86_64
- manylinux2014_x86_64
- manylinux2014_aarch64
steps:
- uses: actions/checkout@v4
- run: echo "MADX_VERSION=$(cat MADX_VERSION)" >> $GITHUB_ENV
- name: Download cached MAD-X build
id: madx-build-cache
uses: actions/cache@v3
with:
path: src/MAD-X/dist
key: "\
madx-${{ env.MADX_VERSION }}-\
${{ matrix.base }}-\
patches-${{ hashFiles('.github/patch/*') }}-\
scripts-${{ hashFiles('.github/build/linux/madx*') }}\
"
- run: git clone https://github.com/MethodicalAcceleratorDesign/MAD-X
src/MAD-X -b $MADX_VERSION --depth 1
if: steps.madx-build-cache.outputs.cache-hit != 'true'
- name: Set up QEMU for running arm64 containers
if: endsWith(matrix.base, '_aarch64')
uses: docker/setup-qemu-action@v3
- name: Prepare docker image
run: |
docker buildx build .github/build/linux \
--build-arg UID=`id -u` \
--build-arg GID=`id -g` \
--build-arg BASE=${{ matrix.base }} \
-t builder
shell: bash
- name: Build MAD-X
if: steps.madx-build-cache.outputs.cache-hit != 'true'
run: |
docker run --rm --init \
-w /mnt \
-v `pwd`:/mnt \
builder \
.github/build/linux/madx.sh src/MAD-X
shell: bash
- name: Build cpymad wheels
run: |
docker run --rm --init \
-w /mnt \
-v `pwd`:/mnt \
builder \
.github/build/linux/cpymad.sh src/MAD-X/dist
shell: bash
- name: Upload cpymad wheels
uses: actions/upload-artifact@v4
with:
name: dist-linux
path: dist
build_windows:
name: "Build: Windows"
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
update: true
path-type: inherit
install: mingw-w64-ucrt-x86_64-gcc
mingw-w64-ucrt-x86_64-gcc-fortran
mingw-w64-ucrt-x86_64-cmake
- run: echo "MSYSTEM=UCRT64" >> $GITHUB_ENV
- run: echo "MADX_VERSION=$(cat MADX_VERSION)" >> $GITHUB_ENV
- name: Download cached MAD-X build
id: madx-build-cache
uses: actions/cache@v3
with:
path: src/MAD-X/dist
key: "\
madx-${{ env.MADX_VERSION }}-\
windows-\
patches-${{ hashFiles('.github/patch/*') }}-\
scripts-${{ hashFiles('.github/build/windows/madx*') }}\
"
- run: git clone https://github.com/MethodicalAcceleratorDesign/MAD-X
src/MAD-X -b $MADX_VERSION --depth 1
if: steps.madx-build-cache.outputs.cache-hit != 'true'
- name: Build MAD-X
if: steps.madx-build-cache.outputs.cache-hit != 'true'
run: .github/build/windows/madx.sh src/MAD-X
- uses: actions/setup-python@v5
with: {python-version: "3.6"}
- run: .github/build/windows/cpymad.sh src/MAD-X/dist 3.6
- uses: actions/setup-python@v5
with: {python-version: "3.7"}
- run: .github/build/windows/cpymad.sh src/MAD-X/dist 3.7
- uses: actions/setup-python@v5
with: {python-version: "3.8"}
- run: .github/build/windows/cpymad.sh src/MAD-X/dist 3.8
- uses: actions/setup-python@v5
with: {python-version: "3.9"}
- run: .github/build/windows/cpymad.sh src/MAD-X/dist 3.9
- uses: actions/setup-python@v5
with: {python-version: "3.10"}
- run: .github/build/windows/cpymad.sh src/MAD-X/dist 3.10
- uses: actions/setup-python@v5
with: {python-version: "3.11"}
- run: .github/build/windows/cpymad.sh src/MAD-X/dist 3.11
- uses: actions/setup-python@v5
with: {python-version: "3.12"}
- run: .github/build/windows/cpymad.sh src/MAD-X/dist 3.12
- name: Upload cpymad wheels
uses: actions/upload-artifact@v4
with:
name: dist-windows
path: dist
build_macos:
name: "Build: MacOS"
runs-on: macos-11
strategy:
matrix:
arch:
- x86_64
- arm64
steps:
- uses: actions/checkout@v4
- run: echo "MADX_VERSION=$(cat MADX_VERSION)" >> $GITHUB_ENV
- name: Download cached MAD-X build
id: madx-build-cache
uses: actions/cache@v3
with:
path: src/MAD-X/dist
key: "\
madx-${{ env.MADX_VERSION }}-\
macos-${{ matrix.arch }}-\
patches-${{ hashFiles('.github/patch/*') }}-\
scripts-${{ hashFiles('.github/build/macos/madx*') }}\
"
- run: git clone https://github.com/MethodicalAcceleratorDesign/MAD-X
src/MAD-X -b $MADX_VERSION --depth 1
if: steps.madx-build-cache.outputs.cache-hit != 'true'
# Select matching Xcode and SDK, see: https://xcodereleases.com/
- run: |
sudo xcode-select -switch /Applications/Xcode_12.5.1.app
echo "SDKROOT=$(xcrun --show-sdk-path)" >> $GITHUB_ENV
- name: Setup gfortran
run: |
set -xeo pipefail
if [[ ${{ matrix.arch }} == "x86_64" ]]; then
FC=gfortran-11
LIBDIR=$(dirname $(find /usr/local/Cellar/gcc@11 -name libgfortran.dylib))
echo "MACOSX_DEPLOYMENT_TARGET=10.14" >> $GITHUB_ENV
elif [[ ${{ matrix.arch }} == "arm64" ]]; then
# See: https://github.com/MacPython/gfortran-install
name=gfortran-darwin-arm64-cross
curl -L -O https://github.com/isuruf/gcc/releases/download/gcc-11.3.0-2/${name}.tar.gz
sudo tar -f ${name}.tar.gz -C /opt -xzv
rm ${name}.tar.gz
FC=$(find /opt/${name}/bin -name "*-gfortran")
LIBDIR=$(dirname $(find /opt/${name}/lib -name libgfortran.dylib))
# See: https://github.com/pypa/cibuildwheel/discussions/997
echo "ARCHFLAGS=-arch arm64" >> $GITHUB_ENV
echo "_PYTHON_HOST_PLATFORM=macosx-11.0-arm64" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=11.0" >> $GITHUB_ENV
fi
LDFLAGS="-L$LIBDIR -Wl,-rpath,$LIBDIR"
echo "FC=$FC" >> $GITHUB_ENV # for cmake
echo "LDFLAGS=$LDFLAGS" >> $GITHUB_ENV # for setuptools
echo "LIBDIR=$LIBDIR" >> $GITHUB_ENV # for delocate step
- name: Build MAD-X
if: steps.madx-build-cache.outputs.cache-hit != 'true'
run: .github/build/macos/madx.sh src/MAD-X ${{ matrix.arch }}
- uses: actions/setup-python@v5
with: { python-version: "3.6" }
- run: .github/build/macos/cpymad.sh src/MAD-X/dist
- uses: actions/setup-python@v5
with: { python-version: "3.7" }
- run: .github/build/macos/cpymad.sh src/MAD-X/dist
- uses: actions/setup-python@v5
with: { python-version: "3.8" }
- run: .github/build/macos/cpymad.sh src/MAD-X/dist
- uses: actions/setup-python@v5
with: { python-version: "3.9" }
- run: .github/build/macos/cpymad.sh src/MAD-X/dist
- uses: actions/setup-python@v5
with: { python-version: "3.10" }
- run: .github/build/macos/cpymad.sh src/MAD-X/dist
- uses: actions/setup-python@v5
with: { python-version: "3.11" }
- run: .github/build/macos/cpymad.sh src/MAD-X/dist
- uses: actions/setup-python@v5
with: { python-version: "3.12" }
- run: .github/build/macos/cpymad.sh src/MAD-X/dist
- name: Fixup wheel dependencies
run: |
pip3 install delocate
DYLD_LIBRARY_PATH=$LIBDIR delocate-wheel dist/*.whl
DYLD_LIBRARY_PATH=$LIBDIR delocate-listdeps --all dist/*.whl
- name: Upload cpymad wheels
uses: actions/upload-artifact@v4
with:
name: dist-macos
path: dist
test:
name: Tests
runs-on: ${{ matrix.os == 'linux' && 'ubuntu' || matrix.os }}-latest
needs: [build_linux, build_windows, build_macos]
strategy:
matrix:
os:
- linux
- windows
- macos
python:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Download cpymad wheels
uses: actions/download-artifact@v3
with:
name: dist-${{ matrix.os }}
path: dist
- name: Install cpymad from wheel
run: |
set -ex
python -m pip install -U pip || sudo python -m pip install -U pip
pip install cpymad -f dist --no-index --no-deps
pip install cpymad
- run: pip install flake8 twine coverage coveralls pytest
- run: twine check dist/*
- run: flake8
- run: coverage run --source=cpymad -p -m pytest -v -k "not dframe"
- run: pip install pandas
- run: coverage run --source=cpymad -p -m pytest -v -k "dframe"
- run: coverage combine
- run: coveralls
if: inputs.COVERALLS_REPO_TOKEN != ''
env:
COVERALLS_REPO_TOKEN: ${{ inputs.COVERALLS_REPO_TOKEN }}
documentation:
name: Update documentation
needs: build_linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- uses: actions/download-artifact@v3
with:
name: dist-linux
path: dist
- run: sudo apt-get install -qy graphviz
- run: pip install -U pip
- run: pip install cpymad[doc] -f dist
- run: make -C doc html
- name: Deploy to GitHub Pages
if: success() && (
startsWith(github.ref, 'refs/tags/v') ||
github.ref == 'refs/heads/master')
uses: crazy-max/ghaction-github-pages@v4
with:
build_dir: doc/_build/html
commit_message: Build documentation from ${{ github.ref }}@${{ github.sha }}
jekyll: false
env:
GITHUB_TOKEN: ${{ github.token }}
upload_release:
name: Upload release
needs: test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Fetch built distributions
uses: actions/download-artifact@v3
with:
path: dist
- name: Merge artifacts to single folder
run: |
mv dist/dist-*/*.whl dist/
mv dist/dist-linux/*.tar.gz dist/
- name: Install twine
run: pip install twine
- name: Publish PyPI package
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*.whl dist/*.tar.gz
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}