Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
name: Publish to PyPI

on:
workflow_dispatch:
inputs:
version_increment:
description: 'Version increment type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
- custom
custom_version:
description: 'Custom version (only if "custom" is selected above)'
required: false
type: string
create_release:
description: 'Create GitHub release'
required: true
default: true
type: boolean

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9, "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
pip install -r requirements.txt

- name: Build package
run: python -m build

- name: Check package
run: twine check dist/*

publish:
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- 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

- name: Calculate new version
id: version
run: |
# Get current version from setup.py
CURRENT_VERSION=$(python -c "
import re
with open('setup.py', 'r') as f:
content = f.read()
match = re.search(r\"version='([^']+)'\", content)
print(match.group(1) if match else '1.0.7')
")

echo "Current version: $CURRENT_VERSION"

if [ "${{ github.event.inputs.version_increment }}" = "custom" ]; then
NEW_VERSION="${{ github.event.inputs.custom_version }}"
else
# Parse current version
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}

case "${{ github.event.inputs.version_increment }}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac

NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
fi

echo "New version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV

- name: Update version in setup.py
run: |
sed -i "s/version='[^']*'/version='${{ steps.version.outputs.NEW_VERSION }}'/" setup.py
echo "Updated setup.py with version ${{ steps.version.outputs.NEW_VERSION }}"

# Show the change
grep "version=" setup.py

- name: Build package
run: python -m build

- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*

- name: Commit version bump
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add setup.py
git commit -m "Bump version to ${{ steps.version.outputs.NEW_VERSION }}"
git push

- name: Create GitHub Release
if: ${{ github.event.inputs.create_release == 'true' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.NEW_VERSION }}
release_name: BookNLP Plus v${{ steps.version.outputs.NEW_VERSION }}
body: |
🚀 **BookNLP Plus v${{ steps.version.outputs.NEW_VERSION }}**

**Install with:**
```bash
pip install booknlp-plus==${{ steps.version.outputs.NEW_VERSION }}
```

**What's New:**
- Manual release triggered by @${{ github.actor }}
- Compatible with Python 3.9-3.12
- Enhanced fork with JSON patch support and sentence transformers

**Links:**
- 📦 [PyPI Package](https://pypi.org/project/booknlp-plus/${{ steps.version.outputs.NEW_VERSION }}/)
- 🔗 [Original BookNLP](https://github.com/dbamman/book-nlp)
- 📋 [Full Changelog](https://github.com/DrewThomasson/booknlp/compare/v${{ steps.version.outputs.NEW_VERSION }}...json-patch-1)

Built from commit: ${{ github.sha }}
draft: false
prerelease: false

notify:
needs: publish
runs-on: ubuntu-latest
if: success()

steps:
- name: Success notification
run: |
echo "🎉 Successfully published booknlp-plus v${{ needs.publish.outputs.NEW_VERSION || env.NEW_VERSION }} to PyPI!"
echo "📦 Install with: pip install booknlp-plus"
echo "🔗 View on PyPI: https://pypi.org/project/booknlp-plus/"
Loading