Skip to content
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

Support skipping profile.ps1 loading in PowerShell Hooks by passing -NoProfile #4595

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cli/azd/.vscode/cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ words:
- Retryable
- runcontext
- unmarshals
- noprofile
- usgovcloudapi
languageSettings:
- languageId: go
Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (hra *hooksRunAction) execHook(
defer hra.console.StopPreviewer(ctx, false)

runOptions := &tools.ExecOptions{StdOut: previewer}

err := hooksRunner.RunHooks(ctx, hookType, runOptions, commandName)
if err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions cli/azd/pkg/ext/hooks_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ func (h *HooksRunner) execHook(ctx context.Context, hookConfig *HookConfig, opti
defer h.console.StopPreviewer(ctx, false)
}

var isRunWithNoProfile bool
if hookConfig.Shell == "pwsh" {
if hookConfig.Run != "" {
isRunWithNoProfile = strings.Contains(strings.ToLower(hookConfig.Run), "-noprofile")
}
}
options.IsRunWithNoProfile = isRunWithNoProfile

log.Printf("Executing script '%s'\n", hookConfig.path)
res, err := script.Execute(ctx, hookConfig.path, *options)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion cli/azd/pkg/tools/powershell/powershell.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ type powershellScript struct {
// Executes the specified powershell script
// When interactive is true will attach to stdin, stdout & stderr
func (bs *powershellScript) Execute(ctx context.Context, path string, options tools.ExecOptions) (exec.RunResult, error) {
runArgs := exec.NewRunArgs("pwsh", path).
cmdConfig := " -NoProfile"
normalCmd := "pwsh"

if options.IsRunWithNoProfile {
normalCmd += cmdConfig
}

runArgs := exec.NewRunArgs(normalCmd, path).
WithCwd(bs.cwd).
WithEnv(bs.envVars).
WithShell(true)
Expand Down
5 changes: 3 additions & 2 deletions cli/azd/pkg/tools/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (

// ExecOptions provide configuration for how scripts are executed
type ExecOptions struct {
Interactive *bool
StdOut io.Writer
Interactive *bool
StdOut io.Writer
IsRunWithNoProfile bool
}

// Utility to easily execute a bash script across platforms
Expand Down
Loading