|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + deploy: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Check out code |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v4 |
| 17 | + with: |
| 18 | + python-version: '3.11' |
| 19 | + |
| 20 | + - name: Install Poetry |
| 21 | + uses: snok/install-poetry@v1 |
| 22 | + with: |
| 23 | + version: latest |
| 24 | + virtualenvs-create: true |
| 25 | + virtualenvs-in-project: true |
| 26 | + |
| 27 | + - name: Extract version from pyproject.toml |
| 28 | + id: get_version |
| 29 | + run: | |
| 30 | + # Extract version from [project] section |
| 31 | + VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") |
| 32 | + echo "project_version=$VERSION" >> $GITHUB_OUTPUT |
| 33 | + echo "Project version: $VERSION" |
| 34 | +
|
| 35 | + - name: Extract tag version |
| 36 | + id: get_tag |
| 37 | + run: | |
| 38 | + # Remove 'refs/tags/' prefix and optional 'v' prefix |
| 39 | + TAG_VERSION=${GITHUB_REF#refs/tags/} |
| 40 | + TAG_VERSION=${TAG_VERSION#v} |
| 41 | + echo "tag_version=$TAG_VERSION" >> $GITHUB_OUTPUT |
| 42 | + echo "Tag version: $TAG_VERSION" |
| 43 | +
|
| 44 | + - name: Verify version matches tag |
| 45 | + run: | |
| 46 | + if [ "${{ steps.get_version.outputs.project_version }}" != "${{ steps.get_tag.outputs.tag_version }}" ]; then |
| 47 | + echo "ERROR: Tag version (${{ steps.get_tag.outputs.tag_version }}) doesn't match project version (${{ steps.get_version.outputs.project_version }})" |
| 48 | + echo "Please ensure your git tag matches the version in pyproject.toml [project] section" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + echo "Version verification passed" |
| 52 | +
|
| 53 | + - name: Install dependencies |
| 54 | + run: poetry install --only-root |
| 55 | + |
| 56 | + - name: Build package |
| 57 | + run: poetry build |
| 58 | + |
| 59 | + - name: Verify build contents |
| 60 | + run: | |
| 61 | + echo "Built packages:" |
| 62 | + ls -la dist/ |
| 63 | + echo "Checking wheel contents:" |
| 64 | + python -m zipfile -l dist/*.whl | head -20 |
| 65 | +
|
| 66 | + - name: Publish to PyPI |
| 67 | + run: poetry publish --username __token__ --password ${{ secrets.PYPI_API_TOKEN }} |
| 68 | + |
| 69 | + - name: Verify publication |
| 70 | + run: | |
| 71 | + echo "🎉 Successfully published lightning-pose v${{ steps.get_version.outputs.project_version }} to PyPI!" |
| 72 | + echo "Package should be available at: https://pypi.org/project/lightning-pose/${{ steps.get_version.outputs.project_version }}/" |
0 commit comments