diff --git a/.github/workflows/mcp-release.yml b/.github/workflows/mcp-release.yml index f758a6a0d..e594c53f3 100644 --- a/.github/workflows/mcp-release.yml +++ b/.github/workflows/mcp-release.yml @@ -73,6 +73,7 @@ jobs: const writeJson = (path, data) => fs.writeFileSync(path, `${JSON.stringify(data, null, 2)}\n`); for (const path of [ + "packages/mongo-shell/package.json", "packages/node-core/package.json", "packages/cli/package.json", "packages/mcp-server/package.json", @@ -110,7 +111,7 @@ jobs: - name: Commit package release version run: | VERSION="${{ steps.version.outputs.version }}" - git add packages/node-core/package.json packages/cli/package.json packages/mcp-server/package.json packages/mcp-server/server.json + git add packages/mongo-shell/package.json packages/node-core/package.json packages/cli/package.json packages/mcp-server/package.json packages/mcp-server/server.json if git diff --cached --quiet; then echo "Package versions already committed for ${VERSION}." else @@ -143,10 +144,64 @@ jobs: git push origin "refs/tags/${TAG}:refs/tags/${TAG}" fi + publish-mongo-shell: + name: Publish mongo-shell + runs-on: ubuntu-latest + needs: prepare + + steps: + - uses: actions/checkout@v5 + with: + ref: ${{ needs.prepare.outputs.tag }} + + - name: Setup pnpm + uses: pnpm/action-setup@v6 + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: 22.13.0 + registry-url: https://registry.npmjs.org + cache: pnpm + cache-dependency-path: pnpm-lock.yaml + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Publish Mongo shell parser + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + VERSION: ${{ needs.prepare.outputs.version }} + run: | + PACKAGE_PATH="packages/mongo-shell/package.json" + set_package_version() { + PACKAGE_PATH="${PACKAGE_PATH}" PACKAGE_VERSION="$1" node <<'NODE' + const fs = require("fs"); + const path = process.env.PACKAGE_PATH; + const pkg = JSON.parse(fs.readFileSync(path, "utf8")); + pkg.version = process.env.PACKAGE_VERSION; + fs.writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`); + NODE + } + + # node-core@0.4.31 already references ^0.1.0, so bootstrap that version once to repair existing installs. + if ! npm view "@dbx-app/mongo-shell@0.1.0" version >/dev/null 2>&1; then + set_package_version "0.1.0" + pnpm --filter @dbx-app/mongo-shell publish --access public --provenance --no-git-checks + fi + + set_package_version "${VERSION}" + if npm view "@dbx-app/mongo-shell@${VERSION}" version >/dev/null 2>&1; then + echo "@dbx-app/mongo-shell@${VERSION} already exists on npm; skipping." + exit 0 + fi + pnpm --filter @dbx-app/mongo-shell publish --access public --provenance --no-git-checks + publish-node-core: name: Publish node-core runs-on: ubuntu-latest - needs: prepare + # node-core keeps mongo-shell as a runtime dependency, so npm must receive it first. + needs: [prepare, publish-mongo-shell] outputs: published-or-existing: ${{ steps.publish.outputs.published_or_existing }} diff --git a/package.json b/package.json index b2ab22fac..71259f8d7 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,9 @@ "dev:full:win": ".\\scripts\\dev-full.bat", "build:packages": "pnpm --filter @dbx-app/mongo-shell build && pnpm --filter @dbx-app/node-core build && pnpm --filter @dbx-app/cli build && pnpm --filter @dbx-app/mcp-server build", "test:packages": "pnpm --filter @dbx-app/node-core test && pnpm --filter @dbx-app/cli test && pnpm --filter @dbx-app/mcp-server test", - "pack:packages": "rm -rf /tmp/dbx-pack-check && mkdir -p /tmp/dbx-pack-check && pnpm --filter @dbx-app/node-core pack --pack-destination /tmp/dbx-pack-check && pnpm --filter @dbx-app/cli pack --pack-destination /tmp/dbx-pack-check && pnpm --filter @dbx-app/mcp-server pack --pack-destination /tmp/dbx-pack-check", - "publish:dry-run": "pnpm build:packages && pnpm pack:packages", + "pack:packages": "rm -rf /tmp/dbx-pack-check && mkdir -p /tmp/dbx-pack-check && pnpm --filter @dbx-app/mongo-shell pack --pack-destination /tmp/dbx-pack-check && pnpm --filter @dbx-app/node-core pack --pack-destination /tmp/dbx-pack-check && pnpm --filter @dbx-app/cli pack --pack-destination /tmp/dbx-pack-check && pnpm --filter @dbx-app/mcp-server pack --pack-destination /tmp/dbx-pack-check", + "verify:package-install": "node scripts/verify-package-install.mjs /tmp/dbx-pack-check", + "publish:dry-run": "pnpm build:packages && pnpm pack:packages && pnpm verify:package-install", "release": "node scripts/release.mjs", "release:agents": "node scripts/release.mjs agents", "release:app": "node scripts/release.mjs app", diff --git a/packages/mongo-shell/package.json b/packages/mongo-shell/package.json index d718688a8..c211cc957 100644 --- a/packages/mongo-shell/package.json +++ b/packages/mongo-shell/package.json @@ -1,7 +1,6 @@ { "name": "@dbx-app/mongo-shell", "version": "0.1.0", - "private": true, "description": "Pure MongoDB shell JSON/argument parsing shared by desktop and node-core", "license": "Apache-2.0", "type": "module", diff --git a/scripts/release.mjs b/scripts/release.mjs index b2712cb65..e39fa00ba 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -10,6 +10,9 @@ const PACKAGE_TAG_PREFIX = "packages-v"; const AGENT_TAG_PREFIX = "agents-v"; const APP_TAG_PREFIX = "v"; const PACKAGE_RELEASE_PATHS = [ + "packages/mongo-shell/src/", + "packages/mongo-shell/package.json", + "packages/mongo-shell/tsconfig.json", "packages/node-core/src/", "packages/node-core/README.md", "packages/node-core/package.json", @@ -255,6 +258,7 @@ function getLatestPackageVersion() { if (tag) return tag.versionText; const packageVersions = [ + "packages/mongo-shell/package.json", "packages/node-core/package.json", "packages/cli/package.json", "packages/mcp-server/package.json", diff --git a/scripts/verify-package-install.mjs b/scripts/verify-package-install.mjs new file mode 100644 index 000000000..36eee4d60 --- /dev/null +++ b/scripts/verify-package-install.mjs @@ -0,0 +1,48 @@ +import { mkdtempSync, readFileSync, readdirSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { basename, join, resolve } from "node:path"; +import { spawnSync } from "node:child_process"; + +const packageDirectory = resolve(process.argv[2] ?? "/tmp/dbx-pack-check"); +const expectedPackages = [ + "@dbx-app/mongo-shell", + "@dbx-app/node-core", + "@dbx-app/cli", + "@dbx-app/mcp-server", +]; +const tarballs = readdirSync(packageDirectory) + .filter((file) => file.endsWith(".tgz")) + .map((file) => join(packageDirectory, file)) + .sort(); + +if (tarballs.length !== expectedPackages.length) { + throw new Error( + `Expected ${expectedPackages.length} package tarballs, found ${tarballs.length}: ${tarballs.map(basename).join(", ")}`, + ); +} + +const installDirectory = mkdtempSync(join(tmpdir(), "dbx-package-install-")); +writeFileSync( + join(installDirectory, "package.json"), + `${JSON.stringify({ name: "dbx-package-install-check", private: true }, null, 2)}\n`, +); + +// Installing every release tarball together verifies workspace dependencies are publishable and semver-compatible. +const install = spawnSync( + "npm", + ["install", "--ignore-scripts", "--no-audit", "--no-fund", ...tarballs], + { cwd: installDirectory, stdio: "inherit" }, +); +if (install.status !== 0) { + process.exit(install.status ?? 1); +} + +for (const packageName of expectedPackages) { + const manifestPath = join(installDirectory, "node_modules", packageName, "package.json"); + const manifest = JSON.parse(readFileSync(manifestPath, "utf8")); + if (manifest.name !== packageName) { + throw new Error(`Installed package mismatch at ${manifestPath}: ${manifest.name}`); + } +} + +console.log(`Verified clean installation of ${expectedPackages.join(", ")}.`);