Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: go backend can't install tools without 'v' prefix in git repo tags #2606

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/backend/go.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::fmt::Debug;

use eyre::bail;

use crate::backend::{Backend, BackendType};
use crate::cache::CacheManager;
use crate::cli::args::BackendArg;
Expand Down Expand Up @@ -63,21 +65,24 @@ impl Backend for GoBackend {
let settings = Settings::get();
settings.ensure_experimental("go backend")?;

// if the (semantic) version has no v prefix, add it
// we allow max. 6 digits for the major version to prevent clashes with Git commit hashes
let version = if regex!(r"^\d{1,6}(\.\d+)*([+-.].+)?$").is_match(&ctx.tv.version) {
format!("v{}", ctx.tv.version)
} else {
ctx.tv.version.clone()
if ctx.tv.version.starts_with("v") {
bail!("versions should not start with a 'v', please remove it");
}

let install = |v| {
CmdLineRunner::new("go")
.arg("install")
.arg(format!("{}@{v}", self.name()))
.with_pr(ctx.pr.as_ref())
.envs(self.dependency_env()?)
.env("GOBIN", ctx.tv.install_path().join("bin"))
.execute()
};

CmdLineRunner::new("go")
.arg("install")
.arg(format!("{}@{}", self.name(), version))
.with_pr(ctx.pr.as_ref())
.envs(self.dependency_env()?)
.env("GOBIN", ctx.tv.install_path().join("bin"))
.execute()?;
if install(ctx.tv.version.to_string()).is_err() {
warn!("Failed to install, trying again without added 'v' prefix");
install(format!("v{}", &ctx.tv.version))?;
}

Ok(())
}
Expand Down
Loading