Skip to content

Build and Publish Python Package #2

Build and Publish Python Package

Build and Publish Python Package #2

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
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: |
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
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.version }}
release_name: Release v${{ steps.get_version.outputs.version }}
draft: false
prerelease: false
- name: Upload Release Assets
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.get_version.outputs.version }}
files: dist/*.whl
token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to PyPI
if: github.ref == 'refs/heads/main'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true