diff --git a/src/bot/botutils.jl b/src/bot/botutils.jl index 33ec50be6..00e37eeaa 100644 --- a/src/bot/botutils.jl +++ b/src/bot/botutils.jl @@ -280,3 +280,35 @@ julia> VersionFloat(v"1.4.2") ``` """ VersionFloat(v::VersionNumber) = join(split(string(v),'.')[1:2],'.') + +# https://github.com/JuliaLang/julia/pull/36223: +""" + JuliaVersionNumber(v::String) + JuliaVersionNumber(v::VersionNumber) +returns the Julia version number by following the same specifications as VersionNumber. +`JuliaVersionNumber` will fetch the latest nightly version number if `"nightly"` or `"latest"` is given as the input. +# Examples +```julia +julia> JuliaVersionNumber("nightly") +v"1.6.0-DEV" +``` +```jldoctest +julia> JuliaVersionNumber("1.2.3") +v"1.2.3" +julia> JuliaVersionNumber(v"1.2.3") +v"1.2.3" +``` +""" +JuliaVersionNumber(v::VersionNumber) = v +function JuliaVersionNumber(v::String) + if in(v, ["nightly", "latest"]) + version_path = download( + "https://raw.githubusercontent.com/JuliaLang/julia/master/VERSION", + joinpath(tempdir(), "VERSION.txt"), + ) + version_str = replace(Base.read(version_path, String), "\n" => "") + return VersionNumber(version_str) + else + return VersionNumber(v) + end +end diff --git a/test/bot/bot.jl b/test/bot/bot.jl index e4da1b16b..b6470e09f 100644 --- a/test/bot/bot.jl +++ b/test/bot/bot.jl @@ -421,3 +421,5 @@ bottestdir = GoodPath(@__DIR__) # just in case cd(snoopcompiledir) end + +include("bot/botutils.jl") diff --git a/test/bot/botutils.jl b/test/bot/botutils.jl new file mode 100644 index 000000000..288069cf5 --- /dev/null +++ b/test/bot/botutils.jl @@ -0,0 +1,8 @@ +# JuliaVersionNumber + +# https://github.com/JuliaLang/julia/pull/36223: +# @test JuliaVersionNumber("nightly") == + # VersionNumber(replace(Base.read("VERSION", String), "\n" => "")) +# @test thispatch(JuliaVersionNumber("nightly")) == thispatch(VERSION) +@test JuliaVersionNumber("1.2.3") == v"1.2.3" +@test JuliaVersionNumber(v"1.2.3") == v"1.2.3"