name: Publish to PyPI
on:
push:
tags:
- 'v*' # 当推送以 v 开头的标签时触发
workflow_dispatch: # 允许手动触发
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.10, 3.11, 3.12]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mcp[cli]
pip install -e .
- name: Run tests
run: |
if [ -f "test_db.py" ]; then
python test_db.py
else
echo "No tests found, skipping..."
fi
publish:
needs: test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') # 只有推送标签时才发布
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
python -m build
- name: Check package
run: |
twine check dist/*
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*