mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 13:34:17 +02:00
151 lines
4.9 KiB
YAML
151 lines
4.9 KiB
YAML
name: Publish fastmcp to PyPI
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ["Publish fastmcp-slim to PyPI"]
|
|
types: [completed]
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
id-token: write
|
|
|
|
jobs:
|
|
pypi-publish:
|
|
name: Upload fastmcp to PyPI
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'release')
|
|
outputs:
|
|
is_prerelease: ${{ steps.package_version.outputs.is_prerelease }}
|
|
version: ${{ steps.package_version.outputs.version }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v7
|
|
with:
|
|
fetch-depth: 0
|
|
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
|
|
|
|
- name: Install uv
|
|
uses: astral-sh/setup-uv@v7
|
|
|
|
- name: Build fastmcp
|
|
run: uv build --package fastmcp
|
|
|
|
- name: Read built package version
|
|
id: package_version
|
|
run: |
|
|
python - <<'PY' >> "$GITHUB_OUTPUT"
|
|
import email.parser
|
|
import re
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
wheel = next(Path("dist").glob("fastmcp-*.whl"))
|
|
metadata_name = next(
|
|
name for name in zipfile.ZipFile(wheel).namelist()
|
|
if name.endswith(".dist-info/METADATA")
|
|
)
|
|
metadata = email.parser.Parser().parsestr(
|
|
zipfile.ZipFile(wheel).read(metadata_name).decode()
|
|
)
|
|
version = metadata["Version"]
|
|
public_version = version.partition("+")[0]
|
|
is_prerelease = bool(
|
|
re.search(
|
|
r"(?i)(?:^|[0-9.])(?:a|b|c|rc|alpha|beta|pre|preview|dev)[0-9]*",
|
|
public_version,
|
|
)
|
|
)
|
|
print(f"version={version}")
|
|
print(f"is_prerelease={str(is_prerelease).lower()}")
|
|
PY
|
|
|
|
- name: Verify matching fastmcp-slim is published
|
|
run: |
|
|
SLIM_VERSION=$(python - <<'PY'
|
|
import email.parser
|
|
import re
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
wheel = next(Path("dist").glob("fastmcp-*.whl"))
|
|
metadata_name = next(
|
|
name for name in zipfile.ZipFile(wheel).namelist()
|
|
if name.endswith(".dist-info/METADATA")
|
|
)
|
|
metadata = email.parser.Parser().parsestr(
|
|
zipfile.ZipFile(wheel).read(metadata_name).decode()
|
|
)
|
|
for value in metadata.get_all("Requires-Dist", []):
|
|
requirement, _, marker = value.partition(";")
|
|
if marker.strip():
|
|
continue
|
|
match = re.fullmatch(
|
|
r"fastmcp-slim(?:\[[^\]]+\])?==([^;\s]+)",
|
|
requirement.strip(),
|
|
)
|
|
if match:
|
|
print(match.group(1))
|
|
break
|
|
else:
|
|
raise RuntimeError("Could not find the base fastmcp-slim dependency")
|
|
PY
|
|
)
|
|
|
|
for attempt in {1..12}; do
|
|
if python - "$SLIM_VERSION" <<'PY'
|
|
import json
|
|
import sys
|
|
import urllib.request
|
|
|
|
version = sys.argv[1]
|
|
url = f"https://pypi.org/pypi/fastmcp-slim/{version}/json"
|
|
with urllib.request.urlopen(url, timeout=30) as response:
|
|
json.load(response)
|
|
PY
|
|
then
|
|
exit 0
|
|
fi
|
|
|
|
echo "fastmcp-slim ${SLIM_VERSION} is not available on PyPI yet; retrying (${attempt}/12)."
|
|
sleep 10
|
|
done
|
|
|
|
echo "fastmcp-slim ${SLIM_VERSION} is not available on PyPI; refusing to publish fastmcp." >&2
|
|
exit 1
|
|
|
|
- name: Publish fastmcp to PyPI
|
|
run: uv publish -v dist/fastmcp-*.tar.gz dist/fastmcp-*.whl
|
|
|
|
update-published-docs:
|
|
name: Update published-docs branch
|
|
runs-on: ubuntu-latest
|
|
needs: pypi-publish
|
|
if: github.event_name == 'workflow_run' && github.event.workflow_run.event == 'release' && needs['pypi-publish'].outputs.is_prerelease != 'true'
|
|
timeout-minutes: 2
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
with:
|
|
fetch-depth: 0
|
|
ref: ${{ github.event.workflow_run.head_sha }}
|
|
|
|
- name: Check release line
|
|
id: release_line
|
|
env:
|
|
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
|
|
run: |
|
|
git fetch origin "${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}"
|
|
if git merge-base --is-ancestor HEAD "refs/remotes/origin/${DEFAULT_BRANCH}"; then
|
|
echo "update_published_docs=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "update_published_docs=false" >> "$GITHUB_OUTPUT"
|
|
echo "Release commit is not on ${DEFAULT_BRANCH}; skipping published-docs update."
|
|
fi
|
|
|
|
- name: Point published-docs at published release
|
|
if: steps.release_line.outputs.update_published_docs == 'true'
|
|
run: git push --force origin "HEAD:published-docs"
|