Skip to content

Commit

Permalink
fix: add backend to lockfile (#3535)
Browse files Browse the repository at this point in the history
Fixes #3339
  • Loading branch information
jdx authored Dec 14, 2024
1 parent 9cf3c1c commit b13f27e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 8 deletions.
8 changes: 6 additions & 2 deletions e2e/cli/test_use_latest
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ touch mise.lock
assert "mise use dummy@1 tiny@1"
assert "cat mise.lock" '[tools.dummy]
version = "1.0.0"
backend = "asdf:dummy"
[tools.tiny]
version = "1.0.0"'
version = "1.0.0"
backend = "asdf:tiny"'
assert "mise tool dummy --requested" "1"
assert "mise tool tiny --requested" "1"
assert "mise tool dummy --active" "1.0.0"
Expand All @@ -29,9 +31,11 @@ assert "mise tool tiny --active" "1.0.0"
assert "mise use dummy@latest"
assert "cat mise.lock" '[tools.dummy]
version = "2.0.0"
backend = "asdf:dummy"
[tools.tiny]
version = "1.0.0"'
version = "1.0.0"
backend = "asdf:tiny"'
assert "mise tool dummy --requested" "latest"
assert "mise tool tiny --requested" "1"
assert "mise tool dummy --active" "2.0.0"
Expand Down
16 changes: 16 additions & 0 deletions e2e/lockfile/test_lockfile_backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

export MISE_LOCKFILE=1
export MISE_EXPERIMENTAL=1

assert "mise tool gh --backend" "aqua:cli/cli"
cat <<EOF >mise.toml
[tools.gh]
version = "1.0.0"
EOF
cat <<EOF >mise.lock
[tools.gh]
version = "1.0.0"
backend = "ubi:cli/cli[exe=gh]"
EOF
assert "mise tool gh --backend" "ubi:cli/cli[exe=gh]"
16 changes: 11 additions & 5 deletions e2e/lockfile/test_lockfile_use
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,39 @@ assert "mise where tiny" "$MISE_DATA_DIR/installs/tiny/1.0.0"
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1"
assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.0.0"
assert "cat mise.lock" '[tools.tiny]
version = "1.0.0"'
version = "1.0.0"
backend = "asdf:tiny"'

assert "mise use tiny@1"
assert "cat mise.lock" '[tools.tiny]
version = "1.0.0"'
version = "1.0.0"
backend = "asdf:tiny"'
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1"
assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.0.0"

assert "mise up tiny"
assert "cat mise.lock" '[tools.tiny]
version = "1.1.0"'
version = "1.1.0"
backend = "asdf:tiny"'
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1"
assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.1.0"

assert "mise up tiny --bump"
assert "cat mise.lock" '[tools.tiny]
version = "3.1.0"'
version = "3.1.0"
backend = "asdf:tiny"'
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "3"
assert "mise ls tiny --json --current | jq -r '.[0].version'" "3.1.0"

echo 'tools.tiny = "1.0.0"' >mise.lock
assert "mise use tiny@1 tiny@2"
assert "cat mise.lock" '[[tools.tiny]]
version = "1.0.0"
backend = "asdf:tiny"
[[tools.tiny]]
version = "2.1.0"'
version = "2.1.0"
backend = "asdf:tiny"'
assert "mise uninstall --all tiny"
assert "mise install tiny"
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1"
Expand Down
19 changes: 19 additions & 0 deletions mise.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tools.actionlint]
version = "1.7.4"
backend = "ubi:rhysd/actionlint"

[tools.actionlint.checksums]
actionlint-linux-x86_64 = "sha256:39cae525cdb54af5d91dcf27f55e040d37ecea01dd4153490c4dc84f5d251d46"
Expand All @@ -8,35 +9,43 @@ actionlint-macos-aarch64 = "sha256:f381afca13b39e095e4cee25e2b2abbb39ae8b2848f5c

[tools.bun]
version = "1.1.38"
backend = "core:bun"

[tools.bun.checksums]
"bun-darwin-aarch64.zip" = "sha256:bbc6fb0e7bb99e7e95001ba05105cf09d0b79c06941d9f6ee3d0b34dc1541590"
"bun-linux-x64-baseline.zip" = "sha256:353e2e6d4086a09eeee984d2ed61736dcd905838ede51b82689fd7b3e95def90"

