Skip to content

Commit

Permalink
update exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
MattParkerDev committed Oct 13, 2024
1 parent 5910da1 commit f1ba8de
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ParallelPipelines/Host/PipelineApplication.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using Microsoft.Extensions.Hosting;
using ParallelPipelines.Domain.Enums;
using ParallelPipelines.Host.Services;
using Spectre.Console;

Expand All @@ -21,6 +22,10 @@ public async Task StartAsync(CancellationToken cancellationToken)
{
var pipelineSummary = await _orchestratorService.RunPipeline(cancellationToken);
await _postStepService.RunPostSteps(pipelineSummary, cancellationToken);
if (pipelineSummary.OverallCompletionType is CompletionType.Cancelled or CompletionType.Failure)
{
Environment.ExitCode = 1;
}
}
catch (Exception e)
{
Expand Down
4 changes: 4 additions & 0 deletions src/ParallelPipelines/ParallelPipelines.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
<None Include="readme.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="ParallelPipelines.Unit.Tests" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions tests/ParallelPipelines.Unit.Tests/OrchestratorServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Example.Deploy.Steps._1Setup;
using ParallelPipelines.Domain.Enums;
using ParallelPipelines.Host;
using ParallelPipelines.Host.Helpers;
using ParallelPipelines.Host.Services;
using ParallelPipelines.Unit.Tests.TestSteps;
using Spectre.Console;
Expand Down Expand Up @@ -116,4 +118,29 @@ public async Task OrchestratorService_TestTimings()

pipelineSummary?.DeploymentEndTime.Should().BeCloseTo(step4.EndTime!.Value, TimeSpan.FromMilliseconds(10));
}

[Fact]
public async Task ParallelPipelinesApplication_FailedStep_ExitsWithExitCode1()
{
// To pass, add a throw in one of the steps
var cts = new CancellationTokenSource();
await PipelineFileHelper.PopulateGitRootDirectory(cts.Token);
// new process
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = "run",
WorkingDirectory = Path.Combine(PipelineFileHelper.GitRootDirectory.FullName, "examplesrc/Example.Deploy"),
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
await process.WaitForExitAsync();
process.ExitCode.Should().Be(1);
}
}

0 comments on commit f1ba8de

Please sign in to comment.