|
| 1 | +# Adapted from example at |
| 2 | +# https://github.com/pypa/cibuildwheel/blob/0319c431dedc020eb/examples/github-deploy.yml |
| 3 | +# |
| 4 | +# Original license: |
| 5 | +# |
| 6 | +# This project is licensed under the 'BSD 2-clause license'. |
| 7 | +# |
| 8 | +# Copyright (c) 2017-2023, Joe Rickerby and contributors. All rights reserved. |
| 9 | +# |
| 10 | +# Redistribution and use in source and binary forms, with or without |
| 11 | +# modification, are permitted provided that the following conditions are met: |
| 12 | +# |
| 13 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 14 | +# list of conditions and the following disclaimer. |
| 15 | +# |
| 16 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 17 | +# this list of conditions and the following disclaimer in the documentation |
| 18 | +# and/or other materials provided with the distribution. |
| 19 | +# |
| 20 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 23 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 24 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 27 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 28 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | + |
| 31 | +name: Build (and upload to PyPI for published releases) |
| 32 | + |
| 33 | +on: |
| 34 | + workflow_dispatch: |
| 35 | + pull_request: |
| 36 | + push: |
| 37 | + branches: |
| 38 | + - main |
| 39 | + release: |
| 40 | + types: |
| 41 | + - published |
| 42 | + |
| 43 | +jobs: |
| 44 | + build_wheels: |
| 45 | + name: Build wheels on ${{ matrix.os }} |
| 46 | + runs-on: ${{ matrix.os }} |
| 47 | + strategy: |
| 48 | + matrix: |
| 49 | + # macos-13 is an intel runner, macos-14 is apple silicon |
| 50 | + os: [ubuntu-latest, windows-latest, macos-13, macos-14] |
| 51 | + |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v4 |
| 54 | + |
| 55 | + - name: Build wheels |
| 56 | + uses: pypa/cibuildwheel@v2.21.2 |
| 57 | + |
| 58 | + - uses: actions/upload-artifact@v4 |
| 59 | + with: |
| 60 | + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} |
| 61 | + path: ./wheelhouse/*.whl |
| 62 | + |
| 63 | + build_sdist: |
| 64 | + name: Build source distribution |
| 65 | + runs-on: ubuntu-latest |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Build sdist |
| 70 | + run: pipx run build --sdist |
| 71 | + |
| 72 | + - uses: actions/upload-artifact@v4 |
| 73 | + with: |
| 74 | + name: cibw-sdist |
| 75 | + path: dist/*.tar.gz |
| 76 | + |
| 77 | + upload_pypi: |
| 78 | + needs: [build_wheels, build_sdist] |
| 79 | + runs-on: ubuntu-latest |
| 80 | + environment: pypi |
| 81 | + permissions: |
| 82 | + id-token: write |
| 83 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 84 | + steps: |
| 85 | + - uses: actions/download-artifact@v4 |
| 86 | + with: |
| 87 | + # Unpack all CIBW artifacts (wheels + sdist) into dist/ |
| 88 | + # pypa/gh-action-pypi-publish action uploads contents of dist/ unconditionally |
| 89 | + pattern: cibw-* |
| 90 | + path: dist |
| 91 | + merge-multiple: true |
| 92 | + # Try publishing to Test PyPI first - if there are issues this should |
| 93 | + # cause job to fail before attempting to publish on PyPI itself |
| 94 | + - name: Publish package distribution to Test PyPI |
| 95 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 96 | + with: |
| 97 | + repository-url: https://test.pypi.org/legacy/ |
| 98 | + - name: Publish package distribution to PyPI |
| 99 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 100 | + |
0 commit comments