[tools.cargo-binstall]
version = "1.10.15"
backend = "aqua:cargo-bins/cargo-binstall"

[tools.cargo-binstall.checksums]
"cargo-binstall-aarch64-apple-darwin.zip" = "sha256:0afb56acd834d7b0bc9a5293963da04abe48923d90f374bed98068b313a48f2c"
"cargo-binstall-x86_64-unknown-linux-musl.tgz" = "sha256:f333f552699e76e8fe570da6fb928c273c0c2d14e0955f6b79f7f59eb932ba73"

[tools."cargo:cargo-edit"]
version = "0.13.0"
backend = "cargo:cargo-edit"

[tools."cargo:cargo-insta"]
version = "1.41.1"
backend = "cargo:cargo-insta"

[tools."cargo:cargo-show"]
version = "0.6.0"
backend = "cargo:cargo-show"

[tools."cargo:git-cliff"]
version = "2.7.0"
backend = "cargo:git-cliff"

[tools."cargo:usage-cli"]
version = "1.5.2"
backend = "cargo:usage-cli"

[tools.cosign]
version = "2.4.1"
backend = "aqua:sigstore/cosign"

[tools.cosign.checksums]
cosign-darwin-arm64 = "sha256:13343856b69f70388c4fe0b986a31dde5958e444b41be22d785d3dc5e1a9cc62"
Expand All @@ -45,6 +54,7 @@ cosign-linux-amd64 = "sha256:8b24b946dd5809c6bd93de08033bcf6bc0ed7d336b7785787c0

[tools.jq]
version = "1.7.1"
backend = "aqua:jqlang/jq"

[tools.jq.checksums]
jq-linux-amd64 = "sha256:5942c9b0934e510ee61eb3e30273f1b3fe2590df93933a93d7c58b81d19c8ff5"
Expand All @@ -53,21 +63,26 @@ jq-macos-arm64 = "sha256:0bbe619e663e0de2c550be2fe0d240d076799d6f8a652b70fa04aea

[tools."npm:markdownlint-cli"]
version = "0.43.0"
backend = "npm:markdownlint-cli"

[tools."npm:prettier"]
version = "3.4.2"
backend = "npm:prettier"

[tools."pipx:toml-sort"]
version = "0.24.2"
backend = "pipx:toml-sort"

[tools.pre-commit]
version = "4.0.1"
backend = "aqua:pre-commit/pre-commit"

[tools.pre-commit.checksums]
"pre-commit-4.0.1.pyz" = "sha256:f3e65c943795be7879e7ea2beda248321b6c8ae851dabc785522a432fb8ce003"

[tools.ripgrep]
version = "14.1.1"
backend = "aqua:BurntSushi/ripgrep"

[tools.ripgrep.checksums]
"ripgrep-14.1.1-aarch64-apple-darwin.tar.gz" = "sha256:24ad76777745fbff131c8fbc466742b011f925bfa4fffa2ded6def23b5b937be"
Expand All @@ -76,6 +91,7 @@ version = "14.1.1"

[tools.shellcheck]
version = "0.10.0"
backend = "aqua:koalaman/shellcheck"

[tools.shellcheck.checksums]
shellcheck-linux-x86_64 = "sha256:f35ae15a4677945428bdfe61ccc297490d89dd1e544cc06317102637638c6deb"
Expand All @@ -85,12 +101,14 @@ shellcheck-macos-aarch64 = "sha256:b9e420df8c78ec7d261d66277d5767cbd4cf6da4e4a9f

[tools.shfmt]
version = "3.10.0"
backend = "aqua:mvdan/sh"

[tools.shfmt.checksums]
"shfmt_v3.10.0_linux_amd64" = "sha256:1f57a384d59542f8fac5f503da1f3ea44242f46dff969569e80b524d64b71dbc"

[tools.slsa-verifier]
version = "2.6.0"
backend = "ubi:slsa-framework/slsa-verifier"

[tools.slsa-verifier.checksums]
slsa-verifier-linux-x86_64 = "sha256:1c9c0d6a272063f3def6d233fa3372adbaff1f5a3480611a07c744e73246b62d"
Expand All @@ -99,6 +117,7 @@ slsa-verifier-macos-aarch64 = "sha256:8740e66832fd48bbaa479acd5310986b876ff54546

