Skip to content

Commit

Permalink
Add sha256 checksum for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
yanecc committed Jun 8, 2024
1 parent 95d4998 commit 6850d43
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export GITHUB_URL=https://mirror.ghproxy.com/https://github.com/

## FAQ

- **Why is there a lack of updated versions?** <br>
- **Why is there a lack of updated versions?**<br>
To minimize the working requirements, vfox-ruby currently uses precompiled packages from conda-forge on Linux and macOS. You could open an issue in the [ruby-feedstock](https://github.com/conda-forge/ruby-feedstock/issues) repository to remind the maintainers to provide the latest build. Once the latest version is available, the plugin will be updated soon.

- **Are there any dependencies required to use this plugin?** <br>
- **Are there any dependencies required to use this plugin?**<br>
On Windows, vfox-ruby uses standalone 7-ZIP archives provided by [RubyInstaller](https://github.com/oneclick/rubyinstaller2/wiki/faq). On Linux and macOS, installing Ruby requires no dependencies other than the built-in commands. Installing TruffleRuby requires `bash`, `make`, `gcc`, `g++` and `zlib-dev`. For more details, refer to the [dependencies](https://github.com/oracle/truffleruby/blob/master/README.md#Dependencies) section.
6 changes: 3 additions & 3 deletions hooks/pre_install.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require("util")

function PLUGIN:PreInstall(ctx)
local file, version = getDownloadInfo(ctx.version)

local file, version, sha256 = getDownloadInfo(ctx.version)
return {
url = file,
version = version
version = version,
sha256 = sha256
}
end
52 changes: 32 additions & 20 deletions lib/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function fetchForWindows()
error("Failed to get information: " .. err .. "\nstatus_code => " .. resp.status_code)
end

for version in resp.body:gmatch('7z">Ruby (%d.%d.%d+)-1 %(x64%)') do
for version in resp.body:gmatch('7z">Ruby (%d.%d.%d+)%-1 %(x64%)') do
table.insert(versions, version)
end
sortVersions(versions)
Expand Down Expand Up @@ -140,48 +140,45 @@ end
-- pre_install.lua
function getDownloadInfo(version)
local file
local sha256
if version == "latest" then
version = getLatestVersion()
end
file = generateURL(version, RUNTIME.osType, RUNTIME.archType)
file, sha256 = generateURL(version, RUNTIME.osType, RUNTIME.archType)

return file, version
return file, version, sha256
end

function getLatestVersion()
local version
if RUNTIME.osType == "windows" then
version = getLatestVersionFromRubyInstaller()
local resp, err = http.get({
url = "https://rubyinstaller.org/downloads/",
})
if err ~= nil then
error("Failed to request: " .. err)
end
if resp.status_code ~= 200 then
error("Failed to get latest version: " .. err .. "\nstatus_code => " .. resp.status_code)
end
version = resp.body:match("Ruby (%d.%d.%d+)%-1 %(x64%)")
else
version = unixRubyVersions[1]
end

return version
end

function getLatestVersionFromRubyInstaller()
local resp, err = http.get({
url = "https://rubyinstaller.org/downloads/",
})
if err ~= nil then
error("Failed to request: " .. err)
end
if resp.status_code ~= 200 then
error("Failed to get latest version: " .. err .. "\nstatus_code => " .. resp.status_code)
end
local version = resp.body:match("Ruby (%d.%d.%d+)-1 %(x64%)")

return version
end

function generateURL(version, osType, archType)
local file
local sha256
local githubURL = os.getenv("GITHUB_URL") or "https://github.com/"
if osType == "windows" then
local bit = archType == "amd64" and "64" or "86"
file = githubURL:gsub("/$", "")
.. "/oneclick/rubyinstaller2/releases/download/RubyInstaller-%s-1/rubyinstaller-%s-1-x%s.7z"
file = file:format(version, version, bit)
sha256 = getSha256ForWindows(version, bit)
elseif osType ~= "darwin" and osType ~= "linux" then
print("Unsupported OS: " .. osType)
os.exit(1)
Expand All @@ -192,7 +189,22 @@ function generateURL(version, osType, archType)
file = generateTruffleRuby(version, osType, archType)
end

return file
return file, sha256
end

function getSha256ForWindows(version, bit)
local resp, err = http.get({
url = "https://rubyinstaller.org/downloads/archives/",
})
if err ~= nil then
error("Failed to request: " .. err)
end
if resp.status_code ~= 200 then
error("Failed to get sha256: " .. err .. "\nstatus_code => " .. resp.status_code)
end
local sha256 = resp.body:match("rubyinstaller%-" .. version .. "%-1%-x" .. bit .. '.7z[%s%S]-value="([0-9a-z]+)')

return sha256
end

function hasValue(table, value)
Expand Down
2 changes: 1 addition & 1 deletion metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PLUGIN = {}
--- Plugin name
PLUGIN.name = "ruby"
--- Plugin version
PLUGIN.version = "0.3.2"
PLUGIN.version = "0.3.3"
--- Plugin homepage
PLUGIN.homepage = "https://github.com/yanecc/vfox-ruby"
--- Plugin license, please choose a correct license according to your needs.
Expand Down

0 comments on commit 6850d43

Please sign in to comment.