|
1 | | -name: Publish SuperGemini to PyPI |
| 1 | +name: Publish to PyPI |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - "v*" |
| 4 | + # Trigger on new releases |
7 | 5 | release: |
8 | 6 | types: [published] |
| 7 | + |
| 8 | + # Allow manual triggering |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + target: |
| 12 | + description: 'Publication target' |
| 13 | + required: true |
| 14 | + default: 'testpypi' |
| 15 | + type: choice |
| 16 | + options: |
| 17 | + - testpypi |
| 18 | + - pypi |
| 19 | + |
| 20 | +# Restrict permissions for security |
| 21 | +permissions: |
| 22 | + contents: read |
9 | 23 |
|
10 | 24 | jobs: |
11 | | - build: |
| 25 | + build-and-publish: |
| 26 | + name: Build and publish Python package |
12 | 27 | runs-on: ubuntu-latest |
13 | | - |
| 28 | + environment: |
| 29 | + name: ${{ github.event_name == 'release' && 'pypi' || 'testpypi' }} |
| 30 | + url: ${{ github.event_name == 'release' && 'https://pypi.org/p/SuperGemini' || 'https://test.pypi.org/p/SuperGemini' }} |
| 31 | + |
14 | 32 | steps: |
15 | | - - name: Checkout source |
16 | | - uses: actions/checkout@v4 |
17 | | - |
18 | | - - name: Set up Python |
19 | | - uses: actions/setup-python@v5 |
20 | | - with: |
21 | | - python-version: "3.11" |
22 | | - |
23 | | - - name: Install build dependencies |
24 | | - run: | |
25 | | - python -m pip install --upgrade pip |
26 | | - pip install build setuptools wheel twine |
| 33 | + - name: Checkout repository |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + # Fetch full history for proper version detection |
| 37 | + fetch-depth: 0 |
| 38 | + |
| 39 | + - name: Set up Python |
| 40 | + uses: actions/setup-python@v5 |
| 41 | + with: |
| 42 | + python-version: '3.11' |
| 43 | + cache: 'pip' |
| 44 | + |
| 45 | + - name: Install build dependencies |
| 46 | + run: | |
| 47 | + python -m pip install --upgrade pip |
| 48 | + python -m pip install build twine |
| 49 | + |
| 50 | + - name: Verify package structure |
| 51 | + run: | |
| 52 | + echo "📦 Checking package structure..." |
| 53 | + ls -la |
| 54 | + echo "🔍 Checking SuperGemini package..." |
| 55 | + ls -la SuperGemini/ |
| 56 | + echo "🔍 Checking setup package..." |
| 57 | + ls -la setup/ |
| 58 | + |
| 59 | + # Verify VERSION file exists |
| 60 | + echo "📋 Checking VERSION file..." |
| 61 | + if [ -f "VERSION" ]; then |
| 62 | + echo "VERSION file content:" |
| 63 | + cat VERSION |
| 64 | + else |
| 65 | + echo "❌ VERSION file not found!" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + |
| 69 | + # Verify package can be imported |
| 70 | + echo "🔍 Testing package import..." |
| 71 | + python -c " |
| 72 | + import sys |
| 73 | + sys.path.insert(0, '.') |
| 74 | + import SuperGemini |
| 75 | + print(f'✅ SuperGemini package imported successfully') |
| 76 | + " |
| 77 | + |
| 78 | + - name: Clean previous builds |
| 79 | + run: | |
| 80 | + rm -rf dist/ build/ *.egg-info/ |
| 81 | + |
| 82 | + - name: Build package |
| 83 | + run: | |
| 84 | + echo "🔨 Building package..." |
| 85 | + python -m build |
| 86 | + echo "📦 Built files:" |
| 87 | + ls -la dist/ |
| 88 | + |
| 89 | + - name: Validate package |
| 90 | + run: | |
| 91 | + echo "🔍 Validating package..." |
| 92 | + python -m twine check dist/* |
| 93 | + |
| 94 | + # Upload to TestPyPI for testing (manual trigger or non-release) |
| 95 | + - name: Upload to TestPyPI |
| 96 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'testpypi' |
| 97 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 98 | + with: |
| 99 | + repository-url: https://test.pypi.org/legacy/ |
| 100 | + password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 101 | + print-hash: true |
| 102 | + |
| 103 | + # Upload to production PyPI (only on releases) |
| 104 | + - name: Upload to PyPI |
| 105 | + if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'pypi') |
| 106 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 107 | + with: |
| 108 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 109 | + print-hash: true |
| 110 | + |
| 111 | + - name: Create deployment summary |
| 112 | + if: always() |
| 113 | + run: | |
| 114 | + echo "## 📦 SuperGemini Package Deployment" >> $GITHUB_STEP_SUMMARY |
| 115 | + echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY |
| 116 | + echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY |
| 117 | + echo "| Target | ${{ github.event_name == 'release' && 'PyPI (Production)' || github.event.inputs.target || 'TestPyPI' }} |" >> $GITHUB_STEP_SUMMARY |
| 118 | + echo "| Trigger | ${{ github.event_name }} |" >> $GITHUB_STEP_SUMMARY |
| 119 | + echo "| Version | $(cat VERSION 2>/dev/null || echo 'Unknown') |" >> $GITHUB_STEP_SUMMARY |
| 120 | + echo "| Commit | ${{ github.sha }} |" >> $GITHUB_STEP_SUMMARY |
| 121 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 122 | + |
| 123 | + if [ "${{ github.event_name }}" == "release" ]; then |
| 124 | + echo "🎉 **Production release published to PyPI!**" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "Install with: \`pip install SuperGemini\`" >> $GITHUB_STEP_SUMMARY |
| 126 | + else |
| 127 | + echo "🧪 **Test release published to TestPyPI**" >> $GITHUB_STEP_SUMMARY |
| 128 | + echo "Test install with: \`pip install --index-url https://test.pypi.org/simple/ SuperGemini\`" >> $GITHUB_STEP_SUMMARY |
| 129 | + fi |
27 | 130 |
|
28 | | - - name: Build SuperGemini package |
29 | | - run: python -m build |
30 | | - |
31 | | - - name: Publish to PyPI |
32 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
33 | | - with: |
34 | | - user: __token__ |
35 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
| 131 | + test-installation: |
| 132 | + name: Test package installation |
| 133 | + needs: build-and-publish |
| 134 | + runs-on: ubuntu-latest |
| 135 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.target == 'testpypi' |
| 136 | + |
| 137 | + steps: |
| 138 | + - name: Set up Python |
| 139 | + uses: actions/setup-python@v5 |
| 140 | + with: |
| 141 | + python-version: '3.11' |
| 142 | + |
| 143 | + - name: Test installation from TestPyPI |
| 144 | + run: | |
| 145 | + echo "🧪 Testing installation from TestPyPI..." |
| 146 | + |
| 147 | + # Wait a bit for the package to be available |
| 148 | + sleep 30 |
| 149 | + |
| 150 | + # Install from TestPyPI |
| 151 | + pip install --index-url https://test.pypi.org/simple/ \ |
| 152 | + --extra-index-url https://pypi.org/simple/ \ |
| 153 | + SuperGemini |
| 154 | + |
| 155 | + # Test basic import |
| 156 | + python -c " |
| 157 | + import SuperGemini |
| 158 | + print(f'✅ Successfully imported SuperGemini') |
| 159 | + |
| 160 | + # Test CLI entry points |
| 161 | + import subprocess |
| 162 | + |
| 163 | + # Test SuperGemini command |
| 164 | + try: |
| 165 | + result = subprocess.run(['SuperGemini', '--help'], capture_output=True, text=True, timeout=10) |
| 166 | + print(f'✅ SuperGemini CLI available') |
| 167 | + except Exception as e: |
| 168 | + print(f'⚠️ SuperGemini CLI test: {e}') |
| 169 | + |
| 170 | + # Test supergemini command |
| 171 | + try: |
| 172 | + result = subprocess.run(['supergemini', '--help'], capture_output=True, text=True, timeout=10) |
| 173 | + print(f'✅ supergemini CLI available') |
| 174 | + except Exception as e: |
| 175 | + print(f'⚠️ supergemini CLI test: {e}') |
| 176 | + |
| 177 | + # Test sg command |
| 178 | + try: |
| 179 | + result = subprocess.run(['sg', '--help'], capture_output=True, text=True, timeout=10) |
| 180 | + print(f'✅ sg CLI available') |
| 181 | + except Exception as e: |
| 182 | + print(f'⚠️ sg CLI test: {e}') |
| 183 | + " |
| 184 | + |
| 185 | + echo "✅ Installation test completed successfully!" |
0 commit comments