Build and Publish Project on PyPI #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish Project on PyPI | |
on: | |
release: | |
workflow_dispatch: | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: pypi | |
cancel-in-progress: false | |
jobs: | |
build-sdist: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Set up Python (not macOS) | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.13 | |
- name: Install build tools | |
run: | | |
python -m pip install --upgrade pip | |
pip install build | |
- name: Build source distribution (sdist) | |
run: | | |
python -m build --sdist --outdir dist | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: builds-sdist | |
path: dist-sdist | |
build-wheels: | |
runs-on: ${{ matrix.platform }} | |
strategy: | |
matrix: | |
platform: [ubuntu-latest, macos-latest] | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Set up Python (not macOS) | |
if: matrix.platform != 'macos-latest' | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.13 | |
- name: Install pyenv (only macOS) | |
if: matrix.platform == 'macos-latest' | |
run: | | |
brew update | |
brew install pyenv | |
echo 'eval "$(pyenv init --path)"' >> ~/.zshrc | |
echo 'eval "$(pyenv init -)"' >> ~/.zshrc | |
source ~/.zshrc | |
pyenv install 3.10 | |
pyenv install 3.11 | |
pyenv install 3.12 | |
pyenv global 3.10 3.11 3.12 | |
- name: Install cibuildwheel | |
run: | | |
python -m pip install --upgrade pip | |
pip install cibuildwheel | |
- name: Build wheels | |
run: | | |
cibuildwheel --output-dir dist | |
env: | |
CIBW_PLATFORM: ${{ matrix.platform == 'ubuntu-latest' && 'linux' || matrix.platform == 'macos-latest' && 'macos' }} | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: builds-${{ matrix.platform }} | |
path: dist-${{ matrix.platform }} | |
publish: | |
runs-on: ubuntu-latest | |
needs: | |
- build-sdist | |
- build-wheels | |
# This environment is used for publishing on PyPI | |
environment: publish-pypi | |
permissions: | |
# IMPORTANT: this permission is mandatory for Trusted Publishing | |
id-token: write | |
steps: | |
- name: Download source distribution | |
uses: actions/download-artifact@v3 | |
with: | |
name: builds-sdist | |
path: dist-sdist | |
- name: Download Linux wheels | |
uses: actions/download-artifact@v3 | |
with: | |
name: builds-ubuntu-latest | |
path: dist-ubuntu-latest | |
- name: Download macOS wheels | |
uses: actions/download-artifact@v3 | |
with: | |
name: builds-macos-latest | |
path: dist-macos-latest | |
- name: Merge wheels | |
run: | | |
mkdir -p dist | |
mv dist-sdist/* dist-ubuntu-latest/* dist-macos-latest/* dist/ | |
- name: Publish on PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 |