Skip to content

publish workflow uploads to PyPI only if bundle builds correctly. #13

publish workflow uploads to PyPI only if bundle builds correctly.

publish workflow uploads to PyPI only if bundle builds correctly. #13

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
jobs:
test:
uses: ./.github/workflows/test.yml
build_package:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.14'
- name: Install uv
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
- name: Check tag matches version files
run: |
TAG_VERSION="${GITHUB_REF##*/}"
TAG_VERSION_NO_PREFIX="${TAG_VERSION#v}"
echo "Tag version: $TAG_VERSION (stripped: $TAG_VERSION_NO_PREFIX)"
PYPROJECT_VERSION=$(grep '^version =' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "pyproject.toml version: $PYPROJECT_VERSION"
INIT_VERSION=$(grep '^__version__ =' src/pythonanywhere_mcp_server/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
echo "__init__.py version: $INIT_VERSION"
if [ "$TAG_VERSION_NO_PREFIX" != "$PYPROJECT_VERSION" ]; then
echo "Tag version ($TAG_VERSION_NO_PREFIX) does not match pyproject.toml version ($PYPROJECT_VERSION)" >&2
exit 1
fi
if [ "$TAG_VERSION_NO_PREFIX" != "$INIT_VERSION" ]; then
echo "Tag version ($TAG_VERSION_NO_PREFIX) does not match __init__.py version ($INIT_VERSION)" >&2
exit 1
fi
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
echo "pyproject.toml version ($PYPROJECT_VERSION) does not match __init__.py version ($INIT_VERSION)" >&2
exit 1
fi
shell: bash
- name: Build package
run: uv build
- name: Upload Python artifacts
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: python-dist
path: dist/
build_bundle:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: '24'
- name: Check tag matches manifest.json version
run: |
TAG_VERSION="${GITHUB_REF##*/}"
TAG_VERSION_NO_PREFIX="${TAG_VERSION#v}"
echo "Tag version: $TAG_VERSION (stripped: $TAG_VERSION_NO_PREFIX)"
MANIFEST_VERSION=$(jq -r .version manifest.json)
echo "manifest.json version: $MANIFEST_VERSION"
if [ "$TAG_VERSION_NO_PREFIX" != "$MANIFEST_VERSION" ]; then
echo "Tag version ($TAG_VERSION_NO_PREFIX) does not match manifest.json version ($MANIFEST_VERSION)" >&2
exit 1
fi
shell: bash
- name: Install MCPB toolchain
run: npm install -g @anthropic-ai/mcpb
- name: Pack extension
run: mcpb pack
- name: Upload MCPB artifacts
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: mcpb-dist
path: '*.mcpb'
publish_pypi:
runs-on: ubuntu-latest
needs: [build_package, build_bundle]
steps:
- name: Download Python artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: python-dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
create_release:
runs-on: ubuntu-latest
needs: publish_pypi
steps:
- name: Download Python artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: python-dist
path: dist/
- name: Download MCPB artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: mcpb-dist
path: ./
- name: Create Release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
with:
files: |
*.mcpb
dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}