Skip to content

Build and Publish Python Package #4

Build and Publish Python Package

Build and Publish Python Package #4

name: Build and Publish Python Package
on:
push:
branches: [main]
paths:
- 'setup.py' # Trigger on version changes in setup.py
workflow_dispatch: # Allow manual triggering
# Add permissions section
permissions:
contents: write
packages: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Extract version from setup.py
id: get_version
run: |
VERSION=$(grep -o "version=\"[0-9]\+\.[0-9]\+\.[0-9]\+\"" setup.py | grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+")
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build wheel setuptools twine
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build package
run: |
# Create pyproject.toml to ensure build works even without one
if [ ! -f pyproject.toml ]; then
echo "Creating minimal pyproject.toml"
echo "[build-system]" > pyproject.toml
echo "requires = ['setuptools>=42', 'wheel']" >> pyproject.toml
echo "build-backend = 'setuptools.build_meta'" >> pyproject.toml
fi
python -m build
python setup.py sdist bdist_wheel
- name: List built distributions
run: ls -l dist/
- name: Store wheel artifact
uses: actions/upload-artifact@v4
with:
name: wheel-package
path: dist/*.whl
# The wheel will have the naming format: ttnn_trace_viewer-version-py3-none-any.whl
- name: Create Release and Upload Assets
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.get_version.outputs.version }}
name: Release v${{ steps.get_version.outputs.version }}
draft: false
prerelease: false
files: dist/*.whl
token: ${{ secrets.GITHUB_TOKEN }}