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

default to latest version when no <version> argument supplied #22

Open
raingloom opened this issue Dec 6, 2016 · 26 comments
Open

default to latest version when no <version> argument supplied #22

raingloom opened this issue Dec 6, 2016 · 26 comments

Comments

@raingloom
Copy link

As the title says, I think this wouldn't be hard to implement and would make sure eg. that the latest bugfixes are installed.

Step 2: parse semver string and install latest compatible version

eg.: luaver install 5.3 will install the latest 5.3 series release

@DhavalKapil
Copy link
Owner

I didn't understand your statement. Can you give me some additional examples?

@raingloom
Copy link
Author

raingloom commented Dec 16, 2016

Say you want to download the latest 5.3 release, but don't remember the exact version number, in that case you should be able to write luaver install 5.3. As it is right now, luaver will look for a source tarball with that exact name and of course, not find it. There will be a https://www.lua.org/ftp/lua-5.3.3.tar.gz file, but no https://www.lua.org/ftp/lua-5.3.tar.gz.

So instead of having to look up what the exact version string is (eg.: 5.3.3), they could write only the first two components (eg.: 5.3) and luaver could automatically look up the correct version and download that.

I think this could be implemented even in a single line of shell script with curl and grep and would make usability just a bit better.

@umireon
Copy link
Contributor

umireon commented Dec 17, 2016

This is not feasible with a single line of shell script because luaver does not ship with the list of lua versions.

@DhavalKapil
Copy link
Owner

I agree that this won't be feasible with a single line shell script. Anyhow, I'm planning to add it as it will improve the usability a lot.

@raingloom
Copy link
Author

In the meantime I started prototyping it in a fork .

Is it looking ok? Should I do the rest too?

@DhavalKapil
Copy link
Owner

But how are you going to find out the latest version of lua?

@umireon
Copy link
Contributor

umireon commented Dec 17, 2016

AFAIK nvm is the only runtime version manager which implements version aliasing.

nvm install 6

They work hard to extract the latest version.

@raingloom
Copy link
Author

@DhavalKapil I haven't tested it yet, but the basic idea is to parse a semver version string and convert it to a grep pattern, then apply that pattern to the html page we get from the lua.org server, then sort (and now i realize it should be reverse sort) the matching lines and just select the first one.

Eg.: 5.2 as regex: '5\.2\..'. This is not completely correct (should be '5\.2\.[0-9]+'), but worked for the latest versions. I'll make it more robust later today and try to work out how to fit it into the script as a whole.

@DhavalKapil
Copy link
Owner

That's cool. Let me know if you're able to solve this :)

@umireon
Copy link
Contributor

umireon commented Dec 19, 2016

IMO having static aliases is simple and enough like this:

__luaver_resolve_lua_version()
{
    case "$1" in
        5 | 5.3 ) echo 5.3.3 ;;
        5.2 ) echo 5.2.4 ;;
        5.1 ) echo 5.1.5 ;;
        5.0 ) echo 5.0.3 ;;
        * ) echo "$1"
    esac
}

@DhavalKapil
Copy link
Owner

I'd rather not go for hardcoding the version within the source code.

@umireon
Copy link
Contributor

umireon commented Dec 19, 2016

I'm afraid web-scraping lua.org may easily break when the lua team decide to change the look-and-feel of their site.
I think getting git tags using wget or curl could be better because they supposed to never be changed.

@DhavalKapil
Copy link
Owner

Using git tags sounds like a good solution!
@raingloom ^

@umireon
Copy link
Contributor

umireon commented Dec 19, 2016

$ digit='[0-9]'
$ curl -fsSL https://api.github.com/repos/lua/lua/git/refs/tags | \
  awk 'match($0, /"refs\/tags\/v'"$digit"."$digit"."$digit"'"/) { $0 = substr($0, RSTART + 12, 5) ; gsub("[-_]", ".") ; print }'
2.5.1
5.2.0
5.2.1
5.2.2
5.2.3
5.3.0
5.3.1
5.3.2
5.3.3
5.1.1

Note that the -o, --only-matchoption of grep may suffer from portability problems.

@raingloom
Copy link
Author

@umireon that really is cleaner, but I think it's more robust to use the original source. Also, sorry, I can't work much on the code this week, I have some important exams, so I can't promise anything.

@umireon
Copy link
Contributor

umireon commented Dec 20, 2016

@raingloom https://github.com/lua/lua is a kind of the original source.

@umireon
Copy link
Contributor

umireon commented Dec 20, 2016

You can use case to avoid any process invocations and "bashisms".

case "$1" in
    5 ) echo "$1.[0-9]+.[0-9]+" ;;
    5.[0-9] ) echo "$1.[0-9]+" ;;
    * ) echo "$1"
esac

@umireon
Copy link
Contributor

umireon commented Dec 21, 2016

lua-all.tar.gz is on the original source and more reliable to obtain the list of versions.

$ curl -fsSL https://www.lua.org/ftp/lua-all.tar.gz | tar -tz | \
  awk 'BEGIN { FS="/" }; /lua-.*\/$/ { print substr($2, 5) }'
1.0
1.1
2.1
2.2
2.4
2.5
2.5.1
3.0
3.1
3.2
3.2.1
3.2.2
4.0
4.0.1
5.0
5.0.1
5.0.2
5.0.3
5.1
5.1.1
5.1.2
5.1.3
5.1.4
5.1.5
5.2.0
5.2.1
5.2.2
5.2.3
5.2.4
5.3.0
5.3.1
5.3.2
5.3.3

@raingloom
Copy link
Author

As someone who up until recently had terrible internet access, the extra download seems a bit overkill. What if the output of your script was cached into a file in /tmp?

@DhavalKapil
Copy link
Owner

Still, downloading all the source code doesn't look good. I prefer the Github tags method.

@umireon
Copy link
Contributor

umireon commented Dec 26, 2016

I admit the lua-all.tar.gz way is stupid and I think that is a bad way to implement.

I have presented it just because it is the most probale way to work in the future.
Recently, I found that the lua team currently does not have any public repo and the git repository may be closed (this is not likely to be happen, though).
And the design of https://www.lua.org/ftp/ have changed sometimes and thus will be.

@raingloom
Copy link
Author

raingloom commented Dec 27, 2016 via email

@umireon
Copy link
Contributor

umireon commented Jan 12, 2017

I think indicating to see downloading area on error is enough in interactive sessions.

$ luaver install 5
...
https://www.lua.org/ftp/lua-5.tar.gz was not found.
Please specify one of the versions listed on https://www.lua.org/ftp/

This feature will not be so useful in batch sessions (e.g. CI) because the release rate of lua, luajit and luarocks is slow.

@hishamhm
Copy link

hishamhm commented Mar 1, 2017

The repositories in https://github.com/lua are semi-official mirrors (they were "blessed" by Roberto to store the development history), and are well-maintained. They can be used to fetch Lua versions. Github repos for LuaRocks and LuaJIT are official, so tags can be fetched from those as well.

@umireon
Copy link
Contributor

umireon commented Apr 9, 2017

This feature requires the list of candidate remote versions and thus #42 may be helpful.

@astadmistry
Copy link

Easy way to download lastest lua rocks version:
luaver install-luarocks $(curl -sL https://api.github.com/repos/luarocks/luarocks/tags | jq -r '.[0].name' | cut -c 2-)

Linux dependency:
sudo apt install jq

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

5 participants