Deploy to PyPI #4
Workflow file for this run
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: Deploy to PyPI | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get current tag | |
| id: get_tag | |
| run: | | |
| # Get the tag that triggered this workflow | |
| TAG=$(git describe --tags --exact-match HEAD 2>/dev/null || echo "") | |
| if [ -z "$TAG" ]; then | |
| echo "Error: This workflow must be run from a tagged commit" | |
| echo "Please run this workflow from a release tag" | |
| exit 1 | |
| fi | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "✅ Running from tag: $TAG" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install build twine | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| TAG="${{ steps.get_tag.outputs.tag }}" | |
| # Remove 'v' prefix if present | |
| VERSION=${TAG#v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "📦 Building version: $VERSION" | |
| - name: Verify version matches pyproject.toml | |
| run: | | |
| PYPROJECT_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") | |
| TAG_VERSION="${{ steps.version.outputs.version }}" | |
| if [ "$PYPROJECT_VERSION" != "$TAG_VERSION" ]; then | |
| echo "❌ Version mismatch:" | |
| echo " pyproject.toml: $PYPROJECT_VERSION" | |
| echo " Tag: $TAG_VERSION" | |
| echo "Please ensure the version in pyproject.toml matches the release tag" | |
| exit 1 | |
| fi | |
| echo "✅ Version match confirmed: $TAG_VERSION" | |
| - name: Build package | |
| run: | | |
| echo "🔨 Building package..." | |
| python -m build | |
| echo "📦 Package built successfully" | |
| ls -la dist/ | |
| - name: Verify package contents | |
| run: | | |
| echo "🔍 Verifying package contents..." | |
| python -m twine check dist/* | |
| echo "✅ Package verification passed" | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| print-hash: true | |
| verbose: true | |
| - name: Create deployment summary | |
| if: success() | |
| run: | | |
| echo "## 🚀 Deployment Successful!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Package:** pytest-deepassert" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Tag:** ${{ steps.get_tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**PyPI:** https://pypi.org/project/pytest-deepassert/${{ steps.version.outputs.version }}/" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "The package has been successfully published to PyPI! 🎉" >> $GITHUB_STEP_SUMMARY |