From 34e56d6dc8d047d9972535824de6596c6cf58b2c Mon Sep 17 00:00:00 2001 From: glihm Date: Tue, 14 Jan 2025 12:35:00 -0600 Subject: [PATCH] feat(sozo): apply semver to tag versions (#2909) feat: apply semver to tag versions --- bin/sozo/src/commands/mod.rs | 59 ++++++++++++++++++-------- crates/dojo/core-cairo-test/Scarb.lock | 2 +- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/bin/sozo/src/commands/mod.rs b/bin/sozo/src/commands/mod.rs index 0c737dfa0c..8aedc965f0 100644 --- a/bin/sozo/src/commands/mod.rs +++ b/bin/sozo/src/commands/mod.rs @@ -5,6 +5,7 @@ use auth::AuthArgs; use clap::Subcommand; use events::EventsArgs; use scarb::core::{Config, Package, Workspace}; +use semver::{Version, VersionReq}; use tracing::info_span; pub(crate) mod auth; @@ -132,30 +133,52 @@ pub fn check_package_dojo_version(ws: &Workspace<'_>, package: &Package) -> anyh let dojo_dep_str = dojo_dep.to_string(); + dbg!(&dojo_dep_str); + dbg!(&dojo_version); + // Only in case of git dependency with an explicit tag, we check if the tag is the same as // the current version. if dojo_dep_str.contains("git+") && dojo_dep_str.contains("tag=v") && !dojo_dep_str.contains(dojo_version) { - if let Ok(cp) = ws.current_package() { - let path = - if cp.id == package.id { package.manifest_path() } else { ws.manifest_path() }; - - anyhow::bail!( - "Found dojo-core version mismatch: expected {}. Please verify your dojo \ - dependency in {}", - dojo_version, - path - ) - } else { - // Virtual workspace. - anyhow::bail!( - "Found dojo-core version mismatch: expected {}. Please verify your dojo \ - dependency in {}", - dojo_version, - ws.manifest_path() - ) + // safe to unwrap since we know the string contains "tag=v". + // "dojo * (git+https://github.com/dojoengine/dojo?tag=v1.0.10)" + let dojo_dep_version = dojo_dep_str.split("tag=v") + .nth(1) // Get the part after "tag=v" + .map(|s| s.trim_end_matches(')')) + .expect("Unexpected dojo dependency format"); + + let dojo_dep_version = Version::parse(dojo_dep_version).unwrap(); + + let version_parts: Vec<&str> = dojo_version.split('.').collect(); + let major_minor = format!("{}.{}", version_parts[0], version_parts[1]); + let dojo_req_version = VersionReq::parse(&format!(">={}", major_minor)).unwrap(); + + if !dojo_req_version.matches(&dojo_dep_version) { + if let Ok(cp) = ws.current_package() { + // Selected package. + let path = if cp.id == package.id { + package.manifest_path() + } else { + ws.manifest_path() + }; + + anyhow::bail!( + "Found dojo-core version mismatch: expected {}. Please verify your dojo \ + dependency in {}", + dojo_req_version, + path + ) + } else { + // Virtual workspace. + anyhow::bail!( + "Found dojo-core version mismatch: expected {}. Please verify your dojo \ + dependency in {}", + dojo_req_version, + ws.manifest_path() + ) + } } } } diff --git a/crates/dojo/core-cairo-test/Scarb.lock b/crates/dojo/core-cairo-test/Scarb.lock index 2c1a7ab14c..8c428deae3 100644 --- a/crates/dojo/core-cairo-test/Scarb.lock +++ b/crates/dojo/core-cairo-test/Scarb.lock @@ -3,7 +3,7 @@ version = 1 [[package]] name = "dojo" -version = "1.0.0-rc.0" +version = "1.0.10" dependencies = [ "dojo_plugin", ]