name: Build & Publish (mcp-server) # Build, test, and publish the Python MCP server (mcp-server/) to PyPI. # Publishing uses PyPI Trusted Publishing (OIDC) — no API token required, # only the GitHub→PyPI OIDC trust configured on the repo. # # Release tags: mcp-server-v* (e.g. mcp-server-v1.0.1) on: push: branches: [main] tags: - "mcp-server-v*" paths: - "mcp-server/**" - ".github/workflows/mcp-server.yml" pull_request: paths: - "mcp-server/**" - ".github/workflows/mcp-server.yml" workflow_dispatch: permissions: contents: read jobs: test: name: Test (Python ${{ matrix.python-version }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: python-version: ["3.10", "3.11", "3.12", "3.13"] defaults: run: working-directory: mcp-server steps: - 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 (test extras) run: uv sync --python ${{ matrix.python-version }} --extra test - name: Run tests # unittest avoids pytest importing __init__.py as a broken package root. # Manual diagnostics live in check_imports.py (not matched by test_*.py). run: uv run --python ${{ matrix.python-version }} python -m unittest discover -s . -p "test_*.py" -v build: name: Build sdist + wheel needs: test runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/mcp-server-v') defaults: run: working-directory: mcp-server steps: - uses: actions/checkout@v4 - name: Install uv uses: astral-sh/setup-uv@v4 - name: Set up Python run: uv python install 3.12 - name: Build package run: uv build - name: Verify wheel contains upload_paths.py (regression guard) run: | set -e if ! python3 -c "import glob, zipfile, sys; whl=glob.glob('dist/*.whl')[0]; z=zipfile.ZipFile(whl); sys.exit(0 if 'upload_paths.py' in z.namelist() else 1)"; then echo "::error::upload_paths.py is missing from the wheel — check py-modules in pyproject.toml/setup.py" exit 1 fi echo "upload_paths.py present in wheel ✓" - name: Upload artifacts uses: actions/upload-artifact@v4 with: name: dist path: mcp-server/dist/ publish: name: Publish to PyPI needs: build runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/mcp-server-v') permissions: id-token: write environment: name: pypi url: https://pypi.org/project/weknora-mcp/ steps: - name: Download artifacts uses: actions/download-artifact@v4 with: name: dist path: dist/ - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1