Files
regorus/xtask/src/tasks/update_deps.rs
Anand Krishnamoorthi 6dc505c88b build: Add xtask automation for binding version management (#491)
* build: Add xtask automation for binding version management

Introduces a dedicated xtask crate that keeps language binding versions
in sync with the core regorus crate, following the workflow pattern used
by rust-analyzer, gitoxide, and ripgrep.

Key features:
- Git-based change detection: compares binding source files against a
  base ref (merge-base with origin/main by default) plus unstaged/
  untracked files to identify which bindings have been modified
- SemVer-aware bumping: binding edits trigger a minor version increment
  (e.g. 0.5.1 → 0.6.0) under pre-1.0 semantics, signaling potential
  breaking changes; clean bindings simply align to the root version
- Multi-language support: updates Cargo manifests (Rust FFI, Java,
  Python, WASM, Ruby), Maven pom.xml (Java), Ruby version constants,
  and C# project files in a single pass
- CI integration: --check mode fails fast when manifests are out of
  sync, ensuring pre-commit and release-plz workflows catch stale
  versions before merge

Integration points:
- release-plz.toml: runs cargo xtask bindings --base-ref origin/main
  after bumping the root crate, so binding versions are updated
  atomically during the release process
- scripts/pre-commit: invokes cargo xtask bindings --check to block
  commits that would leave bindings out of sync
- .cargo/config.toml: defines cargo xtask alias for convenience

Documentation includes inline examples showing how version bumps behave
when bindings are ahead/behind the root, and notes that the minor
field acts as the major version under SemVer 0.y.z initial development
phase.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>

* build: refresh xtask tooling, workflows, and locks

- cargo xtask bindings: keep the binding version-sync pipeline intact
- cargo xtask update-deps: new helper to regenerate workspace/binding Cargo.lock files
- workflows: auto-detect the Java jar version in CI and temporarily disable the Ruby workflow
- lock files: refresh root + binding snapshots after the dependency sweep

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>

---------

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2025-10-28 16:10:54 -05:00

102 lines
3.1 KiB
Rust

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//! Updates dependencies across all Cargo manifests in the workspace.
//!
//! This task runs `cargo update` on the root workspace and each binding that has
//! a Cargo.lock file, ensuring all lock files are refreshed with the latest
//! compatible dependency versions according to their version constraints.
use std::path::{Path, PathBuf};
use std::process::Command;
use anyhow::{bail, Context, Result};
use clap::Args;
/// CLI entry point for `cargo xtask update-deps`.
#[derive(Args)]
pub struct UpdateDepsCommand {
/// Perform a dry run without actually updating lock files
#[arg(long)]
dry_run: bool,
}
impl UpdateDepsCommand {
/// Executes the dependency update workflow.
pub fn run(&self) -> Result<()> {
let workspace_root = workspace_root();
println!("Updating workspace dependencies...");
// Update root workspace
if self.dry_run {
println!(" [dry-run] Would update root workspace Cargo.lock");
} else {
update_manifest(&workspace_root, "Cargo.toml")?;
println!(" ✓ Updated root workspace");
}
// Update each binding with a Cargo.lock
let bindings = vec![
("ffi", "bindings/ffi/Cargo.toml"),
("java", "bindings/java/Cargo.toml"),
("python", "bindings/python/Cargo.toml"),
("wasm", "bindings/wasm/Cargo.toml"),
("ruby", "bindings/ruby/ext/regorusrb/Cargo.toml"),
];
for (name, manifest) in bindings {
let manifest_path = workspace_root.join(manifest);
if !manifest_path.exists() {
continue;
}
// Check if Cargo.lock exists
if let Some(parent) = manifest_path.parent() {
let lock_path = parent.join("Cargo.lock");
if lock_path.exists() {
if self.dry_run {
println!(" [dry-run] Would update {} binding", name);
} else {
update_manifest(&workspace_root, manifest)?;
println!(" ✓ Updated {} binding", name);
}
}
}
}
println!("\nDependency update complete!");
Ok(())
}
}
/// Returns the workspace root (one level above this crate).
fn workspace_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("xtask resides in workspace root")
.to_path_buf()
}
/// Runs cargo update for a specific manifest.
fn update_manifest(root: &Path, manifest: &str) -> Result<()> {
let manifest_path = root.join(manifest);
let output = Command::new("cargo")
.arg("update")
.arg("--manifest-path")
.arg(&manifest_path)
.output()
.context("failed to run cargo update")?;
if !output.status.success() {
bail!(
"cargo update failed for {}: {}",
manifest_path.display(),
String::from_utf8_lossy(&output.stderr).trim()
);
}
Ok(())
}