Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions docs/installing-mise.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ This page lists various ways to install `mise` on your system.

The official single-binary release installed by `mise.run` is the preferred method on macOS and
Linux. These binaries are built with mise's optimized release profile and can be updated immediately
with `mise self-update`. Package-manager builds, including Homebrew, may be less optimized and may
not become available as quickly after a mise release.
with `mise self-update`. Prefer them over third-party package builds: the Homebrew formula can be
substantially slower and larger, and package-manager releases may also trail a mise release.

::: tip Which methods auto-update?
Package managers (apt, dnf, brew, pacman, etc.) update mise when you update system packages. Other methods can be updated with `mise self-update`.

For installations that support `mise self-update`, automatic updates can be enabled globally:

```sh
mise settings set auto_update true
```

mise then periodically checks before eligible interactive commands, installs a newer release without
updating plugins, and re-runs the original command with the new binary. Configure the interval with
[`auto_update_check_duration`](/configuration/settings.html#auto_update_check_duration).
:::

::: tip Keep mise up to date
Expand Down
10 changes: 10 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,16 @@
"type": "string"
}
},
"auto_update": {
"default": false,
"description": "Automatically update mise before running eligible commands.",
"type": "boolean"
},
"auto_update_check_duration": {
"default": "7d",
"description": "How often to check for a new mise release when auto-update is enabled.",
"type": "string"
},
"cache_prune_age": {
"default": "30d",
"description": "Delete files in cache that have not been accessed in this duration",
Expand Down
23 changes: 23 additions & 0 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,29 @@ parse_env = "list_by_comma"
rust_type = "Vec<String>"
type = "ListString"

[auto_update]
default = false
description = "Automatically update mise before running eligible commands."
docs = """
When enabled, mise periodically checks for a newer release before running commands that permit
network access. If an update is available, mise installs it without updating plugins, then re-runs
the original command with the new binary.

Automatic updates are skipped in CI, offline and prefer-offline modes, non-interactive sessions,
shell integration commands, and installations whose packager disabled self-update. This setting is
global-only so a project's configuration cannot opt users into replacing their mise binary.
"""
env = "MISE_AUTO_UPDATE"
global_only = true
type = "Bool"

[auto_update_check_duration]
default = "7d"
description = "How often to check for a new mise release when auto-update is enabled."
env = "MISE_AUTO_UPDATE_CHECK_DURATION"
global_only = true
type = "Duration"

[cache_prune_age]
default = "30d"
description = "Delete files in cache that have not been accessed in this duration"
Expand Down
64 changes: 64 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,28 @@ pub(crate) fn expand_deferred_subcommands(mut command: clap::Command) -> clap::C
}

impl Commands {
/// Whether this parsed command may trigger a pre-command automatic update.
///
/// This operates on clap's canonical command variant so aliases such as
/// `dr` inherit the same policy as `doctor`.
fn allows_auto_update(&self) -> bool {
!matches!(
self,
Self::Activate(_)
| Self::Completion(_)
| Self::Deactivate(_)
| Self::Doctor(_)
| Self::HookEnv(_)
| Self::HookNotFound(_)
| Self::Implode(_)
| Self::SelfUpdate(_)
| Self::Settings(_)
| Self::Shell(_)
| Self::Usage(_)
| Self::Version(_)
)
}

fn implicitly_trusts_active_config(&self) -> bool {
matches!(
self,
Expand Down Expand Up @@ -738,6 +760,7 @@ impl Cli {

async fn run_inner(args: &Vec<String>) -> Result<()> {
crate::env::ARGS.write().unwrap().clone_from(args);
let original_cwd = std::env::current_dir().ok();
// Load .miserc.toml early, before MISE_ENV and other early settings are accessed.
// This allows setting MISE_ENV in a config file instead of only via env vars.
crate::config::miserc::init()?;
Expand Down Expand Up @@ -789,6 +812,19 @@ impl Cli {
validate_cd_path(&cli.cd)?;
measure!("add_cli_matches", { Settings::add_cli_matches(&cli) });
let _ = measure!("settings", { Settings::try_get() });
let auto_update_command_eligible = !print_version
&& cli
.command
.as_ref()
.is_some_and(Commands::allows_auto_update);
measure!("auto_update", {
self_update::maybe_auto_update(
args,
original_cwd.as_deref(),
auto_update_command_eligible,
)
.await?
});
measure!("trust_active_config", {
config_file::trust_active_config()?
});
Expand All @@ -807,6 +843,7 @@ impl Cli {
trace!("MISE_BIN: {}", crate::env::MISE_BIN.display_user());
if print_version {
version::show_latest().await;
version::show_version_hint();
return Err(request_exit(0));
}
let _remote_task_artifacts = crate::task::task_fetcher::RemoteTaskArtifactsGuard::new();
Expand Down Expand Up @@ -1036,6 +1073,33 @@ mod tests {
}
}

#[test]
fn shell_commands_and_aliases_do_not_allow_auto_update() {
for args in [
vec!["mise", "doctor"],
vec!["mise", "dr"],
vec!["mise", "hook-env"],
vec!["mise", "hook-not-found", "missing-bin"],
vec!["mise", "version"],
vec!["mise", "v"],
] {
let cli = Cli::try_parse_from(&args).unwrap();
assert!(
!cli.command
.as_ref()
.is_some_and(Commands::allows_auto_update),
"expected {args:?} to skip automatic updates"
);
}

let cli = Cli::try_parse_from(["mise", "install"]).unwrap();
assert!(
cli.command
.as_ref()
.is_some_and(Commands::allows_auto_update)
);
}

/// Guards [`GLOBAL_FLAGS_WITH_VALUES`]. It is hardcoded so that startup does
/// not have to build the clap tree; this keeps it honest. If you added a
/// value-taking flag to `Cli`, add it to that list too.
Expand Down
Loading
Loading