|
| 1 | +--- |
| 2 | +name: Publish to PyPI |
| 3 | + |
| 4 | +on: |
| 5 | + release: |
| 6 | + types: [published] |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: "Version to publish (must match pyproject.toml)" |
| 11 | + required: true |
| 12 | + default: "" |
| 13 | + |
| 14 | +# Security: Explicit permissions following principle of least privilege |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + build-and-publish: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + environment: |
| 22 | + name: pypi |
| 23 | + url: https://pypi.org/project/sqlite-mcp-server-enhanced/ |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout code |
| 27 | + uses: actions/checkout@v5 |
| 28 | + |
| 29 | + - name: Set up Python |
| 30 | + uses: actions/setup-python@v6 |
| 31 | + with: |
| 32 | + python-version: "3.12" |
| 33 | + |
| 34 | + - name: Install build dependencies |
| 35 | + run: | |
| 36 | + python -m pip install --upgrade pip |
| 37 | + pip install build twine hatchling |
| 38 | +
|
| 39 | + - name: Verify version matches |
| 40 | + if: github.event_name == 'release' |
| 41 | + run: | |
| 42 | + PYPROJECT_VERSION=$(grep -Po '(?<=^version = ")[^"]*' pyproject.toml) |
| 43 | + RELEASE_VERSION="${GITHUB_REF#refs/tags/v}" |
| 44 | + echo "PyProject version: $PYPROJECT_VERSION" |
| 45 | + echo "Release version: $RELEASE_VERSION" |
| 46 | + if [ "$PYPROJECT_VERSION" != "$RELEASE_VERSION" ]; then |
| 47 | + echo "Error: Version mismatch!" |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Build package |
| 52 | + run: python -m build |
| 53 | + |
| 54 | + - name: Check distribution |
| 55 | + run: twine check dist/* |
| 56 | + |
| 57 | + - name: List built artifacts |
| 58 | + run: ls -lh dist/ |
| 59 | + |
| 60 | + - name: Publish to PyPI |
| 61 | + env: |
| 62 | + TWINE_USERNAME: __token__ |
| 63 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 64 | + run: twine upload dist/* |
| 65 | + |
| 66 | + - name: Verify publication |
| 67 | + run: | |
| 68 | + sleep 10 # Wait for PyPI to update |
| 69 | + pip index versions sqlite-mcp-server-enhanced |
| 70 | +
|
| 71 | +
|
0 commit comments