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

Matrix with 3.0 value will install 3.1 ruby #252

Closed
ShockwaveNN opened this issue Dec 28, 2021 · 10 comments
Closed

Matrix with 3.0 value will install 3.1 ruby #252

ShockwaveNN opened this issue Dec 28, 2021 · 10 comments

Comments

@ShockwaveNN
Copy link

ShockwaveNN commented Dec 28, 2021

I'm not totally sure that this is issue in ruby/setup-ruby iselft, but let me describe it

For quite a long time I've used this code block in different github actions in my different projects

name: Ruby
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    continue-on-error: ${{ matrix.allow-failures }}
    strategy:
      matrix:
        ruby: [2.5, 2.6, 2.7, 3.0]
        allow-failures: [false]
        include:
          - ruby: head
            allow-failures: true
    steps:
    - uses: actions/checkout@v2
    ....all_other_steps

This worked well, it set up several ruby versions and run my tests

But with the release of ruby v3.1 I've noticed a very strange situation

That instead of v3.0 is v3.1 actually installed

You can take a look at that workflow
On Setup Ruby 3 stage in logs we see that:

Installing Bundler
  Using Bundler 2.3.2 from Gemfile.lock BUNDLED WITH 2.3.2
  /opt/hostedtoolcache/Ruby/3.1.0/x64/bin/gem install bundler -v 2.3.2
  Successfully installed bundler-2.3.2
  1 gem installed
  Took   0.57 seconds

First of all - I fought 'oh my bad, seems that if I send version as interger and not strings if will install latest major version

But I've rechecked version 2.6 - it send in config as 2.6, not a '2.6' and still installing it correctly, not latest v2.7

I see in docs - https://github.com/ruby/setup-ruby#matrix-of-ruby-versions that 3.0 is in quotes, but I don't quite get why only 3.0 need quotes?

And if quotes are really required - maybe add some readme statement about this to clarify reasons?

@ShockwaveNN ShockwaveNN changed the title Matrix with 3.0 value wil install 3.1 ruby Matrix with 3.0 value will install 3.1 ruby Dec 28, 2021
@ShockwaveNN
Copy link
Author

ShockwaveNN commented Dec 28, 2021

Seems similar issues is tackled at #251 (comment)

But maybe we just force people to use quotes in version numbers and change documentation accordingly?

@dentarg
Copy link

dentarg commented Dec 28, 2021

Yes you need to use quotes due to actions/runner#849

@ShockwaveNN
Copy link
Author

Yeah, I agree if this problem in other dependency
But it's is year old and has little activity from GitHub developers, so I'm not sure if it will be fixed

So I think some mention or troubleshooting should be in readme of setup-ruby?
I'm sure with release of v3.1 and end of Christmas A LOT of people will notice that

@jrochkind
Copy link

jrochkind commented Dec 29, 2021

I'm running into this too, all my build started failing while running ruby 3.1.x while I thought I had told it to run ruby 3.0.x

I see the README has been changed, but this is pretty confusing. I wonder if ALL examples of ruby versions should use quotes?

After reading actions/runner#849, it's not clear to me that this is any kind of a bug, rather than just an unanticipated consequence of using a YAML numeric value.

I wonder if this action should interpret a 3 value as 3.0 -- like even if the user entered just 3, it would be treated as 3.0. If there is no decimal part given, treat it the same as a 0 decimal part. It may be unlikely anyone would ever mean "any 3.x", or "any 2.x", or "any 4.x"? When the 3.0 gets converted to the same as 3 internally, it seems safe to conclude that it means 3.0.

@MSP-Greg
Copy link
Collaborator

MSP-Greg commented Dec 29, 2021

@jrochkind

I wonder if this action should interpret a 3 value as 3.0

Although wanting to allow any version of Ruby matching 3.x.y is unlikely, I don't know about the above. Maybe a warning message. Not.Sure.

I wonder if ALL examples of ruby versions should use quotes?

Being considered...

A general rule is if the version text has a decimal point and ends with a zero, it should be quoted. If one wants to quote all the version values for consistency, that's fine.

@ShockwaveNN

but I don't quite get why only 3.0 need quotes?

