jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
8.84k stars 238 forks source link

`mise use go:pkg` sometimes fails when `go install pkg` does not #1667

Closed sgtsquiggs closed 6 months ago

sgtsquiggs commented 6 months ago

Describe the bug mise use go:github.com/digitalocean/gta/cmd/gta@a677131 fails yet go install go:github.com/digitalocean/gta/cmd/gta@a677131 does not.

To Reproduce

❯ GOPROXY=direct mise use go:github.com/digitalocean/gta/cmd/gta@a677131 --verbose
[DEBUG] ARGS: /Users/mcrenshaw/.local/bin/mise use go:github.com/digitalocean/gta/cmd/gta@a677131 --verbose
[DEBUG] Config {
    Config Files: [
        "~/fleet/src/daedalus/.mise.toml",
        "~/fleet/src/daedalus/.rtx.toml",
        "~/.config/mise/config.toml",
    ],
}
[DEBUG] Toolset: go@1.21, python@3.10, node@lts-hydrogen, pnpm@8, just@1.14.0, poetry@1.4.2, sqlc@1.21.0, golangci-lint@1.54.2, go:github.com/sgtsquiggs/tools/cmd/structtagger@v0.0.3, go:go.uber.org/mock/mockgen@v0.4.0, go:github.com/vektra/mockery/v2@v2.17.0, buf@latest, java@corretto-17, k9s@0.27.4, kubectl@1.28.1, kubefwd@1.22.4, pre-commit@2.21.0, rust@1.69.0, teleport@11.3.11, tilt@0.33.1, direnv@latest, yq@latest, pipx@latest
[DEBUG] $ go list -m -versions -json github.com/digitalocean/gta/cmd/gta
[DEBUG] $ go list -m -versions -json github.com/digitalocean/gta/cmd
[DEBUG] $ go list -m -versions -json github.com/digitalocean/gta
[DEBUG] $ go list -m -versions -json github.com/digitalocean
go: invalid github.com import path "github.com/digitalocean"
Error: 
   0: command ["go", "list", "-m", "-versions", "-json", "github.com/digitalocean"] exited with code 1

Location:
   src/forge/go.rs:33

Version:
   2024.2.6 macos-arm64 (adfcc0d 2024-02-07)

Expected behavior It should install. I can install it via go install:

❯ go install github.com/digitalocean/gta/cmd/gta@a677131
go: downloading github.com/digitalocean/gta v0.0.0-20240212201420-a6771315aa20
go: downloading golang.org/x/crypto v0.13.0
go: downloading golang.org/x/tools v0.13.0
go: downloading golang.org/x/term v0.12.0
go: downloading golang.org/x/sys v0.12.0
go: downloading golang.org/x/mod v0.12.0

mise doctor output

mise version:
  2024.2.6 macos-arm64 (adfcc0d 2024-02-07)

build:
  Target: aarch64-apple-darwin
  Features: DEFAULT, NATIVE_TLS, OPENSSL
  Built: Wed, 7 Feb 2024 15:35:01 +0000
  Rust Version: rustc 1.75.0 (82e1608df 2023-12-21)
  Profile: release

shell:
  /opt/homebrew/bin/fish
  fish, version 3.6.1

mise dirs:
  data: /Users/mcrenshaw/.local/share/mise
  config: /Users/mcrenshaw/.config/mise
  cache: /Users/mcrenshaw/Library/Caches/mise
  state: /Users/mcrenshaw/.local/state/mise
  shims: /Users/mcrenshaw/.local/share/mise/shims

mise environment variables:
  MISE_SHELL=fish

settings:
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf_compat = true
  cargo_binstall = true
  color = true
  disable_default_shorthands = false
  disable_tools = []
  experimental = true
  jobs = 4
  legacy_version_file = true
  legacy_version_file_disable_tools = []
  node_compile = false
  not_found_auto_install = true
  paranoid = false
  plugin_autoupdate_last_check_duration = "1 week"
  python_compile = false
  python_default_packages_file = "/Users/mcrenshaw/.default-python-packages"
  python_pyenv_repo = "https://github.com/pyenv/pyenv.git"
  python_venv_auto_create = false
  raw = false
  trusted_config_paths = ["~/fleet"]
  quiet = false
  verbose = false
  yes = false
  ci = false
  debug = false
  trace = false
  log_level = "info"

  [status]
  missing_tools = "if_other_versions_installed"
  show_env = false
  show_tools = false

activated: yes
shims_on_path: no
config files:
  ~/.config/mise/config.toml
  ~/fleet/src/daedalus/.rtx.toml
  ~/fleet/src/daedalus/.mise.toml

