-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(config): automatically define platform environments (auto_env) #10316
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4e9eff6
feat(config): automatically define platform environments (auto_env)
5a85acb
fix(config): dedupe auto_env warning candidate files
7eb4f2a
fix(config): apply ignored-config filters to auto_env warning detection
28e93bb
fix(config): robust hook-env detection for auto_env warning skip
adb9cc8
fix(config): make auto_env e2e warning assertions phase-proof
3da8ce1
fix(config): simplify boolean expression for clippy
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Test auto_env: platform environments (unix, {os}, {os}-{arch}) are | ||
| # automatically active for config file discovery when enabled | ||
|
|
||
| os="$(uname -s)" | ||
| case "$os" in | ||
| Darwin) os=macos ;; | ||
| Linux) os=linux ;; | ||
| esac | ||
| arch="$(uname -m)" | ||
| case "$arch" in | ||
| x86_64) arch=x64 ;; | ||
| aarch64 | arm64) arch=arm64 ;; | ||
| esac | ||
|
|
||
| echo 'env.AAA = "base" | ||
| env.BBB = "base"' >mise.toml | ||
| echo 'env.AAA = "unix" | ||
| env.UNIX_LOADED = "1"' >mise.unix.toml | ||
| echo "env.AAA = \"$os\"" >"mise.$os.toml" | ||
| echo "env.AAA = \"$os-$arch\"" >"mise.$os-$arch.toml" | ||
| echo 'env.AAA = "prod"' >mise.prod.toml | ||
|
|
||
| # default: off, platform configs are not loaded | ||
| assert "mise env --json | jq -r .AAA" "base" | ||
|
|
||
| # the rollout warning never fires once the user has set auto_env explicitly, | ||
| # regardless of the phase the current version is in (the version-gated unset | ||
| # case is covered by the should_warn_auto_env unit tests) | ||
| assert_not_contains "MISE_AUTO_ENV=false mise env 2>&1" "load automatically" | ||
| assert_not_contains "MISE_AUTO_ENV=true mise env 2>&1" "load automatically" | ||
|
|
||
| # opt in: all platform configs load, most specific wins (unix < os < os-arch) | ||
| MISE_AUTO_ENV=true assert "mise env --json | jq -r .AAA" "$os-$arch" | ||
| MISE_AUTO_ENV=true assert "mise env --json | jq -r .UNIX_LOADED" "1" | ||
| MISE_AUTO_ENV=true assert "mise env --json | jq -r .BBB" "base" | ||
|
|
||
| # explicit MISE_ENV entries take precedence over auto platform envs | ||
| MISE_AUTO_ENV=true MISE_ENV=prod assert "mise env --json | jq -r .AAA" "prod" | ||
|
|
||
| # explicit MISE_ENV listing a platform env dedupes (file loaded once) and | ||
| # keeps its user-specified (higher) precedence | ||
| MISE_AUTO_ENV=true MISE_ENV=$os assert "mise env --json | jq -r .AAA" "$os" | ||
| MISE_AUTO_ENV=true MISE_ENV=$os assert "mise config ls | grep -c \"mise.$os.toml\"" "1" | ||
|
|
||
| # explicit opt-out | ||
| MISE_AUTO_ENV=false assert "mise env --json | jq -r .AAA" "base" | ||
|
|
||
| # auto envs are not added to MISE_ENV itself: {{ mise_env }} and MISE_ENV | ||
| # propagation to subprocesses only reflect explicit environments | ||
| cat <<'EOF' >>mise.toml | ||
| [tasks.print] | ||
| run = '{% if mise_env %}echo {{mise_env}}{% endif %}' | ||
| EOF | ||
| MISE_AUTO_ENV=true assert "mise run print" "" | ||
| MISE_AUTO_ENV=true MISE_ENV=prod assert "mise run print" "[prod]" | ||
|
|
||
| # auto_env can be enabled via .miserc.toml | ||
| echo 'auto_env = true' >.miserc.toml | ||
| assert "mise env --json | jq -r .AAA" "$os-$arch" | ||
| # env var overrides .miserc.toml | ||
| MISE_AUTO_ENV=false assert "mise env --json | jq -r .AAA" "base" | ||
| rm -f .miserc.toml | ||
|
|
||
| # global config dir platform configs load too | ||
| mkdir -p "$MISE_CONFIG_DIR" | ||
| echo "env.GLOBAL_AUTO = \"$os\"" >"$MISE_CONFIG_DIR/config.$os.toml" | ||
| MISE_AUTO_ENV=true assert "mise env --json | jq -r .GLOBAL_AUTO" "$os" | ||
| assert "mise env --json | jq -r .GLOBAL_AUTO" "null" | ||
| rm -f "$MISE_CONFIG_DIR/config.$os.toml" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Test that auto platform environments (auto_env) select matching | ||
| # mise.<env>.lock lockfiles, and explicit MISE_ENV lockfiles still win | ||
|
|
||
| export MISE_LOCKFILE=1 | ||
|
|
||
| os="$(uname -s)" | ||
| case "$os" in | ||
| Darwin) os=macos ;; | ||
| Linux) os=linux ;; | ||
| esac | ||
|
|
||
| cat >"mise.$os.toml" <<'EOF' | ||
| [tools] | ||
| tiny = "2" | ||
| EOF | ||
|
|
||
| touch "mise.$os.lock" | ||
|
|
||
| assert "mise install tiny@2.1.0" | ||
|
|
||
| # with auto_env enabled, mise.$os.toml is active and its lockfile is written | ||
| assert "MISE_AUTO_ENV=true mise use tiny@2" | ||
| assert_contains "cat mise.$os.lock" '[[tools.tiny]]' | ||
| assert_contains "cat mise.$os.lock" 'version = "2.1.0"' | ||
|
|
||
| # the locked version is honored when resolving with auto_env enabled | ||
| assert "MISE_AUTO_ENV=true mise ls tiny --json | jq -r '.[0].version'" "2.1.0" | ||
|
|
||
| # explicit env lockfile takes precedence over the auto platform one | ||
| cat >mise.prod.toml <<'EOF' | ||
| [tools] | ||
| tiny = "1" | ||
| EOF | ||
| touch mise.prod.lock | ||
| assert "mise install tiny@1.0.1" | ||
| assert "MISE_ENV=prod mise use tiny@1" | ||
| assert_contains "cat mise.prod.lock" 'version = "1.0.1"' | ||
| assert "MISE_AUTO_ENV=true MISE_ENV=prod mise ls tiny --json | jq -r '.[0].version'" "1.0.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.