Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
MattParkerDev committed Jul 7, 2024
1 parent de59f50 commit 1c05744
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
26 changes: 26 additions & 0 deletions src/ParallelPipelines/Application/PipelineSummaryDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using ParallelPipelines.Domain.Entities;
using ParallelPipelines.Domain.Enums;

namespace ParallelPipelines.Application;

public class PipelineSummaryDto
{
public CompletionType? OverallCompletionType { get; set; }
public DateTimeOffset? DeploymentStartTime;
public DateTimeOffset? DeploymentEndTime;
public List<StepContainerDto> StepContainers { get; set; } = [];
}

public static class PipelineSummaryMapper
{
public static PipelineSummaryDto ToDto(PipelineSummary pipelineSummary)
{
return new PipelineSummaryDto
{
OverallCompletionType = pipelineSummary.OverallCompletionType,
DeploymentStartTime = pipelineSummary.DeploymentStartTime,
DeploymentEndTime = pipelineSummary.DeploymentEndTime,
StepContainers = pipelineSummary.StepContainers.Select(StepContainerMapper.ToDto).ToList()
};
}
}
26 changes: 26 additions & 0 deletions src/ParallelPipelines/Application/StepContainerDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using ParallelPipelines.Domain.Entities;
using ParallelPipelines.Domain.Enums;

namespace ParallelPipelines.Application;

public class StepContainerDto
{
public string? StepName { get; set; }
public CompletionType? CompletionType { get; set; }
public DateTimeOffset? StartTime { get; set; }
public DateTimeOffset? EndTime { get; set; }
}

public static class StepContainerMapper
{
public static StepContainerDto ToDto(StepContainer stepContainer)
{
return new StepContainerDto
{
StepName = stepContainer.GetStepName(),
CompletionType = stepContainer.CompletionType,
StartTime = stepContainer.StartTime,
EndTime = stepContainer.EndTime
};
}
}
32 changes: 29 additions & 3 deletions src/ParallelPipelines/Host/PipelineApplication.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System.Diagnostics;
using System.IO.Compression;
using System.Text.Json;
using Actions.Octokit;
using GitHub;
using GitHub.Models;
using Microsoft.Extensions.Hosting;
using Octokit;
using Octokit.Internal;
using ParallelPipelines.Domain.Entities;
using ParallelPipelines.Host.Helpers;
using ParallelPipelines.Host.Services;
using Spectre.Console;
Expand Down Expand Up @@ -33,11 +36,34 @@ public async Task StartAsync(CancellationToken cancellationToken)
var owner = Context.Current.Repo.Owner;
var repo = Context.Current.Repo.Repo;
var githubToken = _pipelineContext.Configuration["WorkflowGithubToken"];
//var githubClient = new GitHubClient(new ProductHeaderValue("ParallelPipelines"), new InMemoryCredentialStore(new Credentials(githubToken, AuthenticationType.Bearer)));
var githubClient = new GitHubClient(new ProductHeaderValue("ParallelPipelines"));
var githubClient = new GitHubClient(new ProductHeaderValue("ParallelPipelines"), new InMemoryCredentialStore(new Credentials(githubToken, AuthenticationType.Bearer)));
//var githubClient = new GitHubClient(new ProductHeaderValue("ParallelPipelines"), new InMemoryCredentialStore(new Credentials("", AuthenticationType.Bearer)));
owner = "MattParkerDev";
repo = "ParallelPipelines";
var runs = await githubClient.Actions.Workflows.Runs.ListByWorkflow(owner, repo, "example-prod-deploy.yml");
runId = 9828456326;
var run = await githubClient.Actions.Workflows.Runs.Get(owner, repo, runId);
var attemptNumber = run.RunAttempt + 1;
if (attemptNumber > 1)
{
AnsiConsole.WriteLine($"ParallelPipelines is running on attempt number {attemptNumber}");
var result = await githubClient.Actions.Artifacts.ListWorkflowArtifacts(owner, repo, runId);
var artifacts = result.Artifacts;
var failedRunArtifact = artifacts.FirstOrDefault(s => s.Name == "parallel-pipelines-artifact");
if (failedRunArtifact is not null)
{
await using var stream = await githubClient.Actions.Artifacts.DownloadArtifact(owner, repo, failedRunArtifact.Id, "zip");
// unzip stream and get json string
var zipArchive = new ZipArchive(stream);
var entry = zipArchive.Entries.FirstOrDefault();
if (entry is not null)
{
await using var entryStream = entry.Open();
var json = JsonSerializer.DeserializeAsync<string>(entryStream, cancellationToken: cancellationToken);

}
}
}


var pipelineSummary = await _orchestratorService.RunPipeline(cancellationToken);
await _postStepService.RunPostSteps(pipelineSummary, cancellationToken);
Expand Down
5 changes: 5 additions & 0 deletions src/ParallelPipelines/Host/Services/PostStepService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Diagnostics;
using System.Text.Json;
using Microsoft.Extensions.Options;
using ParallelPipelines.Application;
using ParallelPipelines.Domain.Entities;
using ParallelPipelines.Host.Helpers;
using ParallelPipelines.Host.InternalHelpers;
Expand All @@ -19,6 +21,9 @@ public async Task RunPostSteps(PipelineSummary pipelineSummary, CancellationToke
{
var text = GetGithubSummary(pipelineSummary, cancellationToken);
await WriteGithubSummary(text, cancellationToken);
var pipelineSummaryDto = PipelineSummaryMapper.ToDto(pipelineSummary);
var summaryFile = await PipelineFileHelper.GitRootDirectory.CreateFileIfMissingAndGetFile("pipeline-summary-dto.json");
await File.WriteAllTextAsync(summaryFile.FullName, JsonSerializer.Serialize(pipelineSummaryDto, new JsonSerializerOptions { WriteIndented = true }), cancellationToken);
}

private string GetGithubSummary(PipelineSummary pipelineSummary, CancellationToken cancellationToken)
Expand Down

0 comments on commit 1c05744

Please sign in to comment.