publish-to-pypi.yml•2.02 kB
name: Test and Publish to PyPI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13' , '3.14']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies
run: |
uv venv --python ${{ matrix.python-version }}
uv pip install build
uv pip install -e ".[dev]"
- name: Run tests
run: uv run pytest tests/ -v --tb=short
build-and-publish:
needs: build-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: |
uv venv --python 3.12
uv pip install build
- name: Build package
run: uv run python -m build
- name: Extract version from pyproject.toml
run: |
VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml | head -1)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Check if version exists on PyPI
id: check_version
run: |
PACKAGE_NAME="mysqltuner_mcp"
if curl -sSf "https://pypi.org/pypi/${PACKAGE_NAME}/${VERSION}/json" > /dev/null; then
echo "Version ${VERSION} already exists on PyPI. Skipping publish."
echo "skip_publish=true" >> $GITHUB_ENV
else
echo "skip_publish=false" >> $GITHUB_ENV
fi
- name: Publish to PyPI
if: env.skip_publish != 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}