diff --git a/src/Nox.Cli.Plugins/Nox.Cli.Plugin.Powershell/PowershellScript_v1.cs b/src/Nox.Cli.Plugins/Nox.Cli.Plugin.Powershell/PowershellScript_v1.cs index d56d17a..51c55d0 100755 --- a/src/Nox.Cli.Plugins/Nox.Cli.Plugin.Powershell/PowershellScript_v1.cs +++ b/src/Nox.Cli.Plugins/Nox.Cli.Plugin.Powershell/PowershellScript_v1.cs @@ -70,7 +70,15 @@ public Task> ProcessAsync(INoxWorkflowContext ctx) var results = _pwsh.Invoke(); - if (results.Any(r => (r.ToString() ?? "").Contains("error", StringComparison.OrdinalIgnoreCase))) + if (_pwsh.HadErrors) + { + var errorMessage = ""; + foreach (var err in _pwsh.Streams.Error) + { + errorMessage += err.ErrorDetails.Message + Environment.NewLine; + } + ctx.SetErrorMessage(errorMessage); + } else if (results.Any(r => (r.ToString() ?? "").Contains("error", StringComparison.OrdinalIgnoreCase))) { var errorMessage = ""; foreach (var result in results) @@ -83,7 +91,7 @@ public Task> ProcessAsync(INoxWorkflowContext ctx) { outputs["result"] = results; - ctx.SetState(ActionState.Success); + ctx.SetState(ActionState.Success); } } diff --git a/src/Plugin.Powershell.Tests/Plugin.Powershell.Tests.csproj b/src/Plugin.Powershell.Tests/Plugin.Powershell.Tests.csproj new file mode 100644 index 0000000..8207213 --- /dev/null +++ b/src/Plugin.Powershell.Tests/Plugin.Powershell.Tests.csproj @@ -0,0 +1,30 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Plugin.Powershell.Tests/ScriptTests.cs b/src/Plugin.Powershell.Tests/ScriptTests.cs new file mode 100644 index 0000000..0b417cc --- /dev/null +++ b/src/Plugin.Powershell.Tests/ScriptTests.cs @@ -0,0 +1,36 @@ +using Moq; +using Nox.Cli.Abstractions; +using Nox.Cli.Abstractions.Caching; +using Nox.Cli.Actions; +using Nox.Cli.Configuration; +using Nox.Cli.Plugins.Powershell; +using Nox.Cli.Variables.Secrets; +using Nox.Secrets.Abstractions; +using Nox.Solution; + +namespace Plugin.Powershell.Tests; + +public class ScriptTests +{ + [Fact] + public async Task Can_perform_a_git_pull() + { + Directory.SetCurrentDirectory("/home/jan/Projects/IWG/Fno.MultiDeploy"); + var plugin = new PowershellScript_v1(); + var inputs = new Dictionary + { + {"script", "git pull --rebase iwgplc main"}, + }; + await plugin.BeginAsync(inputs); + var wfConfig = new WorkflowConfiguration(); + var sln = Mock.Of(); + var orgResolver = Mock.Of(); + var cacheMan = Mock.Of(); + var lteConfig = Mock.Of(); + var secretsResolver = Mock.Of(); + var ctx = new NoxWorkflowContext(wfConfig, sln, orgResolver, cacheMan, lteConfig, secretsResolver); + await plugin.ProcessAsync(ctx); + Console.WriteLine(ctx.CurrentAction!.ErrorMessage!); + Assert.Equal(ActionState.Success, ctx.State); + } +} \ No newline at end of file