Test Publish to TestPyPI #26
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: Test Publish to TestPyPI | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to test (optional - uses current version if empty)' | |
| required: false | |
| type: string | |
| permissions: | |
| contents: read | |
| jobs: | |
| test-build-and-publish: | |
| name: Test Build and Publish to TestPyPI | |
| runs-on: ubuntu-latest | |
| environment: testpypi | |
| steps: | |
| - name: Checkout code | |
| 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: Extract version from pyproject.toml | |
| id: version | |
| run: | | |
| VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Building version: $VERSION" | |
| - name: Build package | |
| run: | | |
| python -m build | |
| echo "Built packages:" | |
| ls -la dist/ | |
| - name: Check package metadata | |
| run: | | |
| twine check dist/* | |
| echo "✅ Package metadata is valid" | |
| - name: Verify package contents | |
| run: | | |
| python -c " | |
| import zipfile | |
| import sys | |
| try: | |
| with zipfile.ZipFile('dist/ccnotify-${{ steps.version.outputs.version }}-py3-none-any.whl', 'r') as z: | |
| files = [f for f in z.namelist() if f.startswith('ccnotify/')] | |
| print(f'📦 Package contains {len(files)} files') | |
| for f in sorted(files)[:10]: # Show first 10 files | |
| print(f' {f}') | |
| if len(files) > 10: | |
| print(f' ... and {len(files) - 10} more files') | |
| except Exception as e: | |
| print(f'❌ Error checking package: {e}') | |
| sys.exit(1) | |
| " | |
| - name: Publish to TestPyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
| print-hash: true | |
| verbose: true | |
| - name: Wait for package availability | |
| run: | | |
| echo "⏳ Waiting 30 seconds for package to become available on TestPyPI..." | |
| sleep 30 | |
| - name: Test installation from TestPyPI | |
| run: | | |
| echo "🧪 Testing installation from TestPyPI..." | |
| python -m pip install --upgrade pip | |
| # Install from TestPyPI with fallback to PyPI for dependencies | |
| pip install \ | |
| --index-url https://test.pypi.org/simple/ \ | |
| --extra-index-url https://pypi.org/simple/ \ | |
| ccnotify==${{ steps.version.outputs.version }} | |
| # Test basic functionality | |
| python -c " | |
| import ccnotify | |
| print(f'✅ Successfully imported ccnotify v{ccnotify.__version__}') | |
| # Test version consistency | |
| if ccnotify.__version__ == '${{ steps.version.outputs.version }}': | |
| print('✅ Version matches expected') | |
| else: | |
| print(f'❌ Version mismatch: expected ${{ steps.version.outputs.version }}, got {ccnotify.__version__}') | |
| exit(1) | |
| " | |
| # Test CLI entry point | |
| ccnotify --version | |
| echo "✅ CLI entry point works correctly" | |
| - name: Create test summary | |
| run: | | |
| echo "## 🧪 TestPyPI Publication Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Package:** ccnotify" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**TestPyPI URL:** https://test.pypi.org/project/ccnotify/${{ steps.version.outputs.version }}/" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### ✅ Tests Passed" >> $GITHUB_STEP_SUMMARY | |
| echo "- Package build successful" >> $GITHUB_STEP_SUMMARY | |
| echo "- Metadata validation passed" >> $GITHUB_STEP_SUMMARY | |
| echo "- TestPyPI upload successful" >> $GITHUB_STEP_SUMMARY | |
| echo "- Installation test passed" >> $GITHUB_STEP_SUMMARY | |
| echo "- CLI functionality verified" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 🚀 Ready for Production" >> $GITHUB_STEP_SUMMARY | |
| echo "This version has been tested and is ready for production PyPI publishing." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Test Installation" >> $GITHUB_STEP_SUMMARY | |
| echo '```bash' >> $GITHUB_STEP_SUMMARY | |
| echo "pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ ccnotify==${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY |