@@ -2,178 +2,9 @@ name: Build and publish package to PyPI
22on :
33 release :
44 types : [published]
5- schedule :
6- # Run at 10 am UTC on day-of-month 1 and 15.
7- - cron : " 0 10 1,15 * *"
8- workflow_dispatch :
9- inputs :
10- target :
11- description : ' Deployment target. Can be "pypi" or "testpypi"'
12- default : " testpypi"
13- debug_enabled :
14- type : boolean
15- description : ' Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
16- required : false
17- default : false
18-
19- # Set options available for all jobs that use cibuildwheel
20- env :
21- PYBAMM_DISABLE_TELEMETRY : " true"
22- # Increase pip debugging output, equivalent to `pip -vv`
23- CIBW_BUILD_VERBOSITY : 2
24- # Disable build isolation to allow pre-installing build-time dependencies.
25- # Note: CIBW_BEFORE_BUILD must be present in all jobs using cibuildwheel.
26- CIBW_BUILD_FRONTEND : " pip; args: --no-build-isolation"
27- # Skip PyPy and MUSL builds in any and all jobs
28- CIBW_SKIP : " pp* *musllinux*"
29- FORCE_COLOR : 3
305
316jobs :
32- build_windows_wheels :
33- name : Wheels (windows-latest)
34- runs-on : windows-latest
35- steps :
36- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
37- - uses : actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
38- with :
39- python-version : 3.11
40-
41- - name : Get number of cores on Windows
42- id : get_num_cores
43- shell : python
44- run : |
45- from os import environ, cpu_count
46- num_cpus = cpu_count()
47- output_file = environ['GITHUB_OUTPUT']
48- with open(output_file, "a", encoding="utf-8") as output_stream:
49- output_stream.write(f"count={num_cpus}\n")
50-
51- - name : Cache packages installed through vcpkg on Windows
52- uses : actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
53- env :
54- cache-name : vckpg_binary_cache
55- with :
56- path : C:\Users\runneradmin\AppData\Local\vcpkg\archives
57- key : ${{ runner.os }}-build-VS2022-${{ env.cache-name }}-${{ hashFiles('vcpkg*.json') }}
58-
59- # Enable tmate debugging of manually-triggered workflows if the input option was provided
60- - name : Setup tmate session
61- uses : mxschmitt/action-tmate@e5c7151931ca95bad1c6f4190c730ecf8c7dde48 # v3.19
62- if : ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
63-
64- - name : Build 64-bit wheels on Windows
65- run : pipx run cibuildwheel --output-dir wheelhouse
66- env :
67- CIBW_ENVIRONMENT : >
68- PYBAMM_DISABLE_TELEMETRY="true"
69- PYBAMM_USE_VCPKG=ON
70- VCPKG_ROOT_DIR=C:\vcpkg
71- VCPKG_DEFAULT_TRIPLET=x64-windows-static-md
72- VCPKG_FEATURE_FLAGS=manifests,registries
73- CMAKE_GENERATOR="Visual Studio 17 2022"
74- CMAKE_GENERATOR_PLATFORM=x64
75- CMAKE_BUILD_PARALLEL_LEVEL=${{ steps.get_num_cores.outputs.count }}
76- CIBW_ARCHS : AMD64
77- CIBW_BEFORE_BUILD : python -m pip install setuptools delvewheel # skip CasADi and CMake
78- # Fix access violation because GHA runners have modified PATH that picks wrong
79- # msvcp140.dll, see https://github.com/adang1345/delvewheel/issues/54
80- CIBW_REPAIR_WHEEL_COMMAND : delvewheel repair --add-path C:/Windows/System32 -w {dest_dir} {wheel}
81- CIBW_TEST_EXTRAS : " all,dev,jax"
82- CIBW_TEST_COMMAND : |
83- python -m pytest -m cibw {project}/tests/unit
84- - name : Upload Windows wheels
85- uses : actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
86- with :
87- name : wheels_windows
88- path : ./wheelhouse/*.whl
89- if-no-files-found : error
90-
91- build_manylinux_wheels :
92- name : Wheels (linux-amd64)
93- runs-on : ubuntu-latest
94- steps :
95- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
96- name : Check out PyBaMM repository
97-
98- - uses : actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
99- name : Set up Python
100- with :
101- python-version : 3.11
102-
103- - name : Build wheels on Linux
104- run : pipx run cibuildwheel --output-dir wheelhouse
105- env :
106- CIBW_ENVIRONMENT : >
107- PYBAMM_DISABLE_TELEMETRY="true"
108- CIBW_ARCHS_LINUX : x86_64
109- CIBW_BEFORE_BUILD_LINUX : python -m pip install setuptools
110- CIBW_REPAIR_WHEEL_COMMAND_LINUX : auditwheel repair -w {dest_dir} {wheel}
111- CIBW_TEST_EXTRAS : " all,dev,jax"
112- CIBW_TEST_COMMAND : |
113- set -e -x
114- python -m pytest -m cibw {project}/tests/unit
115-
116- - name : Upload wheels for Linux
117- uses : actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
118- with :
119- name : wheels_manylinux
120- path : ./wheelhouse/*.whl
121- if-no-files-found : error
122-
123- build_macos_wheels :
124- name : Wheels (${{ matrix.os }})
125- runs-on : ${{ matrix.os }}
126- strategy :
127- matrix :
128- os : [macos-13, macos-14]
129- fail-fast : false
130- steps :
131- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
132- - uses : actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
133- with :
134- python-version : ' 3.11'
135-
136- - name : Install cibuildwheel
137- run : python -m pip install cibuildwheel
138-
139- - name : Build wheels on macOS
140- shell : bash
141- run : |
142- set -e -x
143-
144- # cibuildwheel not recognising its environment variable, so set manually
145- export CIBUILDWHEEL="1"
146-
147- python -m cibuildwheel --output-dir wheelhouse
148- env :
149- CIBW_ENVIRONMENT : >
150- PYBAMM_DISABLE_TELEMETRY="true"
151- # 10.13 for Intel (macos-13), 11.0 for Apple Silicon (macos-14 and macos-latest)
152- MACOSX_DEPLOYMENT_TARGET : ${{ matrix.os == 'macos-14' && '11.0' || '10.13' }}
153- CIBW_ARCHS_MACOS : auto
154- CIBW_BEFORE_BUILD : python -m pip install setuptools delocate
155- CIBW_REPAIR_WHEEL_COMMAND : |
156- if [[ $(uname -m) == "x86_64" ]]; then
157- delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel}
158- elif [[ $(uname -m) == "arm64" ]]; then
159- # Use higher macOS target for now since casadi/libc++.1.0.dylib is still not fixed
160- delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel} --require-target-macos-version 11.1
161- for file in {dest_dir}/*.whl; do mv "$file" "${file//macosx_11_1/macosx_11_0}"; done
162- fi
163- CIBW_TEST_EXTRAS : " all,dev,jax"
164- CIBW_TEST_COMMAND : |
165- set -e -x
166- python -m pytest -m cibw {project}/tests/unit
167-
168- - name : Upload wheels for macOS (amd64, arm64)
169- uses : actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
170- with :
171- name : wheels_${{ matrix.os }}
172- path : ./wheelhouse/*.whl
173- if-no-files-found : error
174-
175- build_sdist :
176- name : Build SDist
7+ build :
1778 runs-on : ubuntu-latest
1789
17910 steps :
@@ -182,71 +13,31 @@ jobs:
18213 with :
18314 python-version : 3.12
18415
185- - name : Build SDist
186- run : pipx run build --sdist
16+ - name : Build wheel
17+ run : pipx run build --outdir deploy
18718
188- - name : Upload SDist
19+ - name : Upload package
18920 uses : actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
19021 with :
191- name : sdist
192- path : ./dist/*.tar.gz
22+ name : distributions
23+ path : deploy/
19324 if-no-files-found : error
19425
195- publish_pypi :
196- # This job is only of value to PyBaMM and would always be skipped in forks
197- if : github.event_name != 'schedule' && github.repository == 'pybamm-team/PyBaMM'
198- name : Upload package to PyPI
199- needs : [
200- build_manylinux_wheels,
201- build_macos_wheels,
202- build_windows_wheels,
203- build_sdist
204- ]
26+ publish :
27+ needs : build
20528 runs-on : ubuntu-latest
206- environment :
207- name : pypi
208- url : https://pypi.org/p/pybamm
29+ environment : pypi
20930 permissions :
21031 id-token : write
21132
21233 steps :
213- - name : Download all artifacts
34+ - name : Download artifacts
21435 uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
21536 with :
216- path : artifacts
37+ path : deploy
21738 merge-multiple : true
21839
219- - name : Sanity check downloaded artifacts
220- run : ls -lA artifacts/
221-
222- - name : Publish to PyPI
223- if : github.event.inputs.target == 'pypi' || github.event_name == 'release'
40+ - name : Publish on PyPI
22441 uses : pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3
22542 with :
226- packages-dir : artifacts/
227-
228- - name : Publish to TestPyPI
229- if : github.event.inputs.target == 'testpypi'
230- uses : pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3
231- with :
232- packages-dir : artifacts/
233- repository-url : https://test.pypi.org/legacy/
234-
235- open_failure_issue :
236- needs : [
237- build_windows_wheels,
238- build_manylinux_wheels,
239- build_macos_wheels,
240- build_sdist
241- ]
242- name : Open an issue if build fails
243- if : ${{ always() && contains(needs.*.result, 'failure') && github.repository_owner == 'pybamm-team'}}
244- runs-on : ubuntu-latest
245- steps :
246- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
247- - uses : JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
248- env :
249- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
250- LOGS : ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
251- with :
252- filename : .github/wheel_failure.md
43+ packages-dir : deploy/
0 commit comments