Skip to content

Commit 34e56d6

Browse files
authored
feat(sozo): apply semver to tag versions (#2909)
feat: apply semver to tag versions
1 parent c54c427 commit 34e56d6

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

bin/sozo/src/commands/mod.rs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use auth::AuthArgs;
55
use clap::Subcommand;
66
use events::EventsArgs;
77
use scarb::core::{Config, Package, Workspace};
8+
use semver::{Version, VersionReq};
89
use tracing::info_span;
910

1011
pub(crate) mod auth;
@@ -132,30 +133,52 @@ pub fn check_package_dojo_version(ws: &Workspace<'_>, package: &Package) -> anyh
132133

133134
let dojo_dep_str = dojo_dep.to_string();
134135

136+
dbg!(&dojo_dep_str);
137+
dbg!(&dojo_version);
138+
135139
// Only in case of git dependency with an explicit tag, we check if the tag is the same as
136140
// the current version.
137141
if dojo_dep_str.contains("git+")
138142
&& dojo_dep_str.contains("tag=v")
139143
&& !dojo_dep_str.contains(dojo_version)
140144
{
141-
if let Ok(cp) = ws.current_package() {
142-
let path =
143-
if cp.id == package.id { package.manifest_path() } else { ws.manifest_path() };
144-
145-
anyhow::bail!(
146-
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
147-
dependency in {}",
148-
dojo_version,
149-
path
150-
)
151-
} else {
152-
// Virtual workspace.
153-
anyhow::bail!(
154-
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
155-
dependency in {}",
156-
dojo_version,
157-
ws.manifest_path()
158-
)
145+
// safe to unwrap since we know the string contains "tag=v".
146+
// "dojo * (git+https://github.com/dojoengine/dojo?tag=v1.0.10)"
147+
let dojo_dep_version = dojo_dep_str.split("tag=v")
148+
.nth(1) // Get the part after "tag=v"
149+
.map(|s| s.trim_end_matches(')'))
150+
.expect("Unexpected dojo dependency format");
151+
152+
let dojo_dep_version = Version::parse(dojo_dep_version).unwrap();
153+
154+
let version_parts: Vec<&str> = dojo_version.split('.').collect();
155+
let major_minor = format!("{}.{}", version_parts[0], version_parts[1]);
156+
let dojo_req_version = VersionReq::parse(&format!(">={}", major_minor)).unwrap();
157+
158+
if !dojo_req_version.matches(&dojo_dep_version) {
159+
if let Ok(cp) = ws.current_package() {
160+
// Selected package.
161+
let path = if cp.id == package.id {
162+
package.manifest_path()
163+
} else {
164+
ws.manifest_path()
165+
};
166+
167+
anyhow::bail!(
168+
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
169+
dependency in {}",
170+
dojo_req_version,
171+
path
172+
)
173+
} else {
174+
// Virtual workspace.
175+
anyhow::bail!(
176+
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
177+
dependency in {}",
178+
dojo_req_version,
179+
ws.manifest_path()
180+
)
181+
}
159182
}
160183
}
161184
}

crates/dojo/core-cairo-test/Scarb.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version = 1
33

44
[[package]]
55
name = "dojo"
6-
version = "1.0.0-rc.0"
6+
version = "1.0.10"
77
dependencies = [
88
"dojo_plugin",
99
]

0 commit comments

Comments
 (0)