mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-16 17:01:06 +00:00
fix: dynamically discover packages in release script instead of hardcoding
- sdk.ts: discoverNpmPackages() + topoSort() for library packages - sdk.ts: discoverCrates() via cargo metadata for workspace crates - sdk.ts: publishNpmLibraries replaces publishNpmCliShared + publishNpmSdk - sdk.ts: publishNpmCli now discovers CLI packages from filesystem - update_version.ts: discovers SDK package.json files via glob - update_version.ts: discovers internal crates from Cargo.toml path deps This prevents packages like persist-*, acp-http-client from being silently skipped during releases.
This commit is contained in:
parent
cdbe920070
commit
46193747e6
3 changed files with 240 additions and 268 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import * as fs from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { $ } from "execa";
|
||||
import { glob } from "glob";
|
||||
import type { ReleaseOpts } from "./main";
|
||||
|
|
@ -10,70 +11,36 @@ function assert(condition: any, message?: string): asserts condition {
|
|||
}
|
||||
|
||||
export async function updateVersion(opts: ReleaseOpts) {
|
||||
// Define substitutions
|
||||
const findReplace = [
|
||||
{
|
||||
path: "Cargo.toml",
|
||||
find: /\[workspace\.package\]\nversion = ".*"/,
|
||||
replace: `[workspace.package]\nversion = "${opts.version}"`,
|
||||
},
|
||||
{
|
||||
path: "sdks/cli-shared/package.json",
|
||||
find: /"version": ".*"/,
|
||||
replace: `"version": "${opts.version}"`,
|
||||
},
|
||||
{
|
||||
path: "sdks/acp-http-client/package.json",
|
||||
find: /"version": ".*"/,
|
||||
replace: `"version": "${opts.version}"`,
|
||||
},
|
||||
{
|
||||
path: "sdks/typescript/package.json",
|
||||
find: /"version": ".*"/,
|
||||
replace: `"version": "${opts.version}"`,
|
||||
},
|
||||
{
|
||||
path: "sdks/cli/package.json",
|
||||
find: /"version": ".*"/,
|
||||
replace: `"version": "${opts.version}"`,
|
||||
},
|
||||
{
|
||||
path: "sdks/gigacode/package.json",
|
||||
find: /"version": ".*"/,
|
||||
replace: `"version": "${opts.version}"`,
|
||||
},
|
||||
{
|
||||
path: "sdks/cli/platforms/*/package.json",
|
||||
find: /"version": ".*"/,
|
||||
replace: `"version": "${opts.version}"`,
|
||||
},
|
||||
{
|
||||
path: "sdks/gigacode/platforms/*/package.json",
|
||||
find: /"version": ".*"/,
|
||||
replace: `"version": "${opts.version}"`,
|
||||
},
|
||||
];
|
||||
|
||||
// Update internal crate versions in workspace dependencies
|
||||
// These need to match the new version so cargo publish can resolve them correctly
|
||||
const internalCrates = [
|
||||
"sandbox-agent",
|
||||
"sandbox-agent-error",
|
||||
"sandbox-agent-agent-management",
|
||||
"sandbox-agent-agent-credentials",
|
||||
"sandbox-agent-opencode-adapter",
|
||||
"sandbox-agent-opencode-server-manager",
|
||||
"acp-http-adapter",
|
||||
];
|
||||
|
||||
const cargoTomlPath = `${opts.root}/Cargo.toml`;
|
||||
// 1. Update workspace version and internal crate versions in root Cargo.toml
|
||||
const cargoTomlPath = join(opts.root, "Cargo.toml");
|
||||
let cargoContent = await fs.readFile(cargoTomlPath, "utf-8");
|
||||
|
||||
// Update [workspace.package] version
|
||||
assert(
|
||||
/\[workspace\.package\]\nversion = ".*"/.test(cargoContent),
|
||||
"Could not find workspace.package version in Cargo.toml",
|
||||
);
|
||||
cargoContent = cargoContent.replace(
|
||||
/\[workspace\.package\]\nversion = ".*"/,
|
||||
`[workspace.package]\nversion = "${opts.version}"`,
|
||||
);
|
||||
|
||||
// Discover internal crates from [workspace.dependencies] by matching
|
||||
// lines with both `version = "..."` and `path = "..."` (internal path deps)
|
||||
const internalCratePattern = /^(\S+)\s*=\s*\{[^}]*version\s*=\s*"[^"]+"\s*,[^}]*path\s*=/gm;
|
||||
let match;
|
||||
const internalCrates: string[] = [];
|
||||
while ((match = internalCratePattern.exec(cargoContent)) !== null) {
|
||||
internalCrates.push(match[1]);
|
||||
}
|
||||
|
||||
console.log(`Discovered ${internalCrates.length} internal crates to version-bump:`);
|
||||
for (const crate of internalCrates) console.log(` - ${crate}`);
|
||||
|
||||
for (const crate of internalCrates) {
|
||||
// Match: crate-name = { version = "x.y.z", path = "..." }
|
||||
const pattern = new RegExp(
|
||||
`(${crate.replace(/-/g, "-")} = \\{ version = ")[^"]+(",)`,
|
||||
"g"
|
||||
"g",
|
||||
);
|
||||
cargoContent = cargoContent.replace(pattern, `$1${opts.version}$2`);
|
||||
}
|
||||
|
|
@ -81,18 +48,34 @@ export async function updateVersion(opts: ReleaseOpts) {
|
|||
await fs.writeFile(cargoTomlPath, cargoContent);
|
||||
await $({ cwd: opts.root })`git add Cargo.toml`;
|
||||
|
||||
// Substitute all files
|
||||
for (const { path: globPath, find, replace } of findReplace) {
|
||||
const paths = await glob(globPath, { cwd: opts.root });
|
||||
assert(paths.length > 0, `no paths matched: ${globPath}`);
|
||||
for (const path of paths) {
|
||||
const fullPath = `${opts.root}/${path}`;
|
||||
const file = await fs.readFile(fullPath, "utf-8");
|
||||
assert(find.test(file), `file does not match ${find}: ${fullPath}`);
|
||||
const newFile = file.replace(find, replace);
|
||||
await fs.writeFile(fullPath, newFile);
|
||||
// 2. Discover and update all non-private SDK package.json versions
|
||||
const packageJsonPaths = await glob("sdks/**/package.json", {
|
||||
cwd: opts.root,
|
||||
ignore: ["**/node_modules/**"],
|
||||
});
|
||||
|
||||
await $({ cwd: opts.root })`git add ${path}`;
|
||||
}
|
||||
// Filter to non-private packages only
|
||||
const toUpdate: string[] = [];
|
||||
for (const relPath of packageJsonPaths) {
|
||||
const fullPath = join(opts.root, relPath);
|
||||
const content = await fs.readFile(fullPath, "utf-8");
|
||||
const pkg = JSON.parse(content);
|
||||
if (pkg.private) continue;
|
||||
toUpdate.push(relPath);
|
||||
}
|
||||
|
||||
console.log(`Discovered ${toUpdate.length} SDK package.json files to version-bump:`);
|
||||
for (const relPath of toUpdate) console.log(` - ${relPath}`);
|
||||
|
||||
for (const relPath of toUpdate) {
|
||||
const fullPath = join(opts.root, relPath);
|
||||
const content = await fs.readFile(fullPath, "utf-8");
|
||||
|
||||
const versionPattern = /"version": ".*"/;
|
||||
assert(versionPattern.test(content), `No version field in ${relPath}`);
|
||||
|
||||
const updated = content.replace(versionPattern, `"version": "${opts.version}"`);
|
||||
await fs.writeFile(fullPath, updated);
|
||||
await $({ cwd: opts.root })`git add ${relPath}`;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue