Skip to content

Publish Python Packages #1

Publish Python Packages

Publish Python Packages #1

Workflow file for this run

name: Publish Python Packages
on:
release:
types: [created]
workflow_dispatch:
inputs:
build_wheels:
description: 'Build platform-specific wheels'
required: true
default: 'false'
type: boolean
permissions:
contents: read
id-token: write
concurrency:
group: "publish"
cancel-in-progress: true
jobs:
build-wheels:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
name: Build and publish Python package (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- name: Skip wheels for pure Python package
if: ${{ !inputs.build_wheels }}
run: |
echo "Skipping wheel build - this is *probably* a pure Python package"
shell: bash
- name: Build real wheels
if: ${{ inputs.build_wheels }}
uses: actions/checkout@v3
- name: Set up Python
if: ${{ inputs.build_wheels }}
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
if: ${{ inputs.build_wheels }}
run: |
python -m pip install --upgrade pip
pip install cibuildwheel
shell: bash
- name: Build package
if: ${{ inputs.build_wheels }}
env:
CIBW_SKIP: "pp* *-musllinux*" # Skip PyPy and musllinux builds
run: |
cibuildwheel --output-dir dist
- name: Upload wheel artifacts
if: ${{ inputs.build_wheels }}
uses: actions/upload-artifact@v3
with:
name: wheels-${{ matrix.os }}
path: |
dist/*.whl
build-source-dist:
name: Build and publish Python package (source distribution)
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
shell: bash
- name: Build source distribution
run: |
python -m build --sdist --outdir dist
- name: Upload source distribution
uses: actions/upload-artifact@v3
with:
name: source-dist
path: |
dist/*.tar.gz
publish-wheels:
needs: [build-wheels, build-source-dist]
name: Publish Python wheels
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- name: Download all wheels
uses: actions/download-artifact@v3
with:
path: dist
- name: Move wheels to dist directory
run: |
mkdir -p final_dist
find dist -name "*.whl" -exec mv {} final_dist/ \;
find dist -name "*.tar.gz" -exec mv {} final_dist/ \;
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: final_dist/