Skip to content

Commit 6255e26

Browse files
CTX7-854: Migrate to pnpm monorepo (#1058)
* init sdk and monorepo * init sdk and monorepo * comment cleanup * remove bun.lock * cleanup: remove sdk package and deps * update tsconfigs * chore: add temp changelog * ci: update scripts * ci: update github workflows * fmt: workflows * fix: search libraries response type * ci: update pack-mcpb script * update keywords and author * update eslint config for mcp * include license and readme in build * update release.yaml * add readme symlink * include readme in mcp package * chore: add canary release workflow and update configs * chore: format files * ci: add changeset check workflow * canary release trigger * ci: login to npm before release * bump mcp version on package * remove pr trigger from canary release * ci: remove package input * add mcp lint command * update format scripts
1 parent af0f9ee commit 6255e26

35 files changed

+4440
-649
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "public",
8+
"baseBranch": "master",
9+
"updateInternalDependencies": "patch",
10+
"ignore": [],
11+
"snapshot": {
12+
"useCalculatedVersion": true,
13+
"prereleaseTemplate": "{tag}-{datetime}"
14+
}
15+
}

.changeset/heavy-papers-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@upstash/context7-mcp": patch
3+
---
4+
5+
Migrate to pnpm monorepo structure
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Canary Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: "Branch to release from (defaults to current branch)"
8+
required: false
9+
type: string
10+
11+
jobs:
12+
canary-release:
13+
name: Canary Release
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
steps:
18+
- name: Checkout Repo
19+
uses: actions/checkout@v3
20+
with:
21+
ref: ${{ inputs.branch || github.ref }}
22+
23+
- name: Setup Node
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: "20"
27+
28+
- name: Setup pnpm
29+
uses: pnpm/action-setup@v4
30+
with:
31+
version: 9
32+
33+
- name: Configure npm authentication
34+
run: |
35+
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
36+
37+
- name: Install Dependencies
38+
run: pnpm install --frozen-lockfile
39+
40+
- name: Build all packages
41+
run: pnpm build
42+
43+
- name: Publish Snapshot
44+
run: pnpm release:snapshot
45+
env:
46+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Changeset Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, labeled, unlabeled]
6+
7+
jobs:
8+
check:
9+
name: Check for Changeset
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repo
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Check for changeset
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
const { execSync } = require('child_process');
22+
23+
const labels = context.payload.pull_request.labels.map(l => l.name);
24+
if (labels.includes('skip-changeset')) {
25+
console.log('Skipping changeset check for PR with skip-changeset label');
26+
return;
27+
}
28+
29+
const baseSha = context.payload.pull_request.base.sha;
30+
const headSha = context.payload.pull_request.head.sha;
31+
32+
const diff = execSync(
33+
`git diff --name-only ${baseSha}...${headSha}`,
34+
{ encoding: 'utf-8' }
35+
);
36+
37+
const hasChangeset = diff
38+
.split('\n')
39+
.some(file => file.startsWith('.changeset/') && file.endsWith('.md') && !file.includes('README'));
40+
41+
if (!hasChangeset) {
42+
core.setFailed(
43+
'No changeset found. Please add a changeset using `pnpm changeset` or add the "skip-changeset" label if this PR doesn\'t need one (e.g., docs, CI changes).'
44+
);
45+
} else {
46+
console.log('Changeset found!');
47+
}

.github/workflows/check.yaml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,38 @@ jobs:
1818
- name: Checkout repository
1919
uses: actions/checkout@v4
2020

21-
- name: Setup Bun
22-
uses: oven-sh/setup-bun@v2
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
2323
with:
24-
bun-version: latest
24+
node-version: "20"
2525

26-
- name: Cache dependencies
26+
- name: Setup pnpm
27+
uses: pnpm/action-setup@v4
28+
with:
29+
version: 9
30+
31+
- name: Get pnpm store directory
32+
id: pnpm-cache
33+
shell: bash
34+
run: |
35+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
36+
37+
- name: Cache pnpm dependencies
2738
uses: actions/cache@v4
2839
with:
29-
path: ~/.bun/install/cache
30-
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
40+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
41+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
3142
restore-keys: |
32-
${{ runner.os }}-bun-
43+
${{ runner.os }}-pnpm-store-
3344
3445
- name: Install dependencies
35-
run: bun install --frozen-lockfile
46+
run: pnpm install --frozen-lockfile
3647

3748
- name: Run linter
38-
run: bun run lint:check
49+
run: pnpm run lint:check
3950

4051
- name: Check formatting
41-
run: bun run format --check
52+
run: pnpm run format:check
4253

4354
- name: Build project
44-
run: bun run build
55+
run: pnpm run build

.github/workflows/ecr-deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ jobs:
3434
id: build-push
3535
uses: docker/build-push-action@v5
3636
with:
37-
context: .
37+
context: packages/mcp
38+
file: packages/mcp/Dockerfile
3839
platforms: linux/amd64
3940
push: true
4041
tags: |

.github/workflows/publish-mcp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
# Remove 'v' prefix if it exists
3232
VERSION="${VERSION#v}"
3333
else
34-
VERSION=$(node -p "require('./package.json').version")
34+
VERSION=$(node -p "require('./packages/mcp/package.json').version")
3535
fi
3636
echo "VERSION=$VERSION" >> $GITHUB_ENV
3737
echo "Publishing version: $VERSION"

.github/workflows/release.yml

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,89 @@
11
name: Release
22

33
on:
4-
release:
5-
types:
6-
- published
4+
push:
5+
branches:
6+
- master
7+
8+
concurrency: ${{ github.workflow }}-${{ github.ref }}
79

