Skip to content

Commit

Permalink
feat: include ubi into mise directly (#2290)
Browse files Browse the repository at this point in the history
* Use ubi as a library instead of as a binary

* Move variable declaration to where it's used

* Support passing exe and matching args to ubi backend

* Remove unneeded boxing

* Fix issue found by clippy

* Import ubi

* Use a released version of ubi

* test: remove unnecessary test with baked-in ubi

* test: remove unnecessary test with baked-in ubi

* chore: ubi 0.2

* Fix incorrect comment

* Remove unused import in ubi backend code

* Update Cargo.lock

* fix: kept existing version of toml_edit

* fix: enable tokio timing for ubi

---------

Co-authored-by: Jeff Dickey <[email protected]>
  • Loading branch information
autarch and jdx authored Oct 13, 2024
1 parent 978ea1a commit 91810be
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 57 deletions.
98 changes: 98 additions & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ tokio = { version = "1.37.0", features = [
] }
toml = { version = "0.8", features = ["parse"] }
toml_edit = { version = "0.22", features = ["parse"] }
ubi = { version = "0.2", default-features = false }
url = "2.5.0"
# usage-lib = { path = "../usage/lib", features = ["clap", "docs"] }
usage-lib = { version = "0.10", features = ["clap", "docs"] }
Expand Down Expand Up @@ -160,9 +161,9 @@ test-log = "0.2"
[features]
default = ["native-tls"]
timings = []
native-tls = ["reqwest/native-tls"]
rustls = ["reqwest/rustls-tls", "self_update/rustls"]
rustls-native-roots = ["reqwest/rustls-tls-native-roots", "self_update/rustls"]
native-tls = ["reqwest/native-tls", "ubi/native-tls"]
rustls = ["reqwest/rustls-tls", "self_update/rustls", "ubi/rustls-tls"]
rustls-native-roots = ["reqwest/rustls-tls-native-roots", "self_update/rustls", "ubi/rustls-tls-native-roots"]

[package.metadata.binstall]
bin-dir = "mise/bin/mise"
Expand Down
9 changes: 0 additions & 9 deletions docs/dev-tools/backends/ubi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ You may install GitHub Releases and URL packages directly using [ubi](https://gi

The code for this is inside of the mise repository at [`./src/backend/ubi.rs`](https://github.com/jdx/mise/blob/main/src/backend/ubi.rs).

## Dependencies

This relies on having `ubi` installed. You can install it with or without mise.
Here is how to install `ubi-cli` with mise:

```sh
mise use -g cargo:ubi-cli
```

## Usage

The following installs the latest version of goreleaser
Expand Down
1 change: 0 additions & 1 deletion docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,6 @@ editLink: false
| typos | [asdf:aschiavon91/asdf-typos](https://github.com/aschiavon91/asdf-typos) |
| typst | [asdf:stephane-klein/asdf-typst](https://github.com/stephane-klein/asdf-typst) |
| uaa-cli | [asdf:vmware-tanzu/tanzu-plug-in-for-asdf](https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf) |
| ubi | [cargo:ubi-cli](https://crates.io/crates/ubi-cli) |
| unison | [asdf:susurri/asdf-unison](https://github.com/susurri/asdf-unison) |
| updatecli | [asdf:updatecli/asdf-updatecli](https://github.com/updatecli/asdf-updatecli) |
| upt | [asdf:ORCID/asdf-upt](https://github.com/ORCID/asdf-upt) |
Expand Down
2 changes: 0 additions & 2 deletions e2e/backend/test_ubi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env bash

curl -sSf -L https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh | TARGET="$HOME/bin" sh

assert "mise x ubi:goreleaser/[email protected] -- goreleaser -v | grep -o 1.25.0" "1.25.0"
20 changes: 0 additions & 20 deletions e2e/backend/test_ubi_token

This file was deleted.

49 changes: 28 additions & 21 deletions src/backend/ubi.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::fmt::Debug;

use eyre::eyre;
use ubi::UbiBuilder;

use crate::backend::{Backend, BackendType};
use crate::cache::{CacheManager, CacheManagerBuilder};
use crate::cli::args::BackendArg;
use crate::cmd::CmdLineRunner;
use crate::config::{Config, Settings, SETTINGS};
use crate::config::SETTINGS;
use crate::env::GITHUB_TOKEN;
use crate::github;
use crate::install_context::InstallContext;
Expand All @@ -17,7 +19,6 @@ pub struct UbiBackend {
}

// Uses ubi for installations https://github.com/houseabsolute/ubi
// it can be installed via mise install cargo:ubi-cli
impl Backend for UbiBackend {
fn get_type(&self) -> BackendType {
BackendType::Ubi
Expand All @@ -28,10 +29,9 @@ impl Backend for UbiBackend {
}

fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
Ok(vec!["ubi".into()])
Ok(vec![])
}

// TODO: v0.0.3 is stripped of 'v' such that it reports incorrectly in tool :-/
fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
if name_is_url(self.name()) {
Ok(vec!["latest".to_string()])
Expand All @@ -49,32 +49,39 @@ impl Backend for UbiBackend {
}

fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()> {
let config = Config::try_get()?;
let settings = Settings::get();
let version = &ctx.tv.version;
settings.ensure_experimental("ubi backend")?;
SETTINGS.ensure_experimental("ubi backend")?;
// Workaround because of not knowing how to pull out the value correctly without quoting
let path_with_bin = ctx.tv.install_path().join("bin");

let mut cmd = CmdLineRunner::new("ubi")
.arg("--in")
.arg(path_with_bin)
.arg("--project")
.arg(self.name())
.with_pr(ctx.pr.as_ref())
.envs(ctx.ts.env_with_path(&config)?)
.prepend_path(ctx.ts.list_paths())?
.prepend_path(self.dependency_toolset()?.list_paths())?;
let mut builder = UbiBuilder::new()
.project(self.name())
.install_dir(path_with_bin);

if let Some(token) = &*GITHUB_TOKEN {
cmd = cmd.env("GITHUB_TOKEN", token);
builder = builder.github_token(token);
}

let version = &ctx.tv.version;
if version != "latest" {
cmd = cmd.arg("--tag").arg(version);
builder = builder.tag(version);
}

cmd.execute()
let exe = std::env::var("MISE_TOOL_OPTS__EXE").unwrap_or_default();
if !exe.is_empty() {
builder = builder.exe(&exe);
}
let matching = std::env::var("MISE_TOOL_OPTS__MATCHING").unwrap_or_default();
if !matching.is_empty() {
builder = builder.matching(&matching);
}

let u = builder.build().map_err(|e| eyre!(e))?;

let rt = tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
.build()?;
rt.block_on(u.install_binary()).map_err(|e| eyre!(e))
}
}

Expand Down
1 change: 0 additions & 1 deletion src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use once_cell::sync::Lazy;
use std::collections::BTreeMap;

const _REGISTRY: &[(&str, &str)] = &[
("ubi", "cargo:ubi-cli"),
("cargo-binstall", "cargo:cargo-binstall"),
// ("elixir", "asdf:mise-plugins/mise-elixir"),
];
Expand Down

0 comments on commit 91810be

Please sign in to comment.