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 3 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 @@ -13,6 +13,7 @@ words:
- usgovcloudapi
- chinacloudapi
- unmarshals
- noprofile
languageSettings:
- languageId: go
ignoreRegExpList:
Expand Down
10 changes: 9 additions & 1 deletion cli/azd/cmd/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
"strings"

"github.com/azure/azure-dev/cli/azd/cmd/actions"
"github.com/azure/azure-dev/cli/azd/internal"
Expand Down Expand Up @@ -235,7 +236,14 @@ func (hra *hooksRunAction) execHook(
})
defer hra.console.StopPreviewer(ctx, false)

runOptions := &tools.ExecOptions{StdOut: previewer}
isRunProfile := true
if hook.Windows != nil {
if hook.Windows.Run != "" {
isRunProfile = !strings.Contains(strings.ToLower(hook.Windows.Run), "-noprofile")
}
}
runOptions := &tools.ExecOptions{StdOut: previewer, IsRunProfile: isRunProfile}

err := hooksRunner.RunHooks(ctx, hookType, runOptions, commandName)
if err != nil {
return err
Expand Down
10 changes: 9 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,15 @@ 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.IsRunProfile {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of wondering if instead of adding IsRunProfile and setting it in hooks.go, I wonder if we should be doing it here, so all invocations of pwsh get it out of the box? I'm sort of wondering if we ever want to not do this for pwsh.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellismg In the current version of azd, pwsh does not support the -NoProfile parameter because in the exec.NewRunArgs("pwsh", path) method in the powershell.go file, the default is not have the -NoProfile parameter, and the hard-coded value is pwsh, as follow:
image

So if we want to support the -NoProfile parameter, we can only add IsRunProfile here.

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
IsRunProfile bool
}

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