Skip to content

Commit

Permalink
feat(sozo): apply semver to tag versions (#2909)
Browse files Browse the repository at this point in the history
feat: apply semver to tag versions
  • Loading branch information
glihm authored Jan 14, 2025
1 parent c54c427 commit 34e56d6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
59 changes: 41 additions & 18 deletions bin/sozo/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo/core-cairo-test/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version = 1

[[package]]
name = "dojo"
version = "1.0.0-rc.0"
version = "1.0.10"
dependencies = [
"dojo_plugin",
]
Expand Down

0 comments on commit 34e56d6

Please sign in to comment.