[tools.wait-for-gh-rate-limit]
version = "0.1.8"
backend = "ubi:jdx/wait-for-gh-rate-limit"

[tools.wait-for-gh-rate-limit.checksums]
wait-for-gh-rate-limit-linux-x86_64 = "sha256:a3e7e966a8d681f30bb7887e471740607074ab7f28580dd926efc307b0d35c20"
Expand Down
7 changes: 6 additions & 1 deletion src/cli/args/backend_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::plugins::PluginType;
use crate::registry::REGISTRY;
use crate::toolset::install_state::InstallStateTool;
use crate::toolset::{install_state, parse_tool_options, ToolVersionOptions};
use crate::{backend, config, dirs, registry};
use crate::{backend, config, dirs, lockfile, registry};
use contracts::requires;
use eyre::{bail, Result};
use heck::ToKebabCase;
Expand Down Expand Up @@ -139,6 +139,11 @@ impl BackendArg {
deprecated!("config_plugins", "[plugins] section of mise.toml is deprecated. Use [alias] instead. https://mise.jdx.dev/dev-tools/aliases.html");
return format!("asdf:{url}");
}
if let Some(lt) = lockfile::get_locked_version(None, short, "").unwrap_or_default() {
if let Some(backend) = lt.backend {
return backend;
}
}
}
if let Some(full) = &self.full {
full.clone()
Expand Down
42 changes: 42 additions & 0 deletions src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde_derive::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use toml_edit::DocumentMut;

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
Expand All @@ -21,6 +22,7 @@ pub struct Lockfile {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LockfileTool {
pub version: String,
pub backend: Option<String>,
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub checksums: BTreeMap<String, String>,
}
Expand Down Expand Up @@ -69,6 +71,7 @@ impl Lockfile {
let mut lockfile = toml::Table::new();
lockfile.insert("tools".to_string(), tools.into());
let content = toml::to_string_pretty(&toml::Value::Table(lockfile))?;
let content = format(content.parse()?);
file::write(path, content)?;
}
Ok(())
Expand Down Expand Up @@ -241,6 +244,7 @@ impl TryFrom<toml::Value> for LockfileTool {
let tool = match value {
toml::Value::String(v) => LockfileTool {
version: v,
backend: Default::default(),
checksums: Default::default(),
},
toml::Value::Table(mut t) => {
Expand All @@ -257,6 +261,11 @@ impl TryFrom<toml::Value> for LockfileTool {
.map(|v| v.try_into())
.transpose()?
.unwrap_or_default(),
backend: t
.remove("backend")
.map(|v| v.try_into())
.transpose()?
.unwrap_or_default(),
checksums,
}
}
Expand All @@ -270,6 +279,9 @@ impl LockfileTool {
fn into_toml_value(self) -> toml::Value {
let mut table = toml::Table::new();
table.insert("version".to_string(), self.version.into());
if let Some(backend) = self.backend {
table.insert("backend".to_string(), backend.into());
}
if !self.checksums.is_empty() {
table.insert("checksums".to_string(), self.checksums.into());
}
Expand All @@ -283,8 +295,38 @@ impl From<ToolVersionList> for Vec<LockfileTool> {
.iter()
.map(|tv| LockfileTool {
version: tv.version.clone(),
backend: Some(tv.ba().full()),
checksums: tv.checksums.clone(),
})
.collect()
}
}

fn format(mut doc: DocumentMut) -> String {
if let Some(tools) = doc.get_mut("tools") {
for (_k, v) in tools.as_table_mut().unwrap().iter_mut() {
match v {
toml_edit::Item::ArrayOfTables(art) => {
for t in art.iter_mut() {
t.sort_values_by(|a, _, b, _| {
if a == "version" {
return std::cmp::Ordering::Less;
}
a.to_string().cmp(&b.to_string())
});
}
}
toml_edit::Item::Table(t) => {
t.sort_values_by(|a, _, b, _| {
if a == "version" {
return std::cmp::Ordering::Less;
}
a.to_string().cmp(&b.to_string())
});
}
_ => {}
}
}
}
doc.to_string()
}

0 comments on commit b13f27e

Please sign in to comment.