Skip to content

Commit

Permalink
fix: improve mise generate bootstrap (#3939)
Browse files Browse the repository at this point in the history
* fix: improve mise generate bootstrap

* [autofix.ci] apply automated fixes

* fix test

* additional fix

* lint

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
hverlin and autofix-ci[bot] authored Jan 4, 2025
1 parent f84ae91 commit 39908f0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ megalinter-reports/

.vscode/
testResults.xml
.mise/
5 changes: 5 additions & 0 deletions e2e/generate/test_generate_bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ assert "./bin/mise version"
assert "mise task add xxx -- echo 'running xxx'"
assert "mise generate task-stubs --mise-bin ./bin/mise"
assert "./bin/xxx" "running xxx"

assert "mise generate bootstrap -l -w"
assert_contains "./bin/mise tasks ls" "xxx"

assert_not_contains "MISE_IGNORED_CONFIG_PATHS=$(pwd) ./bin/mise tasks ls" "xxx"
1 change: 1 addition & 0 deletions mise.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version = "1.7.5"
backend = "aqua:rhysd/actionlint"

[tools.actionlint.checksums]
actionlint-macos-aarch64 = "sha256:84d2e2a03e3891bb55aacb09008fc750199242106d2899d8496208fe66b6137b"
"actionlint_1.7.5_darwin_arm64.tar.gz" = "sha256:397119f9baa3fd9fe195db340b30acdaea532826e19a047a9cc9d96add7c267d"

[tools.bun]
Expand Down
20 changes: 15 additions & 5 deletions src/cli/generate/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::config::SETTINGS;
use crate::http::HTTP;
use crate::ui::info;
use crate::Result;
use crate::{file, minisign};
use crate::{file, minisign, Result};
use clap::ValueHint;
use std::path::PathBuf;
use xx::file::display_path;
Expand Down Expand Up @@ -63,19 +62,27 @@ impl Bootstrap {
.get(1)
.unwrap()
.as_str();

let shared_vars = r#"
local script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
local project_dir=$( cd -- "$( dirname -- "$script_dir" )" &> /dev/null && pwd )
export MISE_BOOTSTRAP_PROJECT_DIR="$project_dir"
"#;

let vars = if self.localize {
// TODO: this will only work right if it is in the base directory, not an absolute path or has a subdirectory
let localized_dir = self.localized_dir.to_string_lossy();
format!(
r#"
local script_dir=$( cd -- "$( dirname -- "${{BASH_SOURCE[0]}}" )" &> /dev/null && pwd )
local project_dir=$( cd -- "$( dirname -- "$script_dir" )" &> /dev/null && pwd )
local localized_dir="$project_dir/{localized_dir}"
export MISE_BOOTSTRAP_PROJECT_DIR="$project_dir"
export MISE_DATA_DIR="$localized_dir"
export MISE_CONFIG_DIR="$localized_dir"
export MISE_CACHE_DIR="$localized_dir/cache"
export MISE_STATE_DIR="$localized_dir/state"
export MISE_INSTALL_PATH="$localized_dir/mise-{version}"
export MISE_TRUSTED_CONFIG_PATHS="$project_dir${{MISE_TRUSTED_CONFIG_PATHS:+:$MISE_TRUSTED_CONFIG_PATHS}}"
export MISE_IGNORED_CONFIG_PATHS="$HOME/.config/mise${{MISE_IGNORED_CONFIG_PATHS:+:$MISE_IGNORED_CONFIG_PATHS}}"
"#
)
} else {
Expand All @@ -86,16 +93,19 @@ export MISE_INSTALL_PATH="$cache_home/mise-{version}"
"#
)
};
let shared_vars = info::indent_by(shared_vars.trim(), " ");
let vars = info::indent_by(vars.trim(), " ");
let script = format!(
r#"
#!/bin/sh
#!/usr/bin/env bash
set -eu
__mise_bootstrap() {{
{shared_vars}
{vars}
install() {{
{install}
cd "$MISE_BOOTSTRAP_PROJECT_DIR"
}}
local MISE_INSTALL_HELP=0
test -f "$MISE_INSTALL_PATH" || install
Expand Down

0 comments on commit 39908f0

Please sign in to comment.