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

Add command to install latest stable version of a tool #216

Closed
Stratus3D opened this issue Aug 8, 2017 · 9 comments · Fixed by #575
Closed

Add command to install latest stable version of a tool #216

Stratus3D opened this issue Aug 8, 2017 · 9 comments · Fixed by #575

Comments

@Stratus3D
Copy link
Member

Right now it's up to plugins to decide how they list versions. Some list only stable releases, others may list all releases. Some may print out the versions sorted incorrectly. This prevents us from just doing asdf list-all "$tool" | tail -1 to get the latest stable version of a tool.

We need a command that allows us to install the latest stable version of a tool. In order to have such a command we will need to have a latest-stable callback script in each plugin that returns the latest stable version of a tool. Then we can add a --latest flag to the install command so we can do asdf install ruby --latest to install the version of Ruby returned from the Ruby plugin's latest-stable callback. The callback script would need to return the latest stable version of the tool for the given architecture. Some plugins have different versions available for different architectures, so if a plugin does include the latest-stable it must chose to the right version for the architecture.

This latest-stable callback script would start out optional, but could eventually be made a requirement by adding an assertion to the plugin-test command.

Created when reviewing thoughtbot/laptop#502

@prasannavl
Copy link

prasannavl commented Oct 14, 2017

Once the referred issues are resolved, what would be nice is to have a package cleanup command, that retains only the latest minor versions by default, but still allowing the cleanup for major versions from an input flag, and also optionally a way to hold certain packages manually.

While versioning semantics may differ, asdf could just follow semantic versioning, with optional plugin API that can be used to override this behaviour for custom semantics by the plugins.

This should provide the full functionality needed to maintain a sort of rolling release model. Then this tool can fully replace nvm, gvm etc.

@NightMachinery
Copy link

Has any progress happened since 2017?

@quintrino
Copy link

quintrino commented Sep 5, 2019

I don't know if it's still under development, but this might help you @NightMachinary

I have a small method I've been using in a ruby file that might be of help to you.

def latest(language)
  `asdf plugin-add #{language} 2> /dev/null`
  versions = `asdf list-all #{language} 2> /dev/null`.split("\n")
  stock_versions = versions.select { |v| v.count('a-zA-Z').zero? }
  latest_version = stock_versions.max_by { |v| Gem::Version.new(v) }
  `asdf install #{language} #{latest_version}`
end

So far it's proven functional for Ruby, Rust, Node, Postgres, Elixir and Elm, but other languages may break it.

(This is slightly modified from the original that I use which just returned the version number but should when run in a ruby file/executable install the latest version)

@NightMachinery
Copy link

@quintrino Thanks! I adapted that into a script:

#!/usr/bin/env ruby
def latest(language)
  `asdf plugin-add #{language} 2> /dev/null`
  versions = `asdf list-all #{language} 2> /dev/null`.split("\n")
  stock_versions = versions.select { |v| v.count('a-zA-Z').zero? }
  latest_version = stock_versions.max_by { |v| Gem::Version.new(v) }
  `asdf install #{language} #{latest_version}`
end
latest(ARGV[0])

@quintrino
Copy link

Great!

One thing to keep in mind is that this only works if the default version of the language doesn't include letters in it's name while the alternate versions do.

So with Ruby, the line
stock_versions = versions.select { |v| v.count('a-zA-Z').zero? }
filters out jruby, mruby and preview versions, but keeps the core versions of 2.6.4.

If the core or default version of a language included letters, this would filter it out.

@klane
Copy link
Contributor

klane commented Sep 6, 2019

@NightMachinary @quintrino What do you think about integrating the logic from xxenv-latest into asdf? I currently use it with pyenv and have been pleased, but I am looking into switching to asdf to handle all the languages I use. It defaults to grabbing the latest numeric version like your Ruby script, but permits an additional parameter by which to filter versions. I have not tested it with rbenv, but I imagine it behaves like:

  • rbenv latest install installs 2.6.4
  • rbenv latest install 2.5 installs 2.5.6
  • rbenv latest install jruby installs jruby-9.2.8.0

An asdf implementation could allow:

  • asdf install ruby latest
  • asdf install ruby latest 2.5
  • asdf install ruby latest jruby

It could also look similar to the existing ref support to avoid an additional parameter:

  • asdf install ruby latest
  • asdf install ruby latest:2.5
  • asdf install ruby latest:jruby

I think this would just require updating the install_tool_version function in install.sh. There could also be a new latest or list-latest function to print the version (similar to list and list-all), which install_tool_version would then leverage to get the version.

@NightMachinery
Copy link

NightMachinery commented Sep 8, 2019 via email

@dre-hh
Copy link

dre-hh commented Sep 17, 2019

@NightMachinary @quintrino
tuned your script a bit
https://gist.github.com/dre-hh/88a119bc1e69892e45317eb04c2af9da

can't we add ruby as optional dependency to asdf for implementing latest? 🤣

@ig0rsky
Copy link

ig0rsky commented Apr 14, 2020

For those who end up here: here's my bash script for updating every asdf plugin dependency to latest:
https://gist.github.com/ig0rsky/fef7f785b940d13b52eb1b379bd7438d

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

Successfully merging a pull request may close this issue.

7 participants