diff --git a/scripts/release/main.ts b/scripts/release/main.ts index bf30ce0..66e0143 100755 --- a/scripts/release/main.ts +++ b/scripts/release/main.ts @@ -13,7 +13,7 @@ import { createGitHubRelease, validateGit, } from "./git"; -import { publishCrates, publishNpmCli, publishNpmSdk } from "./sdk"; +import { publishCrates, publishNpmCli, publishNpmCliShared, publishNpmSdk } from "./sdk"; import { updateVersion } from "./update_version"; import { assert, assertEquals, fetchGitRef, versionOrCommitToRef } from "./utils"; @@ -281,6 +281,7 @@ const STEPS = [ "run-ci-checks", "build-js-artifacts", "publish-crates", + "publish-npm-cli-shared", "publish-npm-sdk", "publish-npm-cli", "tag-docker", @@ -322,6 +323,7 @@ const PHASE_MAP: Record = { "complete-ci": [ "update-version", "publish-crates", + "publish-npm-cli-shared", "publish-npm-sdk", "publish-npm-cli", "tag-docker", @@ -595,6 +597,11 @@ async function main() { await publishCrates(releaseOpts); } + if (shouldRunStep("publish-npm-cli-shared")) { + console.log("==> Publishing NPM CLI Shared"); + await publishNpmCliShared(releaseOpts); + } + if (shouldRunStep("publish-npm-sdk")) { console.log("==> Publishing NPM SDK"); await publishNpmSdk(releaseOpts); diff --git a/scripts/release/sdk.ts b/scripts/release/sdk.ts index f5d489a..603aab7 100644 --- a/scripts/release/sdk.ts +++ b/scripts/release/sdk.ts @@ -133,6 +133,43 @@ export async function publishCrates(opts: ReleaseOpts) { console.log("✅ All crates published"); } +export async function publishNpmCliShared(opts: ReleaseOpts) { + const cliSharedPath = join(opts.root, "sdks/cli-shared"); + const packageJsonPath = join(cliSharedPath, "package.json"); + const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf-8")); + const name = packageJson.name; + + // Check if version already exists + const versionExists = await npmVersionExists(name, opts.version); + if (versionExists) { + console.log( + `Version ${opts.version} of ${name} already exists. Skipping...`, + ); + return; + } + + // Build cli-shared + console.log(`==> Building @sandbox-agent/cli-shared`); + await $({ + stdio: "inherit", + cwd: opts.root, + })`pnpm --filter @sandbox-agent/cli-shared build`; + + // Publish + console.log(`==> Publishing to NPM: ${name}@${opts.version}`); + + // Add --tag flag for release candidates + const isReleaseCandidate = opts.version.includes("-rc."); + const tag = isReleaseCandidate ? "rc" : "latest"; + + await $({ + stdio: "inherit", + cwd: cliSharedPath, + })`pnpm publish --access public --tag ${tag} --no-git-checks`; + + console.log(`✅ Published ${name}@${opts.version}`); +} + export async function publishNpmSdk(opts: ReleaseOpts) { const sdkPath = join(opts.root, "sdks/typescript"); const packageJsonPath = join(sdkPath, "package.json"); @@ -148,7 +185,7 @@ export async function publishNpmSdk(opts: ReleaseOpts) { return; } - // Build the SDK + // Build the SDK (cli-shared should already be built by publishNpmCliShared) console.log(`==> Building TypeScript SDK`); await $({ stdio: "inherit", diff --git a/scripts/release/update_version.ts b/scripts/release/update_version.ts index 90f9427..a1c0d1c 100644 --- a/scripts/release/update_version.ts +++ b/scripts/release/update_version.ts @@ -17,6 +17,11 @@ export async function updateVersion(opts: ReleaseOpts) { find: /\[workspace\.package\]\nversion = ".*"/, replace: `[workspace.package]\nversion = "${opts.version}"`, }, + { + path: "sdks/cli-shared/package.json", + find: /"version": ".*"/, + replace: `"version": "${opts.version}"`, + }, { path: "sdks/typescript/package.json", find: /"version": ".*"/,