116 lines
3.5 KiB
YAML
116 lines
3.5 KiB
YAML
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.
|
|
#
|
|
# Adapted from annopick/tuomin .github/workflows/ci.yml, adjusted for the
|
|
# mcp-server/ subdirectory layout and its flat test_*.py test files.
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags:
|
|
- "mcp-server-v*"
|
|
paths:
|
|
- "mcp-server/**"
|
|
- ".github/workflows/workflow.yml"
|
|
pull_request:
|
|
paths:
|
|
- "mcp-server/**"
|
|
- ".github/workflows/workflow.yml"
|
|
workflow_dispatch:
|
|
|
|
# Default: read-only. The publish job overrides with id-token: write.
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
test:
|
|
name: Test (Python ${{ matrix.python-version }})
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
# requires-python = ">=3.10" in mcp-server/pyproject.toml
|
|
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
|
|
# mcp-server has no tests/ dir; tests are flat test_*.py files.
|
|
# Point pytest at them explicitly (pyproject testpaths points at a
|
|
# nonexistent tests/ dir, so --override-ini keeps it working).
|
|
run: uv run --python ${{ matrix.python-version }} pytest test_*.py -v --override-ini "testpaths=."
|
|
|
|
build:
|
|
name: Build sdist + wheel
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
# Only build release artifacts on tagged releases; PR/push-to-main just test.
|
|
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)
|
|
# Guards against the 1.0.0 bug where upload_paths.py was dropped
|
|
# from the wheel because it was missing from py-modules.
|
|
run: |
|
|
set -e
|
|
if ! python -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')
|
|
# Required for PyPI Trusted Publishing (OIDC).
|
|
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
|