fix: sync Cargo.lock when version changes (#302)
Update sync-version.js to also run `cargo update -p agent-browser` after updating Cargo.toml, keeping Cargo.lock in sync. Also update pre-commit hook to stage Cargo.lock along with Cargo.toml. This commit also brings Cargo.lock up to date (was stuck at 0.7.6).
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
pnpm lint-staged
|
pnpm lint-staged
|
||||||
node scripts/sync-version.js
|
node scripts/sync-version.js
|
||||||
git add cli/Cargo.toml
|
git add cli/Cargo.toml cli/Cargo.lock
|
||||||
|
|||||||
Generated
+1
-1
@@ -4,7 +4,7 @@ version = 4
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "agent-browser"
|
name = "agent-browser"
|
||||||
version = "0.7.6"
|
version = "0.8.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dirs",
|
"dirs",
|
||||||
"libc",
|
"libc",
|
||||||
|
|||||||
+27
-1
@@ -5,12 +5,14 @@
|
|||||||
* Run this script before building or releasing.
|
* Run this script before building or releasing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { execSync } from "child_process";
|
||||||
import { readFileSync, writeFileSync } from "fs";
|
import { readFileSync, writeFileSync } from "fs";
|
||||||
import { dirname, join } from "path";
|
import { dirname, join } from "path";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const rootDir = join(__dirname, "..");
|
const rootDir = join(__dirname, "..");
|
||||||
|
const cliDir = join(rootDir, "cli");
|
||||||
|
|
||||||
// Read version from package.json (single source of truth)
|
// Read version from package.json (single source of truth)
|
||||||
const packageJson = JSON.parse(
|
const packageJson = JSON.parse(
|
||||||
@@ -21,17 +23,19 @@ const version = packageJson.version;
|
|||||||
console.log(`Syncing version ${version} to all config files...`);
|
console.log(`Syncing version ${version} to all config files...`);
|
||||||
|
|
||||||
// Update Cargo.toml
|
// Update Cargo.toml
|
||||||
const cargoTomlPath = join(rootDir, "cli/Cargo.toml");
|
const cargoTomlPath = join(cliDir, "Cargo.toml");
|
||||||
let cargoToml = readFileSync(cargoTomlPath, "utf-8");
|
let cargoToml = readFileSync(cargoTomlPath, "utf-8");
|
||||||
const cargoVersionRegex = /^version\s*=\s*"[^"]*"/m;
|
const cargoVersionRegex = /^version\s*=\s*"[^"]*"/m;
|
||||||
const newCargoVersion = `version = "${version}"`;
|
const newCargoVersion = `version = "${version}"`;
|
||||||
|
|
||||||
|
let cargoTomlUpdated = false;
|
||||||
if (cargoVersionRegex.test(cargoToml)) {
|
if (cargoVersionRegex.test(cargoToml)) {
|
||||||
const oldMatch = cargoToml.match(cargoVersionRegex)?.[0];
|
const oldMatch = cargoToml.match(cargoVersionRegex)?.[0];
|
||||||
if (oldMatch !== newCargoVersion) {
|
if (oldMatch !== newCargoVersion) {
|
||||||
cargoToml = cargoToml.replace(cargoVersionRegex, newCargoVersion);
|
cargoToml = cargoToml.replace(cargoVersionRegex, newCargoVersion);
|
||||||
writeFileSync(cargoTomlPath, cargoToml);
|
writeFileSync(cargoTomlPath, cargoToml);
|
||||||
console.log(` Updated cli/Cargo.toml: ${oldMatch} -> ${newCargoVersion}`);
|
console.log(` Updated cli/Cargo.toml: ${oldMatch} -> ${newCargoVersion}`);
|
||||||
|
cargoTomlUpdated = true;
|
||||||
} else {
|
} else {
|
||||||
console.log(` cli/Cargo.toml already up to date`);
|
console.log(` cli/Cargo.toml already up to date`);
|
||||||
}
|
}
|
||||||
@@ -40,4 +44,26 @@ if (cargoVersionRegex.test(cargoToml)) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update Cargo.lock to match Cargo.toml
|
||||||
|
if (cargoTomlUpdated) {
|
||||||
|
try {
|
||||||
|
execSync("cargo update -p agent-browser --offline", {
|
||||||
|
cwd: cliDir,
|
||||||
|
stdio: "pipe",
|
||||||
|
});
|
||||||
|
console.log(` Updated cli/Cargo.lock`);
|
||||||
|
} catch {
|
||||||
|
// --offline may fail if package not in cache, try without it
|
||||||
|
try {
|
||||||
|
execSync("cargo update -p agent-browser", {
|
||||||
|
cwd: cliDir,
|
||||||
|
stdio: "pipe",
|
||||||
|
});
|
||||||
|
console.log(` Updated cli/Cargo.lock`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(` Warning: Could not update Cargo.lock: ${e.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log("Version sync complete.");
|
console.log("Version sync complete.");
|
||||||
|
|||||||
Reference in New Issue
Block a user