Skip to content

Commit

Permalink
Use ubi as a library instead of as a binary
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Jun 15, 2024
1 parent f01cc8d commit d794d4c
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 32 deletions.
327 changes: 325 additions & 2 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ which = "6.0.1"
xx = { version = "1.0.0", features = ["glob"] }
zip = { version = "2", default-features = false, features = ["deflate"] }

ubi = { git = "https://github.com/houseabsolute/ubi.git", branch = "library-ize" }

[target.'cfg(unix)'.dependencies]
exec = "0.3.1"

Expand Down
1 change: 0 additions & 1 deletion docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,6 @@ Examples:
$ mise registry
node core:node
poetry asdf:mise-plugins/mise-poetry
ubi cargo:ubi
```

## `mise reshim`
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` with mise:

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

## Usage

The following installs the latest version of goreleaser
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"
1 change: 0 additions & 1 deletion mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ cmd "registry" help="[experimental] List available tools" {
$ mise registry
node core:node
poetry asdf:mise-plugins/mise-poetry
ubi cargo:ubi
"
}
cmd "reshim" help="rebuilds the shim farm" {
Expand Down
32 changes: 16 additions & 16 deletions src/backend/ubi.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::fmt::Debug;

use eyre::eyre;

use crate::backend::{Backend, BackendType};
use crate::cache::CacheManager;
use crate::cli::args::BackendArg;
use crate::cmd::CmdLineRunner;
use crate::config::{Config, Settings};
use crate::config::Settings;
use crate::env::GITHUB_TOKEN;
use crate::github;
use crate::install_context::InstallContext;
Expand All @@ -28,10 +29,9 @@ impl Backend for UbiBackend {
}

fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
Ok(vec!["cargo: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,31 +49,31 @@ 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")?;
// 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())?;
let mut builder = ubi::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);
}

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

cmd.execute()
let u = builder.build().map_err(|e| eyre!(Box::new(e)))?;

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

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

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

0 comments on commit d794d4c

Please sign in to comment.