forked from pybamm-team/PyBaMM
-
Notifications
You must be signed in to change notification settings - Fork 0
353 lines (313 loc) · 13.8 KB
/
publish_pypi.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
name: Build and publish package to PyPI
on:
release:
types: [published]
schedule:
# Run at 10 am UTC on day-of-month 1 and 15.
- cron: "0 10 1,15 * *"
workflow_dispatch:
inputs:
target:
description: 'Deployment target. Can be "pypi" or "testpypi"'
default: "testpypi"
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
# Set options available for all jobs that use cibuildwheel
env:
PYBAMM_DISABLE_TELEMETRY: "true"
# Increase pip debugging output, equivalent to `pip -vv`
CIBW_BUILD_VERBOSITY: 2
# Disable build isolation to allow pre-installing build-time dependencies.
# Note: CIBW_BEFORE_BUILD must be present in all jobs using cibuildwheel.
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
# Skip PyPy and MUSL builds in any and all jobs
CIBW_SKIP: "pp* *musllinux*"
FORCE_COLOR: 3
jobs:
build_windows_wheels:
name: Wheels (windows-latest)
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Get number of cores on Windows
id: get_num_cores
shell: python
run: |
from os import environ, cpu_count
num_cpus = cpu_count()
output_file = environ['GITHUB_OUTPUT']
with open(output_file, "a", encoding="utf-8") as output_stream:
output_stream.write(f"count={num_cpus}\n")
- name: Clone pybind11 repo (no history)
run: git clone --depth 1 --branch v2.12.0 https://github.com/pybind/pybind11.git -c advice.detachedHead=false
- name: Install vcpkg on Windows
run: |
cd C:\
rm -r -fo 'C:\vcpkg'
git clone https://github.com/microsoft/vcpkg
cd vcpkg
.\bootstrap-vcpkg.bat
- name: Cache packages installed through vcpkg on Windows
uses: actions/cache@v4
env:
cache-name: vckpg_binary_cache
with:
path: C:\Users\runneradmin\AppData\Local\vcpkg\archives
key: ${{ runner.os }}-build-VS2022-${{ env.cache-name }}-${{ hashFiles('vcpkg*.json') }}
# Enable tmate debugging of manually-triggered workflows if the input option was provided
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: Build 64-bit wheels on Windows
run: pipx run cibuildwheel --output-dir wheelhouse
env:
CIBW_ENVIRONMENT: >
PYBAMM_DISABLE_TELEMETRY="true"
PYBAMM_USE_VCPKG=ON
VCPKG_ROOT_DIR=C:\vcpkg
VCPKG_DEFAULT_TRIPLET=x64-windows-static-md
VCPKG_FEATURE_FLAGS=manifests,registries
CMAKE_GENERATOR="Visual Studio 17 2022"
CMAKE_GENERATOR_PLATFORM=x64
CMAKE_BUILD_PARALLEL_LEVEL=${{ steps.get_num_cores.outputs.count }}
CIBW_ARCHS: AMD64
CIBW_BEFORE_BUILD: python -m pip install setuptools wheel delvewheel # skip CasADi and CMake
# Fix access violation because GHA runners have modified PATH that picks wrong
# msvcp140.dll, see https://github.com/adang1345/delvewheel/issues/54
CIBW_REPAIR_WHEEL_COMMAND: delvewheel repair --add-path C:/Windows/System32 -w {dest_dir} {wheel}
CIBW_TEST_EXTRAS: "all,dev,jax"
CIBW_TEST_COMMAND: |
python -c "import pybamm; print(pybamm.IDAKLUSolver())"
python -m pytest -m cibw {project}/tests/unit
- name: Upload Windows wheels
uses: actions/[email protected]
with:
name: wheels_windows
path: ./wheelhouse/*.whl
if-no-files-found: error
build_manylinux_wheels:
name: Wheels (linux-amd64)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Check out PyBaMM repository
- uses: actions/setup-python@v5
name: Set up Python
with:
python-version: 3.11
- name: Clone pybind11 repo (no history)
run: git clone --depth 1 --branch v2.12.0 https://github.com/pybind/pybind11.git -c advice.detachedHead=false
- name: Build wheels on Linux
run: pipx run cibuildwheel --output-dir wheelhouse
env:
CIBW_ENVIRONMENT: >
PYBAMM_DISABLE_TELEMETRY="true"
CIBW_ARCHS_LINUX: x86_64
CIBW_BEFORE_ALL_LINUX: >
yum -y install openblas-devel lapack-devel &&
bash scripts/install_sundials.sh 6.0.3 6.5.0
CIBW_BEFORE_BUILD_LINUX: python -m pip install cmake casadi setuptools wheel
CIBW_REPAIR_WHEEL_COMMAND_LINUX: auditwheel repair -w {dest_dir} {wheel}
CIBW_TEST_EXTRAS: "all,dev,jax"
CIBW_TEST_COMMAND: |
set -e -x
python -c "import pybamm; print(pybamm.IDAKLUSolver())"
python -m pytest -m cibw {project}/tests/unit
- name: Upload wheels for Linux
uses: actions/[email protected]
with:
name: wheels_manylinux
path: ./wheelhouse/*.whl
if-no-files-found: error
build_macos_wheels:
name: Wheels (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-13, macos-14]
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Clone pybind11 repo (no history)
run: git clone --depth 1 --branch v2.12.0 https://github.com/pybind/pybind11.git -c advice.detachedHead=false
- name: Install cibuildwheel
run: python -m pip install cibuildwheel
- name: Build wheels on macOS
shell: bash
run: |
set -e -x
# Set LLVM-OpenMP URL
if [[ $(uname -m) == "x86_64" ]]; then
OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-64/llvm-openmp-11.1.0-hda6cdc1_1.tar.bz2"
elif [[ $(uname -m) == "arm64" ]]; then
OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-arm64/llvm-openmp-11.1.0-hf3c4609_1.tar.bz2"
fi
# Download gfortran with proper macOS minimum version (11.0)
if [[ $(uname -m) == "x86_64" ]]; then
GFORTRAN_URL="https://github.com/isuruf/gcc/releases/download/gcc-11.3.0-2/gfortran-darwin-x86_64-native.tar.gz"
KNOWN_SHA256="981367dd0ad4335613e91bbee453d60b6669f5d7e976d18c7bdb7f1966f26ae4 gfortran.tar.gz"
elif [[ $(uname -m) == "arm64" ]]; then
GFORTRAN_URL="https://github.com/isuruf/gcc/releases/download/gcc-11.3.0-2/gfortran-darwin-arm64-native.tar.gz"
KNOWN_SHA256="84364eee32ba843d883fb8124867e2bf61a0cd73b6416d9897ceff7b85a24604 gfortran.tar.gz"
fi
# Validate gfortran tarball
curl -L $GFORTRAN_URL -o gfortran.tar.gz
if ! echo "$KNOWN_SHA256" != "$(shasum --algorithm 256 gfortran.tar.gz)"; then
echo "Checksum failed"
exit 1
fi
mkdir -p gfortran_installed
tar -xv -C gfortran_installed/ -f gfortran.tar.gz
if [[ $(uname -m) == "x86_64" ]]; then
export FC=$(pwd)/gfortran_installed/gfortran-darwin-x86_64-native/bin/gfortran
export PATH=$(pwd)/gfortran_installed/gfortran-darwin-x86_64-native/bin:$PATH
elif [[ $(uname -m) == "arm64" ]]; then
export FC=$(pwd)/gfortran_installed/gfortran-darwin-arm64-native/bin/gfortran
export PATH=$(pwd)/gfortran_installed/gfortran-darwin-arm64-native/bin:$PATH
fi
# link libgfortran dylibs and place them in $HOME/.local/lib
# and then change rpath to $HOME/.local/lib for each of them
# Note: libgcc_s.1.dylib not available on macOS arm64; skip for now
mkdir -p $HOME/.local/lib
if [[ $(uname -m) == "x86_64" ]]; then
lib_dir=$(pwd)/gfortran_installed/gfortran-darwin-x86_64-native/lib
for lib in libgfortran.5.dylib libgfortran.dylib libquadmath.0.dylib libquadmath.dylib libgcc_s.1.dylib libgcc_s.1.1.dylib; do
cp $lib_dir/$lib $HOME/.local/lib/
install_name_tool -id $HOME/.local/lib/$lib $HOME/.local/lib/$lib
codesign --force --sign - $HOME/.local/lib/$lib
done
elif [[ $(uname -m) == "arm64" ]]; then
lib_dir=$(pwd)/gfortran_installed/gfortran-darwin-arm64-native/lib
for lib in libgfortran.5.dylib libgfortran.dylib libquadmath.0.dylib libquadmath.dylib libgcc_s.1.1.dylib; do
cp $lib_dir/$lib $HOME/.local/lib/
install_name_tool -id $HOME/.local/lib/$lib $HOME/.local/lib/$lib
codesign --force --sign - $HOME/.local/lib/$lib
done
fi
export SDKROOT=${SDKROOT:-$(xcrun --show-sdk-path)}
# Can't download LLVM-OpenMP directly, use conda/mamba and set environment variables
brew install miniforge
mamba create -n pybamm-dev $OPENMP_URL
if [[ $(uname -m) == "x86_64" ]]; then
PREFIX="/usr/local/Caskroom/miniforge/base/envs/pybamm-dev"
elif [[ $(uname -m) == "arm64" ]]; then
PREFIX="/opt/homebrew/Caskroom/miniforge/base/envs/pybamm-dev"
fi
# Copy libomp.dylib from PREFIX to $HOME/.local/lib, needed for wheel repair
cp $PREFIX/lib/libomp.dylib $HOME/.local/lib/
install_name_tool -id $HOME/.local/lib/libomp.dylib $HOME/.local/lib/libomp.dylib
codesign --force --sign - $HOME/.local/lib/libomp.dylib
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
export CFLAGS="$CFLAGS -I$PREFIX/include"
export CXXFLAGS="$CXXFLAGS -I$PREFIX/include"
export LDFLAGS="$LDFLAGS -L$PREFIX/lib -lomp"
# cibuildwheel not recognising its environment variable, so set manually
export CIBUILDWHEEL="1"
python scripts/install_KLU_Sundials.py
python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_ENVIRONMENT: >
PYBAMM_DISABLE_TELEMETRY="true"
# 10.13 for Intel (macos-13), 11.0 for Apple Silicon (macos-14 and macos-latest)
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.os == 'macos-14' && '11.0' || '10.13' }}
CIBW_ARCHS_MACOS: auto
CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate
CIBW_REPAIR_WHEEL_COMMAND: |
if [[ $(uname -m) == "x86_64" ]]; then
delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel}
elif [[ $(uname -m) == "arm64" ]]; then
# Use higher macOS target for now since casadi/libc++.1.0.dylib is still not fixed
delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} --require-target-macos-version 11.1
for file in {dest_dir}/*.whl; do mv "$file" "${file//macosx_11_1/macosx_11_0}"; done
fi
CIBW_TEST_EXTRAS: "all,dev,jax"
CIBW_TEST_COMMAND: |
set -e -x
python -c "import pybamm; print(pybamm.IDAKLUSolver())"
python -m pytest -m cibw {project}/tests/unit
- name: Upload wheels for macOS (amd64, arm64)
uses: actions/[email protected]
with:
name: wheels_${{ matrix.os }}
path: ./wheelhouse/*.whl
if-no-files-found: error
build_sdist:
name: Build SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Build SDist
run: pipx run build --sdist
- name: Upload SDist
uses: actions/[email protected]
with:
name: sdist
path: ./dist/*.tar.gz
if-no-files-found: error
publish_pypi:
# This job is only of value to PyBaMM and would always be skipped in forks
if: github.event_name != 'schedule' && github.repository == 'pybamm-team/PyBaMM'
name: Upload package to PyPI
needs: [
build_manylinux_wheels,
build_macos_wheels,
build_windows_wheels,
build_sdist
]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pybamm
permissions:
id-token: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Sanity check downloaded artifacts
run: ls -lA artifacts/
- name: Publish to PyPI
if: github.event.inputs.target == 'pypi' || github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: artifacts/
- name: Publish to TestPyPI
if: github.event.inputs.target == 'testpypi'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: artifacts/
repository-url: https://test.pypi.org/legacy/
open_failure_issue:
needs: [
build_windows_wheels,
build_manylinux_wheels,
build_macos_wheels,
build_sdist
]
name: Open an issue if build fails
if: ${{ always() && contains(needs.*.result, 'failure') && github.repository_owner == 'pybamm-team'}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LOGS: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
filename: .github/wheel_failure.md