Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sozo): apply semver to tag versions #2909

Merged
merged 1 commit into from
Jan 14, 2025
Merged

feat(sozo): apply semver to tag versions #2909

merged 1 commit into from
Jan 14, 2025

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Jan 14, 2025

This PR adds semver behavior for the usage of dojo versions, since we can't use scarbs.xyz yet.

Summary by CodeRabbit

  • New Features

    • Enhanced version compatibility checking for Dojo dependencies
    • Improved error reporting for package version mismatches
  • Refactor

    • Upgraded version comparison logic to use semantic versioning checks

@glihm glihm mentioned this pull request Jan 14, 2025
Copy link

coderabbitai bot commented Jan 14, 2025

Walkthrough

Ohayo, sensei! The changes focus on enhancing the version compatibility checking mechanism for Dojo packages. The modification introduces a more sophisticated approach to comparing Dojo dependency versions by leveraging the semver crate. The new implementation parses version strings more precisely, creating version requirement objects that allow for more nuanced version compatibility checks, with improved error handling and debugging capabilities.

Changes

File Change Summary
bin/sozo/src/commands/mod.rs - Added semver imports for version parsing
- Enhanced check_package_dojo_version function with more robust version comparison
- Introduced detailed version extraction and compatibility checking logic

Sequence Diagram

sequenceDiagram
    participant Package as Current Package
    participant DepChecker as Dependency Version Checker
    participant SemVer as Semver Parser

    Package->>DepChecker: Request version check
    DepChecker->>SemVer: Extract dependency version
    SemVer-->>DepChecker: Parsed Version
    DepChecker->>DepChecker: Create Version Requirement
    DepChecker->>SemVer: Check Version Compatibility
    SemVer-->>DepChecker: Compatibility Result
    DepChecker-->>Package: Return Compatibility Status
Loading

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
bin/sozo/src/commands/mod.rs (1)

147-151: Ohayo sensei! Consider using a more robust method to extract the tag version.

Splitting dojo_dep_str based on hardcoded substrings like "tag=v" can be brittle. If the dependency format changes, this method may fail. Consider using URL parsing libraries or regular expressions to extract the tag parameter more reliably.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c54c427 and 3a676ba.

⛔ Files ignored due to path filters (1)
  • crates/dojo/core-cairo-test/Scarb.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • bin/sozo/src/commands/mod.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: fmt
🔇 Additional comments (1)
bin/sozo/src/commands/mod.rs (1)

145-181: Ohayo sensei! Great job enhancing version compatibility checking using semver.

The introduction of semantic versioning improves the reliability and flexibility of dependency management within the Dojo project.

Comment on lines +136 to +137
dbg!(&dojo_dep_str);
dbg!(&dojo_version);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ohayo sensei! Please remove debug statements before committing code.

The use of dbg!() macro is intended for debugging purposes and should not be included in production code as it can clutter output and expose internal state.

Apply this diff to remove the debug statements:

-            dbg!(&dojo_dep_str);
-            dbg!(&dojo_version);

Comment on lines +154 to +155
let version_parts: Vec<&str> = dojo_version.split('.').collect();
let major_minor = format!("{}.{}", version_parts[0], version_parts[1]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ohayo sensei! Ensure dojo_version has major and minor components to prevent panics.

Accessing version_parts[0] and version_parts[1] without verifying the length may cause an index out of bounds panic if dojo_version doesn't contain both major and minor parts.

Modify the code to check the length before accessing the elements:

                 let version_parts: Vec<&str> = dojo_version.split('.').collect();
+                if version_parts.len() < 2 {
+                    anyhow::bail!("Invalid dojo version format: {}", dojo_version);
+                }
                 let major_minor = format!("{}.{}", version_parts[0], version_parts[1]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let version_parts: Vec<&str> = dojo_version.split('.').collect();
let major_minor = format!("{}.{}", version_parts[0], version_parts[1]);
let version_parts: Vec<&str> = dojo_version.split('.').collect();
if version_parts.len() < 2 {
anyhow::bail!("Invalid dojo version format: {}", dojo_version);
}
let major_minor = format!("{}.{}", version_parts[0], version_parts[1]);

Comment on lines +147 to +156
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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ohayo sensei! Handle potential parsing errors to prevent panics.

Using .unwrap() when parsing versions can lead to runtime panics if the input strings are not in the expected format. To enhance robustness, handle these errors gracefully using map_err or the ? operator.

Apply this diff to handle parsing errors:

-                let dojo_dep_version = Version::parse(dojo_dep_version).unwrap();
+                let dojo_dep_version = Version::parse(dojo_dep_version)
+                    .map_err(|e| anyhow::anyhow!("Failed to parse dojo dependency version: {}", e))?;

...

-                let dojo_req_version = VersionReq::parse(&format!(">={}", major_minor)).unwrap();
+                let dojo_req_version = VersionReq::parse(&format!(">={}", major_minor))
+                    .map_err(|e| anyhow::anyhow!("Failed to parse required dojo version: {}", e))?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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();
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)
.map_err(|e| anyhow::anyhow!("Failed to parse dojo dependency version: {}", e))?;
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))
.map_err(|e| anyhow::anyhow!("Failed to parse required dojo version: {}", e))?;

@glihm glihm changed the title feat: apply semver to tag versions feat(sozo): apply semver to tag versions Jan 14, 2025
Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 0% with 31 lines in your changes missing coverage. Please review.

Project coverage is 56.04%. Comparing base (c54c427) to head (3a676ba).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
bin/sozo/src/commands/mod.rs 0.00% 31 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2909      +/-   ##
==========================================
- Coverage   56.05%   56.04%   -0.02%     
==========================================
  Files         449      449              
  Lines       57927    57944      +17     
==========================================
- Hits        32473    32472       -1     
- Misses      25454    25472      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glihm glihm merged commit 34e56d6 into main Jan 14, 2025
13 of 15 checks passed
@glihm glihm deleted the sozo/dojo-version branch January 14, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant