diff options
| author | William Boman <william@redwill.se> | 2023-04-12 19:32:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-12 19:32:43 +0200 |
| commit | df4bf38688c31056d222e68aa9f26e3c51090a97 (patch) | |
| tree | f55891f022556599a43044ce1de28e6814082611 | |
| parent | chore: autogenerate (#1206) (diff) | |
| download | mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.gz mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.bz2 mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.lz mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.xz mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.zst mason-df4bf38688c31056d222e68aa9f26e3c51090a97.zip | |
fix(github): use evaluated out_file as asset file value (#1208)
This makes it so that after parsing the source, the `{{source.asset.file}}` context value points to the downloaded file,
rather than the raw value. This is helpful for source definitions such as:
```yaml
source:
id: pkg:github/mrjosh/helm-ls@v0.0.3
asset:
- target: win_x64
file: helm_ls_windows_amd64:helm_ls_windows_amd64.exe
# …
bin:
# This now evaluates to "helm_ls_windows_amd64.exe" rather than "helm_ls_windows_amd64:helm_ls_windows_amd64.exe".
helm_ls: "{{source.asset.file}}"
```
| -rw-r--r-- | lua/mason-core/installer/registry/providers/github.lua | 52 | ||||
| -rw-r--r-- | tests/mason-core/installer/registry/providers/github_spec.lua | 64 |
2 files changed, 101 insertions, 15 deletions
diff --git a/lua/mason-core/installer/registry/providers/github.lua b/lua/mason-core/installer/registry/providers/github.lua index 06ac0b06..243f021d 100644 --- a/lua/mason-core/installer/registry/providers/github.lua +++ b/lua/mason-core/installer/registry/providers/github.lua @@ -68,27 +68,51 @@ local release = { ---@type { out_file: string, download_url: string }[] local downloads = {} - for __, file in ipairs(type(asset.file) == "string" and { asset.file } or asset.file) do - local asset_file_components = _.split(":", file) - local source_file = try(expr.interpolate(_.head(asset_file_components), expr_ctx)) - local out_file = try(expr.interpolate(_.last(asset_file_components), expr_ctx)) + local interpolated_asset = try(expr.tbl_interpolate(asset, expr_ctx)) - if _.matches("/$", out_file) then - -- out_file is a dir expression (e.g. "libexec/") - out_file = out_file .. source_file - end + ---@param file string + ---@return Result # Result<{ source_file: string, out_file: string }> + local function parse_asset_file(file) + return Result.try(function(try) + local asset_file_components = _.split(":", file) + local source_file = try(expr.interpolate(_.head(asset_file_components), expr_ctx)) + local out_file = try(expr.interpolate(_.last(asset_file_components), expr_ctx)) + + if _.matches("/$", out_file) then + -- out_file is a dir expression (e.g. "libexec/") + out_file = out_file .. source_file + end + + return { + source_file = source_file, + out_file = out_file, + } + end) + end - table.insert(downloads, { - out_file = out_file, + local get_downloads = _.map(function(asset_file) + return { + out_file = asset_file.out_file, download_url = settings.current.github.download_url_template:format( ("%s/%s"):format(purl.namespace, purl.name), purl.version, - source_file + asset_file.source_file ), - }) - end + } + end) - local interpolated_asset = try(expr.tbl_interpolate(asset, expr_ctx)) + if type(asset.file) == "string" then + local parsed_asset_file = try(parse_asset_file(asset.file)) + downloads = get_downloads { parsed_asset_file } + interpolated_asset.file = parsed_asset_file.out_file + else + local parsed_asset_files = {} + for _, file in ipairs(asset.file) do + table.insert(parsed_asset_files, try(parse_asset_file(file))) + end + downloads = get_downloads(parsed_asset_files) + interpolated_asset.file = _.map(_.prop "out_file", parsed_asset_files) + end ---@class ParsedGitHubReleaseSource : ParsedPackageSource local parsed_source = { diff --git a/tests/mason-core/installer/registry/providers/github_spec.lua b/tests/mason-core/installer/registry/providers/github_spec.lua index de301d88..c70e0b10 100644 --- a/tests/mason-core/installer/registry/providers/github_spec.lua +++ b/tests/mason-core/installer/registry/providers/github_spec.lua @@ -75,7 +75,7 @@ describe("github provider :: parsing", function() Result.success { repo = "namespace/name", asset = { - file = "file-linux-amd64-2023-03-09.tar.gz:out-dir/", + file = "out-dir/file-linux-amd64-2023-03-09.tar.gz", }, downloads = { { @@ -92,6 +92,68 @@ describe("github provider :: parsing", function() ) end) + it("should expand returned asset.file to point to out_file", function() + assert.same( + Result.success { + repo = "namespace/name", + asset = { + file = { + "out-dir/linux-amd64-2023-03-09.tar.gz", + "LICENSE.txt", + "README.md", + }, + }, + downloads = { + { + out_file = "out-dir/linux-amd64-2023-03-09.tar.gz", + download_url = "https://github.com/namespace/name/releases/download/2023-03-09/linux-amd64-2023-03-09.tar.gz", + }, + { + out_file = "LICENSE.txt", + download_url = "https://github.com/namespace/name/releases/download/2023-03-09/license", + }, + { + out_file = "README.md", + download_url = "https://github.com/namespace/name/releases/download/2023-03-09/README.md", + }, + }, + }, + github.parse({ + asset = { + file = { + "linux-amd64-{{version}}.tar.gz:out-dir/", + "license:LICENSE.txt", + "README.md", + }, + }, + }, purl(), { target = "linux_x64" }) + ) + end) + + it("should interpolate asset table", function() + assert.same( + Result.success { + repo = "namespace/name", + asset = { + file = "linux-amd64-2023-03-09.tar.gz", + bin = "linux-amd64-2023-03-09", + }, + downloads = { + { + out_file = "linux-amd64-2023-03-09.tar.gz", + download_url = "https://github.com/namespace/name/releases/download/2023-03-09/linux-amd64-2023-03-09.tar.gz", + }, + }, + }, + github.parse({ + asset = { + file = "linux-amd64-{{version}}.tar.gz", + bin = "linux-amd64-{{version}}", + }, + }, purl(), { target = "linux_x64" }) + ) + end) + it("should parse build source", function() assert.same( Result.success { |
