From 3046f825709d4e10ace2799ce57e978a9ca5441d Mon Sep 17 00:00:00 2001 From: Jeong-Yoon Lee Date: Fri, 19 Apr 2024 10:52:30 -0700 Subject: [PATCH] update python-publish GHA to build multi-platform wheels --- .github/workflows/python-publish.yml | 73 ++++++++++++++++++++-------- .gitignore | 1 + pyproject.toml | 4 ++ 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index bfa1a44a..d02c7977 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -1,5 +1,6 @@ # This workflow will upload a Python Package using Twine when a release is created # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries +# Updated with cibuildwheel: https://learn.scientific-python.org/development/guides/gha-wheels/ # This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by @@ -9,32 +10,62 @@ name: Upload Python Package on: + workflow_dispatch: release: - types: [published] + types: + - published jobs: - deploy: - + make_sdist: + name: Make SDist runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Optional, use if you use setuptools_scm + submodules: false # Optional, use if you have submodules + + - name: Build SDist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: dist/*.tar.gz + + build_wheels: + name: Wheel on ${{ matrix.os }} + runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: - python-version: ['3.8'] + os: [ubuntu-latest, windows-latest, macos-13, macos-14] steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -U setuptools wheel twine build - - name: Build and publish - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: | - pip install . - python -m build - python -m twine upload dist/*.tar.gz + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + + - uses: pypa/cibuildwheel@v2.17 + + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }} + path: wheelhouse/*.whl + + upload_all: + needs: [build_wheels, make_sdist] + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + steps: + - uses: actions/download-artifact@v4 + with: + pattern: cibw-* + path: dist + merge-multiple: true + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.gitignore b/.gitignore index 4ca21107..603e1d20 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ env_docs/ __pycache__ build dist +wheelhouse *.pyc _build/ .ipynb_checkpoints/ diff --git a/pyproject.toml b/pyproject.toml index c771f022..3bd41679 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,3 +68,7 @@ requires = [ [project.urls] homepage = "https://github.com/uber/causalml" + +[tool.cibuildwheel] +build = ["cp38-*", "cp39-*", "cp310-*", "cp311-*"] +build-verbosity = 1