name: Publish to PyPI
on:
release:
types: [created]
workflow_dispatch:
inputs:
version:
description: "Version to publish (leave empty to use pyproject.toml version)"
required: false
default: ""
jobs:
build_and_publish:
name: Build and publish to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install maturin twine
- name: Update version if provided
if: github.event.inputs.version != ''
run: |
sed -i "s/^version = \".*\"/version = \"${{ github.event.inputs.version }}\"/" pyproject.toml
echo "Publishing version ${{ github.event.inputs.version }}"
- name: Build package
env:
PYO3_USE_ABI3_FORWARD_COMPATIBILITY: 1
run: |
maturin build --release
- name: List built packages
run: |
ls -la target/wheels/
- name: Test package
run: |
WHEEL_PATH=$(ls -t target/wheels/*.whl | head -1)
python -m pip install $WHEEL_PATH
python -c "import denet; print(f'Successfully imported denet version: {denet.__version__}')"
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: target/wheels/
skip-existing: true
verbose: true