810
jobs:
911
release:
1012
name: Release
1113
runs-on: ubuntu-latest
1214
permissions:
1315
id-token: write # Required for OIDC authentication with MCP Registry
14-
contents: read
16+
contents: write
17+
pull-requests: write
1518
steps:
1619
- name: Checkout Repo
1720
uses: actions/checkout@v3
1821

19-
- name: Set env
20-
run: |
21-
VERSION="${GITHUB_REF##refs/*/}"
22-
# Remove 'v' prefix if it exists
23-
VERSION="${VERSION#v}"
24-
echo "VERSION=$VERSION" >> $GITHUB_ENV
25-
2622
- name: Setup Node
2723
uses: actions/setup-node@v4
2824
with:
29-
node-version: lts/*
25+
node-version: "20"
3026

31-
- name: Setup Bun
32-
uses: oven-sh/setup-bun@v2
27+
- name: Setup pnpm
28+
uses: pnpm/action-setup@v4
3329
with:
34-
bun-version: latest
30+
version: 9
3531

36-
- name: Set package version
32+
- name: Configure npm authentication
3733
run: |
38-
echo $(jq --arg v "${{ env.VERSION }}" '(.version) = $v' package.json) > package.json
39-
40-
- name: Update version in source file
41-
run: |
42-
sed -i "s/version: \"[0-9]*\.[0-9]*\.[0-9]*\"/version: \"${{ env.VERSION }}\"/" src/index.ts
43-
44-
- name: Update package version in server.json
45-
run: |
46-
echo $(jq --arg v "${{ env.VERSION }}" '.version = $v | .packages[0].version = $v' server.json) > server.json
34+
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
4735
4836
- name: Install Dependencies
49-
run: bun install
50-
51-
- name: Build
52-
run: bun run build
37+
run: pnpm install --frozen-lockfile
5338

54-
- name: Set NPM_TOKEN
55-
run: npm config set //registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}
39+
- name: Build all packages
40+
run: pnpm build
5641

57-
- name: Publish
58-
if: "!github.event.release.prerelease"
42+
- name: Create Release PR or Publish
43+
id: changesets
44+
uses: changesets/action@v1
45+
with:
46+
publish: pnpm release
47+
commit: "chore(release): version packages"
48+
title: "chore(release): version packages"
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
52+
53+
- name: Check if MCP was published
54+
id: check-mcp
55+
if: steps.changesets.outputs.published == 'true'
5956
run: |
60-
npm pkg delete scripts.prepare
61-
npm publish --access public
62-
63-
- name: Publish release candidate
64-
if: "github.event.release.prerelease"
57+
PUBLISHED='${{ steps.changesets.outputs.publishedPackages }}'
58+
if echo "$PUBLISHED" | jq -e '.[] | select(.name == "@upstash/context7-mcp")' > /dev/null; then
59+
VERSION=$(echo "$PUBLISHED" | jq -r '.[] | select(.name == "@upstash/context7-mcp") | .version')
60+
echo "mcp_published=true" >> $GITHUB_OUTPUT
61+
echo "mcp_version=$VERSION" >> $GITHUB_OUTPUT
62+
fi
63+
64+
- name: Update version in MCP source file
65+
if: steps.check-mcp.outputs.mcp_published == 'true'
6566
run: |
66-
npm pkg delete scripts.prepare
67-
npm publish --access public --tag=canary
68-
69-
- name: Validate server.json
70-
if: "!github.event.release.prerelease"
71-
run: npx mcp-registry-validator validate server.json
72-
73-
- name: Install MCP Publisher
74-
if: "!github.event.release.prerelease"
67+
VERSION="${{ steps.check-mcp.outputs.mcp_version }}"
68+
sed -i "s/version: \"[0-9]*\.[0-9]*\.[0-9]*\"/version: \"$VERSION\"/" packages/mcp/src/index.ts
69+
git config user.name "github-actions[bot]"
70+
git config user.email "github-actions[bot]@users.noreply.github.com"
71+
git add packages/mcp/src/index.ts
72+
git commit -m "chore: update MCP version in source to $VERSION" || true
73+
git push || true
74+
75+
- name: Update server.json
76+
if: steps.check-mcp.outputs.mcp_published == 'true'
7577
run: |
76-
curl -L "https://github.com/modelcontextprotocol/registry/releases/download/v1.3.3/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher
77-
78-
- name: Login to MCP Registry
79-
if: "!github.event.release.prerelease"
80-
run: ./mcp-publisher login github-oidc
78+
VERSION="${{ steps.check-mcp.outputs.mcp_version }}"
79+
echo $(jq --arg v "$VERSION" '.version = $v | .packages[0].version = $v' server.json) > server.json
80+
git add server.json
81+
git commit -m "chore: update server.json to v$VERSION" || true
82+
git push || true
8183
8284
- name: Publish to MCP Registry
83-
if: "!github.event.release.prerelease"
84-
run: ./mcp-publisher publish
85+
if: steps.check-mcp.outputs.mcp_published == 'true'
86+
run: |
87+
curl -L "https://github.com/modelcontextprotocol/registry/releases/download/v1.3.3/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher
88+
./mcp-publisher login github-oidc
89+
./mcp-publisher publish

.prettierignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Dependencies
2+
node_modules
3+
4+
# Lock files
5+
pnpm-lock.yaml
6+
package-lock.json
7+
yarn.lock
8+
bun.lockb
9+
10+
# Build outputs
11+
dist
12+
build
13+
.next
14+
out
15+
16+
# Logs
17+
*.log
18+
19+
# Environment files
20+
.env
21+
.env.*
22+
23+
# IDE
24+
.vscode
25+
.idea
26+
27+
# Changesets
28+
.changeset/*.md

0 commit comments

Comments
 (0)