Skip to content

Commit

Permalink
feat: upgrade ubi (#4078)
Browse files Browse the repository at this point in the history
* feat: upgrade ubi

* added extract_all option for ubi

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
jdx and autofix-ci[bot] authored Jan 15, 2025
1 parent fcbe2c4 commit cad188c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ thiserror = "2"
tokio = { version = "1", features = ["io-std", "rt", "time"] }
toml = { version = "0.8", features = ["parse"] }
toml_edit = { version = "0.22", features = ["parse"] }
ubi = { version = "0.3", default-features = false }
ubi = { version = "0.4", default-features = false }
url = "2"
usage-lib = { version = "2", features = ["clap", "docs"] }
versions = { version = "6", features = ["serde"] }
Expand Down
33 changes: 32 additions & 1 deletion docs/dev-tools/backends/ubi.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,38 @@ then this will be ignored.

```toml
[tools]
"ubi:BurntSushi/ripgrep" = { matching = "musl" }
"ubi:BurntSushi/ripgrep" = { version = "latest", matching = "musl" }
```

### `extract_all`

Set to `true` to extract all files in the tarball instead of just the "bin". Not compatible with `exe`.

```toml
[tools]
"ubi:helix-editor/helix" = { version = "latest", extract_all = "true" }
```

### `bin_path`

The directory in the tarball where the binary(s) are located. This is useful when the binary is not in the root of the tarball.
This only makes sense when `extract_all` is set to `true`.

```toml
[tools]
"ubi:BurntSushi/ripgrep" = { version = "latest", extract_all = "true", bin_path = "target/release" }
```

### `tag_regex`

Set a regex to filter out tags that don't match the regex. This is useful when a vendor has a bunch of
releases for unrelated CLIs in the same repo. For example, `cargo-bins/cargo-binstall` has a bunch of
releases for unrelated CLIs that are not `cargo-binstall`. This option can be used to filter out those
releases.

```toml
[tools]
"ubi:cargo-bins/cargo-binstall" = { version = "latest", tag_regex = "^\d+\." }
```

## Supported Ubi Syntax
Expand Down
1 change: 1 addition & 0 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ You can also specify the full name for a tool using `mise use aqua:1password/cli
| haxe | [asdf:mise-plugins/mise-haxe](https://github.com/mise-plugins/mise-haxe) |
| hcl2json | [aqua:tmccombs/hcl2json](https://github.com/tmccombs/hcl2json) [asdf:dex4er/asdf-hcl2json](https://github.com/dex4er/asdf-hcl2json) |
| hcloud | [aqua:hetznercloud/cli](https://github.com/hetznercloud/cli) [asdf:chessmango/asdf-hcloud](https://github.com/chessmango/asdf-hcloud) |
| helix | [ubi:helix-editor/helix](https://github.com/helix-editor/helix) |
| helm | [aqua:helm/helm](https://github.com/helm/helm) [asdf:Antiarchitect/asdf-helm](https://github.com/Antiarchitect/asdf-helm) |
| helm-cr | [aqua:helm/chart-releaser](https://github.com/helm/chart-releaser) [asdf:Antiarchitect/asdf-helm-cr](https://github.com/Antiarchitect/asdf-helm-cr) |
| helm-ct | [aqua:helm/chart-testing](https://github.com/helm/chart-testing) [asdf:tablexi/asdf-helm-ct](https://github.com/tablexi/asdf-helm-ct) |
Expand Down
1 change: 1 addition & 0 deletions registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ hasura-cli.backends = [
haxe.backends = ["asdf:mise-plugins/mise-haxe"]
hcl2json.backends = ["aqua:tmccombs/hcl2json", "asdf:dex4er/asdf-hcl2json"]
hcloud.backends = ["aqua:hetznercloud/cli", "asdf:chessmango/asdf-hcloud"]
helix.backends = ["ubi:helix-editor/helix[extract_all=true]"]
helm.backends = ["aqua:helm/helm", "asdf:Antiarchitect/asdf-helm"]
helm-cr.backends = [
"aqua:helm/chart-releaser",
Expand Down
30 changes: 23 additions & 7 deletions src/backend/ubi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ impl Backend for UbiBackend {
mut tv: ToolVersion,
) -> eyre::Result<ToolVersion> {
let mut v = tv.version.to_string();
let opts = tv.request.options();
let extract_all = opts.get("extract_all").is_some_and(|v| v == "true");
let bin_dir = tv.install_path();

if let Err(err) = github::get_release(&self.tool_name(), &tv.version) {
// this can fail with a rate limit error or 404, either way, try prefixing and if it fails, try without the prefix
Expand All @@ -86,14 +89,10 @@ impl Backend for UbiBackend {
}

let install = |v: &str| {
let opts = tv.request.options();
// Workaround because of not knowing how to pull out the value correctly without quoting
let path_with_bin = tv.install_path().join("bin");
let name = self.tool_name();

let mut builder = UbiBuilder::new()
.project(&name)
.install_dir(path_with_bin.clone());
let mut builder = UbiBuilder::new().project(&name).install_dir(&bin_dir);

if let Some(token) = &*GITHUB_TOKEN {
builder = builder.github_token(token);
Expand All @@ -103,7 +102,9 @@ impl Backend for UbiBackend {
builder = builder.tag(v);
}

if let Some(exe) = opts.get("exe") {
if extract_all {
builder = builder.extract_all();
} else if let Some(exe) = opts.get("exe") {
builder = builder.exe(exe);
}
if let Some(matching) = opts.get("matching") {
Expand All @@ -127,7 +128,6 @@ impl Backend for UbiBackend {
})
})?;

let bin_dir = tv.install_path().join("bin");
let mut possible_exes = vec![tv
.request
.options()
Expand Down Expand Up @@ -210,6 +210,22 @@ impl Backend for UbiBackend {
}
Ok(())
}

fn list_bin_paths(&self, tv: &ToolVersion) -> eyre::Result<Vec<std::path::PathBuf>> {
let opts = tv.request.options();
if let Some(bin_path) = opts.get("bin_path") {
Ok(vec![tv.install_path().join(bin_path)])
} else if opts.get("extract_all").is_some_and(|v| v == "true") {
Ok(vec![tv.install_path()])
} else {
let bin_path = tv.install_path().join("bin");
if bin_path.exists() {
Ok(vec![bin_path])
} else {
Ok(vec![tv.install_path()])
}
}
}
}

impl UbiBackend {
Expand Down

0 comments on commit cad188c

Please sign in to comment.