plugins:
  buf             https://github.com/truepay/asdf-buf.git#6c27312
  bun             (core)
  deno            (core)
  direnv          https://github.com/asdf-community/asdf-direnv.git#a2219c2
  erlang          (core)
  go              (core)
  golangci-lint   https://github.com/hypnoglow/asdf-golangci-lint.git#fee877b
  java            (core)
  just            https://github.com/olofvndrhr/asdf-just.git#93771e1
  k9s             https://github.com/looztra/asdf-k9s.git#2b3af87
  kubectl         https://github.com/asdf-community/asdf-kubectl.git#cbe6df4
  kubefwd         https://github.com/nklmilojevic/asdf-kubefwd.git#f341a66
  node            (core)
  pipx            https://github.com/yozachar/asdf-pipx.git#81cb547
  pnpm            https://github.com/jonathanmorley/asdf-pnpm.git#305baff
  poetry          https://github.com/rtx-plugins/rtx-poetry.git#82d11e3
  pre-commit      https://github.com/jonathanmorley/asdf-pre-commit.git#26bfc42
  python          (core)
  ruby            (core)
  rust            https://github.com/code-lever/asdf-rust.git#95acf4f
  sqlc            https://github.com/schmir/asdf-sqlc.git#9ad97b1
  teleport        https://github.com/gozer/asdf-teleport.git#7900506
  tilt            https://github.com/eaceaser/asdf-tilt.git#69eac7b
  yq              https://github.com/sudermanjr/asdf-yq.git#772992f

toolset:
  go@1.21, python@3.10, node@lts-hydrogen, pnpm@8, just@1.14.0, poetry@1.4.2, sqlc@1.21.0, golangci-lint@1.54.2, go:github.com/sgtsquiggs/tools/cmd/structtagger@v0.0.3, go:go.uber.org/mock/mockgen@v0.4.0, go:github.com/vektra/mockery/v2@v2.17.0, buf@latest, java@corretto-17, k9s@0.27.4, kubectl@1.28.1, kubefwd@1.22.4, pre-commit@2.21.0, rust@1.69.0, teleport@11.3.11, tilt@0.33.1, direnv@latest, yq@latest, pipx@latest

2 problems found:
shims are missing, run mise reshim to create them
Missing shims: gta

new mise version 2024.2.14 available, currently on 2024.2.6

Additional context Add any other context about the problem here.

Ajpantuso commented 6 months ago

The issue is that https://github.com/digitalocean/gta has no tagged versions. The failure however is a little confusing since you can install from SHA, which is not a true version, as long as there is at least one tagged version of the module.

@endigma I can make this work by returning empty vecs on errors, but not really sure if that would just create silent failures for other scenarios.

    fn list_remote_versions(&self) -> eyre::Result<Vec<String>> {
        self.remote_version_cache
            .get_or_try_init(|| {
                let mut mod_path = Some(self.name());

                while let Some(cur_mod_path) = mod_path {
                    match cmd!("go", "list", "-m", "-versions", "-json", cur_mod_path).read() {
                        Ok(raw) => {
                            let result = serde_json::from_str::<GoModInfo>(&raw);
                            if let Ok(mod_info) = result {
                                return Ok(mod_info.versions);
                            }

                            mod_path = trim_after_last_slash(cur_mod_path);
                        },
                        Err(_) => return Ok(vec![]),
                    }
                }

                Ok(vec![])
                // Err(eyre!("couldn't find module versions"))
            })
            .cloned()
    }
endigma commented 6 months ago

It would be best if we could somehow get a fuller list of valid versions, including git shas, or maybe just regex for a git sha and accept that fast? idk how that would work with updater code though, haven't looked at it.

@jdx does update code just pick the first version in the vec or could it potentially be split into some sort of channels thing? ("git" vs "release" ? this could affect npm as well)

sgtsquiggs commented 6 months ago

Perhaps just need to support the ref:sha syntax? Or is it supported if there is at least one version available?

Ajpantuso commented 6 months ago

Perhaps just need to support the ref:sha syntax? Or is it supported if there is at least one version available?

@SHA worked when I tested it on a module with at least one tagged version.

The trick with supporting SHAs as part of building upgrade paths IMO is that commit logs are not linear in the sense that they branch and form ancestry trees rather than an ordered sequence. From a modeling standpoint I think refs would just have to be treated as terminal versions and upgrading would force you back on the properly versioned edge.

endigma commented 6 months ago

That's true in some sense, but "git" as a version pretty commonly means HEAD of the main branch, and that series of shas can be interpreted as a version list in some sense. Although force pushes could be evil here. (unless this just works by "upgrading" to the latest HEAD no matter where it is in relation to the previous HEAD? Is this how aur -git packages work? Those seem to be fine)

A short-term solution here short of different "channels" of versions for any given package in the forge impl would be to add some sort of regex to shortcut the go "valid version checker" with a regex for a git sha. The only actual usability issue here at the moment is that mise expects a valid version list from every installable thing, not just go packages. We could just do what @Ajpantuso wrote above and return an empty vec instead of Err, as a patch. go install will fail for any invalid version using its own internal checking code anyway.

sgtsquiggs commented 6 months ago

My expectations were that using a sha completely bypasses any versioning. This is really an edge case - most go tools would have a version. I forked this repo and versioned it to make it work with mise 🤷‍♂️

This isn’t a strong ask, just bad assumption (on my part)

Ajpantuso commented 6 months ago

Yeah, my intuition is that a SHA version should be treated as if it was outside the versioned upgrade path and upgrade logic would only "upgrade" by bringing the version back to the latest available which could very well be an ancestor from a commit log point of view.

endigma commented 6 months ago

You can probably PR the empty vec solution, at least as a bandaid. Usable > perfect for now