Skip to content

Commit

Permalink
Add basic version of PowerShell script execution on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Jul 31, 2023
1 parent f064b9b commit 3415929
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func LookPath(name string) (string, error) {
exts = append(exts, e)

Check warning on line 33 in internal/plugin/plugin.go

View check run for this annotation

Codecov / codecov/patch

internal/plugin/plugin.go#L30-L33

Added lines #L30 - L33 were not covered by tests
}
} else {
exts = []string{".com", ".exe", ".bat", ".cmd"}
exts = []string{".com", ".exe", ".bat", ".cmd", ".ps1"}
}
for _, ext := range exts {

Check warning on line 38 in internal/plugin/plugin.go

View check run for this annotation

Codecov / codecov/patch

internal/plugin/plugin.go#L35-L38

Added lines #L35 - L38 were not covered by tests
path := filepath.Join(step.BasePath(), "plugins", fileName+ext)
Expand All @@ -54,8 +54,16 @@ func LookPath(name string) (string, error) {
// it to complete.
func Run(ctx *cli.Context, file string) error {
args := ctx.Args()
//nolint:gosec // arguments controlled by step.
cmd := exec.Command(file, args[1:]...)
cmdName := file

// if running on Windows and (likely) a PowerShell script, invoke powershell
// with the arguments instead of the plugin file directly.
if runtime.GOOS == "windows" && filepath.Ext(file) == ".ps1" {
cmdName = "powershell"
args = append([]string{args[0], "-noprofile", "-nologo", file}, args[1:]...)
}

Check warning on line 64 in internal/plugin/plugin.go

View check run for this annotation

Codecov / codecov/patch

internal/plugin/plugin.go#L57-L64

Added lines #L57 - L64 were not covered by tests

cmd := exec.Command(cmdName, args[1:]...)

Check warning on line 66 in internal/plugin/plugin.go

View check run for this annotation

Codecov / codecov/patch

internal/plugin/plugin.go#L66

Added line #L66 was not covered by tests
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 3415929

Please sign in to comment.