chore: copy and adapt rivet release scripts for sandbox-agent

This commit is contained in:
Nathan Flurry 2026-01-27 15:43:19 -08:00
parent 29b159ca20
commit 2a922ef562
14 changed files with 1284 additions and 1263 deletions

View file

@ -1,15 +1,21 @@
import * as fs from "node:fs/promises";
import { glob } from "glob";
import { $ } from "execa";
import type { ReleaseOpts } from "./main.js";
import { assert } from "./utils.js";
import { glob } from "glob";
import type { ReleaseOpts } from "./main";
function assert(condition: any, message?: string): asserts condition {
if (!condition) {
throw new Error(message || "Assertion failed");
}
}
export async function updateVersion(opts: ReleaseOpts) {
// Define substitutions
const findReplace = [
{
path: "Cargo.toml",
find: /^version = ".*"/m,
replace: `version = "${opts.version}"`,
find: /\[workspace\.package\]\nversion = ".*"/,
replace: `[workspace.package]\nversion = "${opts.version}"`,
},
{
path: "sdks/typescript/package.json",
@ -28,41 +34,17 @@ export async function updateVersion(opts: ReleaseOpts) {
},
];
// 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 filePath of paths) {
const fullPath = `${opts.root}/${filePath}`;
const file = await fs.readFile(fullPath, "utf-8");
assert(find.test(file), `file does not match ${find}: ${filePath}`);
for (const path of paths) {
const file = await fs.readFile(path, "utf-8");
assert(find.test(file), `file does not match ${find}: ${path}`);
const newFile = file.replace(find, replace);
await fs.writeFile(fullPath, newFile);
await fs.writeFile(path, newFile);
await $({ cwd: opts.root })`git add ${filePath}`;
await $({ cwd: opts.root })`git add ${path}`;
}
}
// Update optionalDependencies in CLI package.json
const cliPkgPath = `${opts.root}/sdks/cli/package.json`;
const cliPkg = JSON.parse(await fs.readFile(cliPkgPath, "utf-8"));
if (cliPkg.optionalDependencies) {
for (const dep of Object.keys(cliPkg.optionalDependencies)) {
cliPkg.optionalDependencies[dep] = opts.version;
}
await fs.writeFile(cliPkgPath, JSON.stringify(cliPkg, null, 2) + "\n");
await $({ cwd: opts.root })`git add sdks/cli/package.json`;
}
// Update optionalDependencies in TypeScript SDK package.json
const sdkPkgPath = `${opts.root}/sdks/typescript/package.json`;
const sdkPkg = JSON.parse(await fs.readFile(sdkPkgPath, "utf-8"));
if (sdkPkg.optionalDependencies) {
for (const dep of Object.keys(sdkPkg.optionalDependencies)) {
sdkPkg.optionalDependencies[dep] = opts.version;
}
await fs.writeFile(sdkPkgPath, JSON.stringify(sdkPkg, null, 2) + "\n");
await $({ cwd: opts.root })`git add sdks/typescript/package.json`;
}
}