Update publish.yml #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release and Publish | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: 'Release type (patch, minor, major)' | |
| required: false | |
| default: 'minor' | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| env: | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org/' | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y jq | |
| pip install build twine | |
| # Determine the release type | |
| - name: Set release type | |
| id: set_release_type | |
| run: | | |
| if [ -z "${{ github.event.inputs.release_type }}" ]; then | |
| echo "release_type=minor" >> $GITHUB_OUTPUT | |
| else | |
| echo "release_type=${{ github.event.inputs.release_type }}" >> $GITHUB_OUTPUT | |
| fi | |
| # ---- Version Bump (TypeScript) ---- | |
| - name: Bump npm version (TypeScript) | |
| id: bump_npm | |
| working-directory: ./typescript | |
| run: | | |
| npm version ${{ steps.set_release_type.outputs.release_type }} --no-git-tag-version | |
| VERSION=$(jq -r .version package.json) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "New version: $VERSION" | |
| # ---- Sync versions across packages ---- | |
| - name: Sync versions across all packages | |
| run: | | |
| VERSION=${{ steps.bump_npm.outputs.version }} | |
| echo "Syncing version $VERSION across packages" | |
| # Update TypeScript package.json (already done, but ensure consistency) | |
| jq ".version = \"$VERSION\"" typescript/package.json > tmp.json && mv tmp.json typescript/package.json | |
| # Update MCP package.json | |
| jq ".version = \"$VERSION\"" modelcontextprotocol/package.json > tmp.json && mv tmp.json modelcontextprotocol/package.json | |
| # Update Python version using direct file manipulation | |
| if [ -f python/pyproject.toml ]; then | |
| # Update version in pyproject.toml | |
| sed -i "s/^version = .*/version = \"$VERSION\"/" python/pyproject.toml | |
| echo "Updated Python version in pyproject.toml" | |
| fi | |
| # Alternative: Update __init__.py if it exists | |
| if [ -f python/src/__init__.py ]; then | |
| sed -i "s/__version__ = .*/__version__ = \"$VERSION\"/" python/src/__init__.py | |
| elif [ -f python/__init__.py ]; then | |
| sed -i "s/__version__ = .*/__version__ = \"$VERSION\"/" python/__init__.py | |
| fi | |
| # Commit, tag, and push | |
| - name: Commit and tag version bump | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add typescript/package.json modelcontextprotocol/package.json python/pyproject.toml | |
| git commit -m "chore: version bump to v${{ steps.bump_npm.outputs.version }} [skip ci]" || echo "No changes to commit" | |
| git tag v${{ steps.bump_npm.outputs.version }} | |
| git push origin main --tags | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # ---- Build & Publish npm (TypeScript) ---- | |
| - name: Build and publish npm (TypeScript) | |
| working-directory: ./typescript | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc | |
| npm install | |
| npm run build | |
| npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| # ---- Build & Publish npm (MCP) ---- | |
| - name: Build and publish npm (MCP) | |
| working-directory: ./modelcontextprotocol | |
| run: | | |
| echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc | |
| npm install | |
| npm run build | |
| npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| # ---- Build & Publish PyPI ---- | |
| - name: Build and publish Python | |
| working-directory: ./python | |
| run: | | |
| python -m build | |
| python -m twine upload dist/* --username __token__ --password $PYPI_TOKEN --non-interactive |