-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(hooks): add MISE_TOOL_NAME and MISE_TOOL_VERSION to preinstall/postinstall hooks #7311
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,20 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Test that MISE_TOOL_NAME and MISE_TOOL_VERSION are set in preinstall/postinstall hooks | ||
|
|
||
| cat <<EOF >mise.toml | ||
| [tools] | ||
| dummy = 'latest' | ||
|
|
||
| [hooks] | ||
| preinstall = 'echo "PREINSTALL: name=\$MISE_TOOL_NAME version=\$MISE_TOOL_VERSION"' | ||
| postinstall = 'echo "POSTINSTALL: name=\$MISE_TOOL_NAME version=\$MISE_TOOL_VERSION"' | ||
| EOF | ||
|
|
||
| # Install dummy tool and check that env vars are set | ||
| assert_contains "mise i dummy@1.0.0 2>&1" "PREINSTALL: name=dummy version=1.0.0" | ||
| assert_contains "mise i dummy@1.0.0 2>&1" "POSTINSTALL: name=dummy version=1.0.0" | ||
|
|
||
| # Test with a different version | ||
| assert_contains "mise i dummy@2.0.0 2>&1" "PREINSTALL: name=dummy version=2.0.0" | ||
| assert_contains "mise i dummy@2.0.0 2>&1" "POSTINSTALL: name=dummy version=2.0.0" |
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,13 @@ use std::sync::Mutex; | |||||
| use std::{iter::once, sync::Arc}; | ||||||
| use tokio::sync::OnceCell; | ||||||
|
|
||||||
| /// Context for tool-specific hooks (preinstall/postinstall) | ||||||
| #[derive(Debug, Clone)] | ||||||
| pub struct HookToolContext { | ||||||
| pub name: String, | ||||||
| pub version: String, | ||||||
| } | ||||||
|
|
||||||
| #[derive( | ||||||
| Debug, | ||||||
| Clone, | ||||||
|
|
@@ -84,6 +91,38 @@ pub async fn run_one_hook( | |||||
| ts: &Toolset, | ||||||
| hook: Hooks, | ||||||
| shell: Option<&dyn Shell>, | ||||||
| ) { | ||||||
| run_one_hook_with_shell(config, ts, hook, shell).await; | ||||||
| } | ||||||
|
|
||||||
| /// Run a hook with optional tool context for preinstall/postinstall hooks (used during installation) | ||||||
| /// This version doesn't take a shell parameter and can be used in spawned async tasks. | ||||||
| #[async_backtrace::framed] | ||||||
| pub async fn run_one_hook_with_tool( | ||||||
| config: &Arc<Config>, | ||||||
| ts: &Toolset, | ||||||
| hook: Hooks, | ||||||
| tool_ctx: &HookToolContext, | ||||||
| ) { | ||||||
| for (root, h) in all_hooks(config).await { | ||||||
| if hook != h.hook || h.shell.is_some() { | ||||||
| // Skip shell-specific hooks during installation | ||||||
|
||||||
| // Skip shell-specific hooks during installation | |
| // Skip hooks if the type doesn't match or if it's shell-specific (during installation) |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter is not optional -
tool_ctxis a required&HookToolContextparameter. The docstring should reflect that this function requires tool context rather than describing it as optional.