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

- changed powershell script error reporting #241

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ public Task<IDictionary<string, object>> 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)
Expand All @@ -83,7 +91,7 @@ public Task<IDictionary<string, object>> ProcessAsync(INoxWorkflowContext ctx)
{
outputs["result"] = results;

ctx.SetState(ActionState.Success);
ctx.SetState(ActionState.Success);
}

}
Expand Down
30 changes: 30 additions & 0 deletions src/Plugin.Powershell.Tests/Plugin.Powershell.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Nox.Cli.Plugins\Nox.Cli.Plugin.Powershell\Nox.Cli.Plugin.Powershell.csproj" />
<ProjectReference Include="..\Nox.Cli.Variables\Nox.Cli.Variables.csproj" />
<ProjectReference Include="..\Nox.Cli\Nox.Cli.csproj" />
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions src/Plugin.Powershell.Tests/ScriptTests.cs
Original file line number Diff line number Diff line change
@@ -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<string, object>
{
{"script", "git pull --rebase iwgplc main"},
};
await plugin.BeginAsync(inputs);
var wfConfig = new WorkflowConfiguration();
var sln = Mock.Of<NoxSolution>();
var orgResolver = Mock.Of<IOrgSecretResolver>();
var cacheMan = Mock.Of<INoxCliCacheManager>();
var lteConfig = Mock.Of<LocalTaskExecutorConfiguration>();
var secretsResolver = Mock.Of<INoxSecretsResolver>();
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);
}
}
Loading