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

Consider enabling - (dash/hypen) in prerelease strings #3086

Closed
2 of 5 tasks
aharpervc opened this issue Jan 16, 2020 · 11 comments
Closed
2 of 5 tasks

Consider enabling - (dash/hypen) in prerelease strings #3086

aharpervc opened this issue Jan 16, 2020 · 11 comments

Comments

@aharpervc
Copy link

I'm having a problem and would like to a feature.

My current problem is:

I would like to publish prerelease versions with dashes, eg something like 1.2.0.pre-update-logo. This appears to not be possible as of rubygems version 3.0.4:

irb(main):001:0> Gem::Version.new('1.2.0.pre-update-logo')
=> #<Gem::Version "1.2.0.pre.pre.update.pre.logo">

The -'s are all replaced by .pre. which is fairly unhelpful (except possibly the first replacement). That happens here:

@version = version.to_s.strip.gsub("-",".pre.")

Dashes in prerelease versions are allowed by the SemVer spec:

A pre-release version MAY be denoted by appending a hyphen and a series of dot separated identifiers immediately following the patch version. Identifiers MUST comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-]

Note that I'm not asking about "FULL SEMVER", but only about dashes in prerelease labels

This issue is related to:

  • Network problems
  • Installing a library
  • Publishing a library
  • The command line gem
  • Other

Other issues:

Here are my current environment details:

$ gem env version
RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.4
  - RUBY VERSION: 2.5.3 (2018-10-18 patchlevel 105) [x86_64-linux]
(etc, n/a)

I will abide by the code of conduct.

@esotericpig
Copy link

I had a similar thing with bundler.

My Gemspec:

spec.version = '0.4.9-alpha'

According to Semantic Version v2, this is correct.

I then created a release and tag on GitHub as v0.4.9-alpha.

Then I was surprised when I did this command:

$ bundle exec rake release

as it then creates the release and tag:

v0.4.9.pre.alpha

I decided to just remove -alpha because then I'd have to do all of my releases manually.

I think it'd be good to change this for bundler/gem_tasks (which is gem_helper).

You can see my example releases here.

@pboling
Copy link
Contributor

pboling commented Oct 9, 2023

Just ran into this, and now I'm not sure what the correct way to version my gem is. I'm trying to follow SemVer, but RubyGems doesn't allow it.

I'd also like for my version string to match the tagged and released version, as well as the version people put in their gemfiles.

@martinemde
Copy link
Member

martinemde commented Oct 9, 2023

I think the fundamental challenge here is that rubygems get composed into dash separated strings from the gem name, version, and platform. This means that require_bench-1.0.4-alpha2 would have an identical filename to the gem require_bench version 1.0.4 for platform alpha2. As far as I understand, this is why the versions dashes are converted.

I'm not commenting on whether or not it will get solved, but I don't think it will be easy without changing how gems are stored on the file system and on the CDN.

@indirect
Copy link
Member

indirect commented Oct 9, 2023

As you all have noticed, you can in fact denote prerelease versions by putting a dash in the version number.

RubyGems is not able to put that dash into the filename (as described by Martin above), so the dash is always converted to .pre. instead. For example, this Gemfile installs the gem whose file is conjur-debify-3.0.3.pre.1933.gem:

source "https://rubygems.org"
gem "conjur-debify", "3.0.3-1933"

That said, if you want your version string, tag, .gem filename, etc, to all be identical, you need to use .pre. instead of -.

In conclusion, RubyGems does allow a dash in prerelease version strings, but we cannot put that dash into the final .gem filename without any modification.

@indirect indirect closed this as completed Oct 9, 2023
@aharpervc
Copy link
Author

aharpervc commented Oct 10, 2023

In conclusion, RubyGems does allow a dash in prerelease version strings

What parameter value should I pass to Gem::Version.new to have the resulting value show dashes, per the example above?

@martinemde
Copy link
Member

martinemde commented Oct 10, 2023

Whoa! I used the github mobile app to quote reply and it edited your comment! Very sorry. Let me see if I can revert it. How strange! (Edit: I can’t seem to completely remove my edit but I restored the original text.)

My reply:

The file cannot currently have the dash, nor will Gem::Version preserve it. The goal is that dash conversions are consistent across bundler and rubygems. If you specify a gem with version 1.2.3-alpha, and then you install that gem via gem or Bundler as 1.2.3-alpha, you will get that same gem version.

@aharpervc
Copy link
Author

aharpervc commented Oct 10, 2023

If you specify a gem with version 1.2.3-alpha

How can this version be defined? Also, how would you do 1.2.3-alpha-with-dashes?

When I run that in irb, I get this, which is the same as what I originally posted above and remains unresolved:

irb(main):002:0> Gem::Version.new('1.2.3-alpha-with-dashes')
=> Gem::Version.new("1.2.3.pre.alpha.pre.with.pre.dashes")

@martinemde
Copy link
Member

If you name your gem and add it to bundler in the same way, it should work regardless of how the file and version are transformed internally. I agree it's not pretty but SemVer didn't exist when rubygems adopted this pattern.

@pboling
Copy link
Contributor

pboling commented Oct 10, 2023

When pre-release versions are involved Gem::Version.new comparison operator doesn't sort them properly.

gem_pkgs = File.join("pkg", "*.gem")
gems = Dir[gem_pkgs]
# Should be newest last!
gems.sort_by! { |gem| Gem::Version.new(gem[VERSION_REGEX]) }
gem_pkg = gems.last
puts gem_pkg # => "pkg/my_gem-1.0.4.pre.alpha.7.gem"

It should have been "pkg/my_gem-1.0.4.gem"
Screenshot 2023-10-10 at 12 02 18

@martinemde
Copy link
Member

martinemde commented Oct 10, 2023

I don't get the same result:

irb(main):008> [Gem::Version.new("1.0.4-alpha1"), Gem::Version.new("1.0.4-alpha12"), Gem::Version.new("1.0.4")].sort
=> [Gem::Version.new("1.0.4.pre.alpha1"), Gem::Version.new("1.0.4.pre.alpha12"), Gem::Version.new("1.0.4")]

I think you're including .gem in the version number.

irb(main):009> [Gem::Version.new("1.0.4-alpha1.gem"), Gem::Version.new("1.0.4-alpha2.gem"), Gem::Version.new("1.0.4.gem")].sort
=> [Gem::Version.new("1.0.4.gem"), Gem::Version.new("1.0.4.pre.alpha1.gem"), Gem::Version.new("1.0.4.pre.alpha2.gem")]

@pboling
Copy link
Contributor

pboling commented Oct 11, 2023

That was exactly it. Thanks! I assumed erroneously that it would handle .gem in some special way (because it worked until I used it with pre-release versions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants