Skip to content
Closed
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
4 changes: 4 additions & 0 deletions ADotNet/ADotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@
</None>
</ItemGroup>


<ItemGroup>
<InternalsVisibleTo Include="ADotNet.Tests.Unit" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion ADotNet/Clients/ADotNetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ADotNet.Clients
{
public class ADotNetClient
public class ADotNetClient : IADotNetClient
{
private readonly IBuildService buildService;

Expand Down
77 changes: 77 additions & 0 deletions ADotNet/Clients/Builders/GitHubPipelineBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets;

namespace ADotNet.Clients.Builders
{
public class GitHubPipelineBuilder
{
private readonly GithubPipeline githubPipeline;
private readonly IADotNetClient aDotNetClient;

internal GitHubPipelineBuilder(IADotNetClient aDotNetClient)
{
this.githubPipeline = new GithubPipeline
{
OnEvents = new Events(),
Jobs = new Dictionary<string, Job>()
};

this.aDotNetClient = aDotNetClient;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line above as it is following a multi liner.

}

public static GitHubPipelineBuilder CreateNewPipeline()
{
var aDotNetClient = new ADotNetClient();

return new GitHubPipelineBuilder(aDotNetClient);

@cjdutoit cjdutoit Jan 27, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line before return, fix others as well

}

public GitHubPipelineBuilder SetName(string name)
{
this.githubPipeline.Name = name;

return this;
}

public GitHubPipelineBuilder OnPush(params string[] branches)
{
this.githubPipeline.OnEvents.Push = new PushEvent
{
Branches = branches
};

return this;
}

public GitHubPipelineBuilder OnPullRequest(params string[] branches)
{
this.githubPipeline.OnEvents.PullRequest = new PullRequestEvent
{
Branches = branches
};

return this;
}

public GitHubPipelineBuilder AddJob(string jobIdentifier, Action<JobBuilder> configureJob)
{
var jobBuilder = new JobBuilder();

configureJob(jobBuilder);

this.githubPipeline.Jobs[jobIdentifier] = jobBuilder.Build();

return this;
}

public void SaveToFile(string path) =>
this.aDotNetClient.SerializeAndWriteToFile(this.githubPipeline, path);
}
}
123 changes: 123 additions & 0 deletions ADotNet/Clients/Builders/JobBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using System.Collections.Generic;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV1s;

namespace ADotNet.Clients.Builders
{
public class JobBuilder
{
private readonly Job job;

internal JobBuilder()
{
this.job = new Job
{
Steps = new List<GithubTask>(),
EnvironmentVariables = null
};
}

public JobBuilder WithName(string name)
{
this.job.Name = name;
return this;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line before a return, fix others on file as well

}

public JobBuilder RunsOn(string machine)
{
this.job.RunsOn = machine;
return this;
}

public JobBuilder AddEnvironmentVariable(string key, string value)
{
this.job.EnvironmentVariables ??= new Dictionary<string, string>();

this.job.EnvironmentVariables[key] = value;
return this;
}

public JobBuilder AddEnvironmentVariables(Dictionary<string, string> variables)
{
this.job.EnvironmentVariables ??= new Dictionary<string, string>();

foreach (var variable in variables)
{
this.job.EnvironmentVariables[variable.Key] = variable.Value;
}

return this;
}

public JobBuilder AddCheckoutStep(string name = "Check out")
{
this.job.Steps.Add(new CheckoutTaskV2 { Name = name });

return this;
}

public JobBuilder AddSetupDotNetStep(
string version,
string stepName = "Setup Dot Net Version",
bool includePrerelease = false)
{
this.job.Steps.Add(new SetupDotNetTaskV1
{
Name = stepName,
TargetDotNetVersion = new TargetDotNetVersion
{
DotNetVersion = version,
IncludePrerelease = includePrerelease
}
});

return this;
}

public JobBuilder AddRestoreStep(string name = "Restore")
{
this.job.Steps.Add(new RestoreTask { Name = name });

return this;
}

public JobBuilder AddBuildStep(string name = "Build")
{
this.job.Steps.Add(new DotNetBuildTask { Name = name });

return this;
}

public JobBuilder AddTestStep(string name = "Test", string command = null)
{
this.job.Steps.Add(new TestTask
{
Name = name,
Run = command ?? "dotnet test --no-build --verbosity normal"
});

return this;
}

public JobBuilder AddGenericStep(string name, string runCommand)
{
this.job.Steps.Add(new GithubTask
{
Name = name,
Run = runCommand
});

return this;
}

public Job Build() => this.job;
}

}
24 changes: 24 additions & 0 deletions ADotNet/Models/Pipelines/GithubPipelines/DotNets/EventsV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using YamlDotNet.Serialization;

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets
{
public class EventsV2
{
[YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public PushEvent Push { get; set; }

[YamlMember(Alias = "pull_request", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public PullRequestEvent PullRequest { get; set; }

public ScheduledEvent[] Schedule { get; set; }

[YamlMember(Alias = "workflow_dispatch")]
public WorkflowDispatchEvent WorkflowDispatch { get; set; }
}
}
16 changes: 16 additions & 0 deletions ADotNet/Models/Pipelines/GithubPipelines/DotNets/ScheduledEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using YamlDotNet.Serialization;

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets
{
public class ScheduledEvent
{
[YamlMember(Order = 0, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public string Cron { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using YamlDotNet.Serialization;

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks
{
public class InstallPlaywrightBrowsersTask : GithubTask
{
[YamlIgnore]
public string ProjectName { get; set; }
public override string Run => $"pwsh ./{ProjectName}/bin/Debug/net9.0/playwright.ps1 install";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks
{
public class InstallPlaywrightTask : GithubTask
{
public override string Run { get; set; } = "dotnet tool install --global Microsoft.Playwright.CLI";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using YamlDotNet.Serialization;

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks
{
public class RunUntilFailureTask : GithubTask
{
[YamlMember(Order = 1, Alias = "shell", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public override string Shell => "bash";

[YamlMember(Order = 2, Alias = "run", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public override string Run => "for i in {1..1000};" +
@" do echo ""Run #$i""; dotnet test --no-build " +
"--verbosity normal --filter 'FullyQualifiedName!~Integrations' || exit 1; done";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks
{
public class WorkloadUpdateTask : GithubTask
{
public override string Run { get; set; } = "dotnet workload update";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets
{
public class WorkflowDispatchEvent
{ }
}
28 changes: 28 additions & 0 deletions AdoNet.Tests.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System.Collections.Generic;
using ADotNet.Clients;
using ADotNet.Clients.Builders;
using ADotNet.Models.Pipelines.AdoPipelines.AspNets;
using ADotNet.Models.Pipelines.AdoPipelines.AspNets.Tasks.DotNetExecutionTasks;
using ADotNet.Models.Pipelines.AdoPipelines.AspNets.Tasks.PublishBuildArtifactTasks;
Expand Down Expand Up @@ -185,6 +186,33 @@ static void Main(string[] args)
};

adoClient.SerializeAndWriteToFile(githubPipeline, "github-pipelines.yaml");

GitHubPipelineBuilder.CreateNewPipeline()
.SetName("Github")
.OnPush("master")
.OnPullRequest("master")
.AddJob("build", job => job
.WithName("Build")
.RunsOn(BuildMachines.WindowsLatest)
.AddEnvironmentVariable("AzureClientId", "${{ secrets.AZURECLIENTID }}")
.AddEnvironmentVariables(new Dictionary<string, string>
{
{ "AzureTenantId", "${{ secrets.AZURETENANTID }}" },
{ "AzureClientSecret", "${{ secrets.AZURECLIENTSECRET }}" },
{ "AzureAdminName", "${{ secrets.AZUREADMINNAME }}" },
{ "AzureAdminAccess", "${{ secrets.AZUREADMINACCESS }}" }
})
.AddCheckoutStep("Check Out")
.AddSetupDotNetStep(
version: "6.0.101",
includePrerelease: true)
.AddRestoreStep()
.AddBuildStep()
.AddGenericStep(
name: "Provision",
runCommand: "dotnet run --project .\\OtripleS.Api.Infrastructure.Provision\\OtripleS.Web.Api.Infrastructure.Provision.csproj"))
.SaveToFile("github-pipelines-2.yaml");

}
}
}
Loading