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
Method to bump semantic version #12499
Comments
Nice! Getting ahead of a possible PR, I have a question. I understand that you have something like enum Bump
Major
Minor
Patch
end How do you fancy the name |
Well, the enum is actually enum Bump
Major
Minor
Patch
PreMajor
PreMinor
PrePatch
PreRelease
end So I used some CLI tools that do version operations (namely npm and poetry) as a base, but even then there are some differences in behavior, so I could make changes to make the implementation a better solution for the community needs. |
@beta-ziliani I made a draft with the snippets I've been using so far; any suggestions to make it more suitable for a PR? |
We'll look into it after 1.6 is released. |
Hi @gabriel-ss thanks for your patience! I checked your proposal. I'd say I prefer to have different methods for each part, as in |
As suggested in #7637 (comment), I think a method |
Hey @beta-ziliani, using a The only point is how exactly to handle the pre-releases; since a version with a pre-release is actually lower than the same version without one, doing it in two operations would mean to go backwards in the second one. Not really a problem, just a little quirk, and probably means that there is a part of the version handling logic that the applications will have to implement themselves, but then again maybe the need for this functionality doesn't come very often. What do you have in mind for an API to manipulate the pre-releases? |
I'm not sure about bumping prereleases. It only works for scenarios like "rc", but not in those like "alpha", so in those cases I guess it's simpler to just go with I have three possible implementations, probably the last one is my favorite, but not strongly.
def bump_major(prerelease : String | Prerelease | Nil = nil, build : String? = nil)
def bump_minor(prerelease : String | Prerelease | Nil = nil, build : String? = nil)
def bump_patch(prerelease : String | Prerelease | Nil = nil, build : String? = nil)
def bump_prerelease(build : String? = nil) # precondition: it should have a prerelease! And I'm not sure it should exists
# In this scenario Part makes more sense
Enum Part
Major
Minor
Patch
Prerelease # not sure about this one
end
def bump(part : Part, prerelease : String | Prerelease | Nil = nil, build : String? = nil)
struct Bump
end
BUMP = Bump.new
def copy_with(major : Int | Bump = @major, minor : Int | Bump = @minor, patch : Int | Bump = @patch, prerelease : String | Prerelease | Nil = @prerealease, build : String? = @build) |
My preference would be this:
def copy_with(major : Int32 = @major, minor : Int32 = @minor, patch : Int32 = @patch, prerelease : String | Prerelease | Nil = @prerealease, build : String? = @build)
def bump_major
def bump_minor
def bump_patch Maybe also a |
I agree with the arguments about the pre-releases; it's really hard to come up with a bump implementation that would work across multiple conventions. Maybe the best here is to just leave it open. About the methods to bump versions, I find the semantic of version.copy_with(minor: BUMP) very elegant, but at the same time, if copy_with is supposed to be a low-level building block to, say, a package manager, I don't know if the special semantics would be appropriated. I'm divided between 3 and 4 in this case. In both cases though, I think it would bring a great convenience by handling the edge cases, in special bumping the patch of a pre-release. I would be happy with either one. |
let's go with 4. sounds good? |
Nice! Do you mind if I work on my previous implementation to make a new draft over the weekend? I'll let you guys know as soon as it's ready. |
@straight-shoota, @beta-ziliani, I made a new draft! What are your thoughts on this one? |
Looks good. Why don't you open a PR for it? |
Recently, I've been using Crystal at work to create some tools for the team and it's been awesome. One of the features of the std lib that has been very useful is the Semantic Version module; having a class with all the arithmetic for versions implemented helped during the development of many tools.
The only feature it currently lacks is a method to evaluate the next semantic version given the current version and the type of bump. Since this is a snippet that I reused in multiple projects, I thought that other people might find it useful enough to have in the std lib.
My implementation, created by extending the std class, can be used as:
Is there any interest in a PR adding something like this to the language?
The text was updated successfully, but these errors were encountered: