actions / setup-ruby

Set up your GitHub Actions workflow with a specific version of Ruby
MIT License
173 stars 69 forks source link

Support .ruby-version #31

Open scottohara opened 5 years ago

scottohara commented 5 years ago

Many ruby projects include a .ruby-version file in the root directory, containing the version of Ruby needed.

Tools such as rvm, rbenv and chruby all recognise and use this file.

This is not unlike the .nvmrc file often used in Node projects, and the setup-node action has a discussion on potentially using the contents of that file as the node version if no with: argument is specified. (https://github.com/actions/setup-node/issues/32)

I would suggest that setup-ruby might consider a similar approach, where if no explicit ruby version is given, look for a .ruby-version file and use the version contained within.

tisba commented 4 years ago

I was wondering if there is a workaround available, like

- name: Set up Ruby
  uses: actions/setup-ruby@v1
  with:
    ruby-version: "{{ cat('.ruby-version') }}"

However I was not able to figure out how to do that yet :(

sobstel commented 4 years ago

I found a workaround in actions/setup-node repo.

- run: echo "::set-output name=RUBY_VERSION::$(cat .ruby-version)"
  id: rbenv

- uses: actions/setup-ruby@v1
  with:
   ruby-version: "${{ steps.rbenv.outputs.RUBY_VERSION }}"
bryanmacfarlane commented 4 years ago

happy to see the workaround ☝️ - leaving as an enhancement for consideration

vvo commented 4 years ago

@bryanmacfarlane To be honest, and without any anger or nothing, I want to point out that supporting .ruby-version should not be seen as an "enhancement" but as a requirement for the ruby community. When any company starts a Ruby project they will first choose between rvm or rbenv, most of them. And the next step will be to create a .ruby-version file to easily create a reproducible environment for devs and continuous integration, which is supported by both rbenv and rvm.

Thus I think we should consider supporting the .ruby-version really as a requirement to consider "setup-ruby" good enough for any Ruby project. Right now a lot of people are just not using it and instead using https://github.com/eregon/use-ruby-action or https://github.com/masa-iwasaki/setup-rbenv.

I think it's fine and great that people are creating actions on the marketplace but for some very popular actions, the ones from GitHub should really cover most use cases otherwise we'll endup with a marketplace like the npm registry where you spend half a day trying to find the "right" ruby action that works well..

Thanks for consideration!

PS: Maybe @eregon, creator of use-ruby-action you have some thoughts about this too? Thanks!

eregon commented 4 years ago

I implemented it in use-ruby-action (issue: https://github.com/eregon/use-ruby-action/issues/4). It's really trivial.

I think longer term we'll want most (all maybe) features of use-ruby-action in this repo: https://github.com/actions/setup-ruby/issues/44

mo-rubikal commented 4 years ago

I saw the same concept works for user-ruby-action as following: (tested and working)


      - name: Install Ruby version from .ruby-version
        uses: eregon/use-ruby-action@master

It would be nice if that supported the same way here.

MSP-Greg commented 4 years ago

Given that someone may be AFK...

eregon/use-ruby-action@master has moved to ruby/setup-ruby.

For info specific to .ruby_version, see supported-version-syntax.

ruby/setup-ruby supports almost all Ruby versions since 2.2, fully tested head/master builds, and all platforms are supported. Understandably, GitHub prefers not to host EOL software, but others can, as does ruby/setup-ruby. I'm not recommending using it.

Also, most actions that are past development stage are not using master. Or, master may be dangerous, as new features may be developed there. So, use

uses: ruby/setup-ruby@v1

instead of

uses: ruby/setup-ruby@master
mo-rubikal commented 4 years ago

That got me confused as I was trying to install my ruby version which I can't give as an argument for setup-ruby, and the only way mentioned as in the example:

    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 2.6

Until I landed in an example that does so as my last comment, I wonder why that not specified in the docs here, if that is the official one!

MSP-Greg commented 4 years ago

Forgive me, I'm confused.

why that not specified in the docs here

here is actions/setup-ruby, which is the action supported by GitHub.

My post was mostly referring to ruby/setup-ruby (which is where eregon/use-ruby-action moved to) which is within the Ruby organization, and is not supported by GitHub.

If, using ruby/setup-ruby, you want to read Ruby version info from the .ruby-version file, use:

- uses: ruby/setup-ruby@v1
  with:
    ruby-version: .ruby-version

You can also not include the ruby-version: input, but specifying .ruby-version makes it very clear where the info is retrieved from.

mo-rubikal commented 4 years ago

Thanks, @MSP-Greg for clarification, both have the same name really confused me, between Ruby and Actions, and BTW when I used:

uses: ruby/setup-ruby@v1

without with clause it worked as well

Screen Shot 2020-04-06 at 4 12 24 AM

eregon commented 4 years ago

@mo-rubikal Glad you found how to use it. Do you think the docs at https://github.com/ruby/setup-ruby#usage are clear enough about this? If not, please file an issue and I'll try to improve them.