YAML and other similar syntaxes are often designed to be human-readable and terse. So, parsers will try to parse a value as a number, and if that doesn't work, the value is considered a string. An example would be 3.0.3, which can't be parsed as a number. So, now we have 3.0. Many non-typed languages assume all numbers are floats, so, 3.0 is the same as 3. YAML has a means of forcing a float (!!float), but quotes are easier on the eyes. Also, I don't think the YAML parser used by Actions supports it.

Off-topic: the following yaml will be parsed by Psysch as two floats and a atring

---
[!!float 3, 4.0, 5.1.0]

@ShockwaveNN
Copy link
Author

A general rule is if the version text has a decimal point and ends with a zero, it should be quoted.

I don't think a lot of people think about then whey writing a simple yaml file with several lines

YAML and other similar syntaxes are often designed to be human-readable and terse.

Yeah, thanks for description. I understand technical problem and seems this will be rather complicated to resolve elegantly

Usually my rule of thumb - if someone can mess one value it's better to force everyone to use all values in quotes. So when writing a new YAML config you will not try to remember 'should I quote only 3.0 and can leave 3.1 without quotes...'

Or another way - show warning if case after parsing 3.0 was replace to 3 (being 3.1)

@jrochkind
Copy link

jrochkind commented Dec 29, 2021

Another option would be supporting/showing in examples rubygems-style specifiers.

If you want "latest 3.0.x", write ~> 3.0.0 , which YAML will interpret as a string even without quotes.

If we had to do it all over again, that seems desirable, now that we realize x.0 unquoted ends up being treated differently by logic in the current system, in which you write 2.7 and intend it to mean what to rubygems would be ~> 2.7.0. But of course to rubygems 2.7 alone means the same thing as 2.7.0, exact version 2.7.0. But making this action do that at this point would be a disruptive backwards incompat.

Although could still be done with a ruby/setup-ruby@v2, without disrupting existing users? Maybe a @v2 where more rubygems-style specifiers are used, you write ~> 3.0.0, and "3.0" even as string means the same thing as "3.0.0" (exact version either way, as it does to rubygems/bundler), so it doesn't matter if you write it as string or number?

I don't think anything is going to be changed in the GH runner yaml parser. It's pretty standard. For instance, almost any YAML to JSON converter you find will convert foo: 3.0 to JSON {'foo': 3}, it seems totally normal and standard to parse YAML unquoted 3.0 identically to YAML unquoted 3.0.

@MSP-Greg
Copy link
Collaborator

Maybe the easiest solution is to show all version examples quoted, and a brief explanation why?

picandocodigo added a commit to elastic/elasticsearch-ruby that referenced this issue Dec 31, 2021
picandocodigo added a commit to elastic/elasticsearch-ruby that referenced this issue Dec 31, 2021
picandocodigo added a commit to elastic/elasticsearch-ruby that referenced this issue Dec 31, 2021
picandocodigo added a commit to elastic/elasticsearch-ruby that referenced this issue Dec 31, 2021
pboling added a commit to oauth-xx/oauth2 that referenced this issue Feb 16, 2022
> A general rule is if the version text has a decimal point and ends with a zero, it should be quoted. If one wants to quote all the version values for consistency, that's fine.

ref: ruby/setup-ruby#252 (comment)
Signed-off-by: Peter Boling <peter.boling@gmail.com>
gregorw added a commit to gregorw/discriminable that referenced this issue Mar 20, 2022
@pboling
Copy link

pboling commented May 1, 2022

3.0 needs quotes because it is == 3, and it is treated as a float, not a string. It isn't the only one that needs quotes, 2.0 currently has the same exact problem, and someday 4.0 will too. This is standard YAML, and as a result I've begun quoting all my version numbers to avoid the confusing why this-not-that. IMO, this issue should be closed as not-a-bug or wont-fix.

@eregon
Copy link
Member

eregon commented May 16, 2022

I've added quotes in the README, etc: b9675e1

This is standard YAML

No, because the GH Actions C# YAML parser could easily differentiate 3.0 and 3 (just like Ruby does), or maybe even treat all action inputs as strings without touching them, but instead it has this leaky number type which doesn't remember if it was floating point or not.
That said, it doesn't sound like actions/runner#849 is seeing much progress if at all.
Let's close this, the ball is in GitHub's YAML parser.

@eregon eregon closed this as completed May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants