|
| 1 | +name: Release to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: 'Version to release (e.g., 0.1.0)' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-publish: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: '3.11' |
| 25 | + |
| 26 | + - name: Install build dependencies |
| 27 | + run: | |
| 28 | + python -m pip install --upgrade pip |
| 29 | + pip install build twine |
| 30 | + |
| 31 | + - name: Extract version from tag or input |
| 32 | + id: version |
| 33 | + run: | |
| 34 | + if [ "${{ github.event_name }}" == "release" ]; then |
| 35 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 36 | + VERSION=${VERSION#refs/tags/} |
| 37 | + else |
| 38 | + VERSION="${{ github.event.inputs.version }}" |
| 39 | + fi |
| 40 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 41 | + echo "Version: $VERSION" |
| 42 | + |
| 43 | + - name: Update version in pyproject.toml |
| 44 | + run: | |
| 45 | + VERSION="${{ steps.version.outputs.version }}" |
| 46 | + sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml |
| 47 | + |
| 48 | + - name: Update version in __init__.py |
| 49 | + run: | |
| 50 | + VERSION="${{ steps.version.outputs.version }}" |
| 51 | + sed -i "s/^__version__ = \".*\"/__version__ = \"$VERSION\"/" sentience/__init__.py |
| 52 | + |
| 53 | + - name: Build package |
| 54 | + run: | |
| 55 | + python -m build |
| 56 | + |
| 57 | + - name: Check package |
| 58 | + run: | |
| 59 | + twine check dist/* |
| 60 | + |
| 61 | + - name: Publish to PyPI |
| 62 | + env: |
| 63 | + TWINE_USERNAME: __token__ |
| 64 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 65 | + run: | |
| 66 | + twine upload dist/* |
| 67 | + |
| 68 | + - name: Create GitHub Release |
| 69 | + if: github.event_name == 'workflow_dispatch' |
| 70 | + uses: softprops/action-gh-release@v1 |
| 71 | + with: |
| 72 | + tag_name: v${{ steps.version.outputs.version }} |
| 73 | + name: Release v${{ steps.version.outputs.version }} |
| 74 | + body: | |
| 75 | + Release v${{ steps.version.outputs.version }} of sentience-python |
| 76 | + |
| 77 | + ## Installation |
| 78 | + ```bash |
| 79 | + pip install sentience-python==${{ steps.version.outputs.version }} |
| 80 | + ``` |
| 81 | + draft: false |
| 82 | + prerelease: false |
| 83 | + env: |
| 84 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + |
0 commit comments