|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + publish_to_pypi: |
| 7 | + description: 'Publish to PyPI? Type "yes" to confirm' |
| 8 | + required: true |
| 9 | + default: 'no' |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - 'no' |
| 13 | + - 'yes' |
| 14 | + version_tag: |
| 15 | + description: 'Version tag (e.g., v0.1.0)' |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + |
| 19 | +jobs: |
| 20 | + test: |
| 21 | + name: Run tests |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Install uv |
| 28 | + uses: astral-sh/setup-uv@v4 |
| 29 | + with: |
| 30 | + version: "latest" |
| 31 | + |
| 32 | + - uses: actions/setup-python@v5 |
| 33 | + with: |
| 34 | + python-version: "3.12" |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: uv sync --group dev |
| 38 | + |
| 39 | + - name: Run tests |
| 40 | + run: uv run pytest tests/ -v |
| 41 | + |
| 42 | + build-and-publish: |
| 43 | + name: Build and Publish |
| 44 | + needs: test |
| 45 | + runs-on: ubuntu-latest |
| 46 | + permissions: |
| 47 | + contents: write |
| 48 | + |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v4 |
| 51 | + |
| 52 | + - name: Install uv |
| 53 | + uses: astral-sh/setup-uv@v4 |
| 54 | + with: |
| 55 | + version: "latest" |
| 56 | + |
| 57 | + - uses: actions/setup-python@v5 |
| 58 | + with: |
| 59 | + python-version: "3.12" |
| 60 | + |
| 61 | + - name: Install build tools |
| 62 | + run: pip install twine |
| 63 | + |
| 64 | + - name: Build package |
| 65 | + run: uv build |
| 66 | + |
| 67 | + - name: Check package |
| 68 | + run: | |
| 69 | + twine check dist/* |
| 70 | + ls -la dist/ |
| 71 | + echo "📦 Package version: $(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")" |
| 72 | +
|
| 73 | + - name: Confirm before publish |
| 74 | + if: github.event.inputs.publish_to_pypi == 'yes' |
| 75 | + run: | |
| 76 | + echo "⚠️ About to publish to PyPI (PRODUCTION)" |
| 77 | + echo "📦 Package contents:" |
| 78 | + ls -la dist/ |
| 79 | + echo "✅ Proceeding with PyPI upload..." |
| 80 | +
|
| 81 | + - name: Publish to PyPI |
| 82 | + if: github.event.inputs.publish_to_pypi == 'yes' |
| 83 | + env: |
| 84 | + TWINE_USERNAME: __token__ |
| 85 | + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |
| 86 | + run: | |
| 87 | + if [ -z "$TWINE_PASSWORD" ]; then |
| 88 | + echo "❌ Error: PYPI_TOKEN secret is not configured!" |
| 89 | + echo "Please add your PyPI token to GitHub Secrets" |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | + twine upload dist/* |
| 93 | + echo "✅ Published to PyPI successfully!" |
| 94 | + echo "📦 View at: https://pypi.org/project/qql-cli/" |
| 95 | + echo "📥 Install: pip install qql-cli" |
| 96 | +
|
| 97 | + - name: Skip publish message |
| 98 | + if: github.event.inputs.publish_to_pypi != 'yes' |
| 99 | + run: | |
| 100 | + echo "📦 Package built successfully but NOT published to PyPI" |
| 101 | + echo "ℹ️ Test run complete. To publish, re-run with 'yes' selected." |
0 commit comments