Merge pull request #94 from srijanAtGithub/dev #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Publish | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| publish: | |
| name: Check version, build, and publish to PyPI | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version-file: ".python-version" | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Check version is bumped vs PyPI | |
| run: | | |
| # Read the version from pyproject.toml | |
| LOCAL_VERSION=$(python -c " | |
| import tomllib | |
| with open('pyproject.toml', 'rb') as f: | |
| data = tomllib.load(f) | |
| print(data['project']['version']) | |
| ") | |
| echo "Local version: $LOCAL_VERSION" | |
| # Fetch the latest published version from PyPI | |
| PYPI_RESPONSE=$(curl -s https://pypi.org/pypi/sicily/json || echo "NOT_FOUND") | |
| if echo "$PYPI_RESPONSE" | grep -q "NOT_FOUND\|Not Found\|404"; then | |
| echo "Package not yet on PyPI — first publish, skipping version check." | |
| else | |
| PYPI_VERSION=$(echo "$PYPI_RESPONSE" | python -c " | |
| import sys, json | |
| data = json.load(sys.stdin) | |
| print(data['info']['version']) | |
| ") | |
| echo "PyPI version: $PYPI_VERSION" | |
| # Compare using uv to temporarily install 'packaging' | |
| VERSION_OK=$(uv run --with packaging -- python -c " | |
| from packaging.version import Version | |
| local = Version('$LOCAL_VERSION') | |
| pypi = Version('$PYPI_VERSION') | |
| print('yes' if local > pypi else 'no') | |
| ") | |
| if [ "$VERSION_OK" != "yes" ]; then | |
| echo "" | |
| echo "ERROR: Version in pyproject.toml ($LOCAL_VERSION) must be greater than" | |
| echo " the current PyPI version ($PYPI_VERSION)." | |
| echo " Please bump the version before merging to main." | |
| exit 1 | |
| fi | |
| echo "Version check passed: $LOCAL_VERSION > $PYPI_VERSION" | |
| fi | |
| - name: Build package | |
| run: uv build | |
| - name: Publish to PyPI | |
| env: | |
| UV_PUBLISH_TOKEN: ${{ secrets.Sicily_Publishing_Token }} | |
| run: uv publish --token "$UV_PUBLISH_TOKEN" |