Skip to content

Merge pull request #40 from remichu-ai/transformer_multimodal #2

Merge pull request #40 from remichu-ai/transformer_multimodal

Merge pull request #40 from remichu-ai/transformer_multimodal #2

name: Publish Python Package to PyPI
on:
push:
branches:
- main
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for checking version changes
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine packaging
- name: Build package
run: python -m build
# Add step to extract current version
- name: Get current version
id: current_version
run: |
# Try to get version from pyproject.toml first
if [ -f "pyproject.toml" ]; then
VERSION=$(grep -Po "(?<=version = \")[^\"]*" pyproject.toml)
# Fallback to setup.py
elif [ -f "setup.py" ]; then
VERSION=$(python setup.py --version)
else
echo "No version file found"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# Check if version exists on PyPI
- name: Check if version exists on PyPI
id: check_version
run: |
# Get package name from setup.py or pyproject.toml
if [ -f "pyproject.toml" ]; then
PACKAGE_NAME=$(grep -Po "(?<=name = \")[^\"]*" pyproject.toml)
elif [ -f "setup.py" ]; then
PACKAGE_NAME=$(python setup.py --name)
else
echo "No package configuration found"
exit 1
fi
VERSION="${{ steps.current_version.outputs.version }}"
# Check if version already exists on PyPI
if pip index versions "$PACKAGE_NAME" 2>/dev/null | grep -q "^$VERSION$"; then
echo "Version $VERSION already exists on PyPI"
echo "should_publish=false" >> "$GITHUB_OUTPUT"
else
echo "Version $VERSION is new"
echo "should_publish=true" >> "$GITHUB_OUTPUT"
fi
- name: Publish to PyPI
if: steps.check_version.outputs.should_publish == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m twine upload dist/*
- name: Log skip publication
if: steps.check_version.outputs.should_publish != 'true'
run: |
echo "Skipping publication to PyPI as version ${{ steps.current_version.outputs.version }} already exists"