Skip to content

Build and deploy wheels #58

Build and deploy wheels

Build and deploy wheels #58

Workflow file for this run

name: Build and deploy wheels
on:
push:
tags:
- v*
workflow_dispatch:
inputs:
os_choice:
description: 'Choose what to build'
required: true
default: 'all'
type: choice
options:
- all
- sdist-only
- ubuntu-latest
- windows-latest
- macos-latest
jobs:
build_wheels_ubuntu:
name: Build wheels on ubuntu-latest
runs-on: ubuntu-latest
steps:
- name: Check if build is needed
id: check_build
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "build_needed=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.os_choice }}" = "all" ] || [ "${{ github.event.inputs.os_choice }}" = "ubuntu-latest" ]; then
echo "build_needed=true" >> $GITHUB_OUTPUT
else
echo "build_needed=false" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
- name: Set up Python 3.11
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Build wheels
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: pypa/[email protected]
with:
output-dir: ./wheelhouse
- name: Upload wheels
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: actions/upload-artifact@v4
with:
name: wheels-ubuntu-latest
path: ./wheelhouse/*.whl
overwrite: true
build_wheels_windows:
name: Build wheels on windows-latest
runs-on: windows-latest
steps:
- name: Check if build is needed
id: check_build
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "build_needed=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.os_choice }}" = "all" ] || [ "${{ github.event.inputs.os_choice }}" = "windows-latest" ]; then
echo "build_needed=true" >> $GITHUB_OUTPUT
else
echo "build_needed=false" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
- name: Set up Python 3.11
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Build wheels
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: pypa/[email protected]
with:
output-dir: ./wheelhouse
- name: Upload wheels
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: actions/upload-artifact@v4
with:
name: wheels-windows-latest
path: ./wheelhouse/*.whl
overwrite: true
build_wheels_macos:
name: Build wheels on macos-latest
runs-on: macos-latest
steps:
- name: Check if build is needed
id: check_build
shell: bash
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "build_needed=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.os_choice }}" = "all" ] || [ "${{ github.event.inputs.os_choice }}" = "macos-latest" ]; then
echo "build_needed=true" >> $GITHUB_OUTPUT
else
echo "build_needed=false" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
- name: Set up Python 3.11
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Build wheels
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: pypa/[email protected]
with:
output-dir: ./wheelhouse
- name: Upload wheels
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: actions/upload-artifact@v4
with:
name: wheels-macos-latest
path: ./wheelhouse/*.whl
overwrite: true
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- name: Check if build is needed
id: check_build
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "build_needed=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event.inputs.os_choice }}" = "all" ] || [ "${{ github.event.inputs.os_choice }}" = "sdist-only" ]; then
echo "build_needed=true" >> $GITHUB_OUTPUT
else
echo "build_needed=false" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v4
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
- name: Set up Python 3.11
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install build dependencies
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
run: python -m pip install --upgrade pip build
- name: Build sdist
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
run: python -m build --sdist
- name: Upload sdist
if: ${{ steps.check_build.outputs.build_needed == 'true' }}
uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
overwrite: true
upload_pypi:
name: Upload to PyPI
needs:
- build_wheels_ubuntu
- build_wheels_windows
- build_wheels_macos
- build_sdist
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
steps:
- name: Download Ubuntu wheels
uses: actions/download-artifact@v4
with:
name: wheels-ubuntu-latest
path: dist/
continue-on-error: true
- name: Download Windows wheels
uses: actions/download-artifact@v4
with:
name: wheels-windows-latest
path: dist/
continue-on-error: true
- name: Download macOS wheels
uses: actions/download-artifact@v4
with:
name: wheels-macos-latest
path: dist/
continue-on-error: true
- name: Download sdist
uses: actions/download-artifact@v4
with:
name: sdist
path: dist/
continue-on-error: true
- name: List artifacts (debug)
run: ls dist || echo "No artifacts found."
- name: Upload to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
pip install twine
twine upload dist/*