-
Notifications
You must be signed in to change notification settings - Fork 35
EXPOSERS: Fluent GitHub Pipeline Builder #145
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
Closed
mabroukmahdhi
wants to merge
15
commits into
main
from
users/mabroukmahdhi/exposures-fluent-pipeline-builder
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4ff2c08
DATA: InstallPlaywrightTask
mabroukmahdhi f7a12d1
DATA: WorkloadUpdateTask
mabroukmahdhi 3217e27
DATA: InstallPlaywrightBrowsersTask
mabroukmahdhi 50db6ba
DATA: RunUntilFailureTask
mabroukmahdhi a062501
DATA: EventsV2
mabroukmahdhi 0a3e0ed
EXPOSURES: GitHubPipelineBuilder
mabroukmahdhi 2f4f6ed
ShouldCreateNewPipeline -> PASS
mabroukmahdhi f9aab96
ShouldSetPipelineName -> PASS
mabroukmahdhi b68c2be
CODE RUB: Assert With Fluent Assertion
mabroukmahdhi ec73e2b
ShouldAddPushTrigger -> PASS
mabroukmahdhi a13914a
ShouldAddPullRequestTrigger -> PASS
mabroukmahdhi 4805b5e
ShouldAddJobToPipeline -> PASS
mabroukmahdhi 8af445b
ShouldSavePipelineToFile -> FAIL
mabroukmahdhi 08fc22c
ShouldSavePipelineToFile -> PASS
mabroukmahdhi 8905d97
CODE RUB: Fix Syntax and Clean up
mabroukmahdhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,4 +86,8 @@ | |
| </None> | ||
| </ItemGroup> | ||
|
|
||
|
|
||
| <ItemGroup> | ||
| <InternalsVisibleTo Include="ADotNet.Tests.Unit" /> | ||
| </ItemGroup> | ||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| public static GitHubPipelineBuilder CreateNewPipeline() | ||
| { | ||
| var aDotNetClient = new ADotNetClient(); | ||
|
|
||
| return new GitHubPipelineBuilder(aDotNetClient); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
24
ADotNet/Models/Pipelines/GithubPipelines/DotNets/EventsV2.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
16
ADotNet/Models/Pipelines/GithubPipelines/DotNets/ScheduledEvent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/InstallPlaywrightBrowsersTask.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/InstallPlaywrightTask.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/RunUntilFailureTask.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/WorkloadUpdateTask.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
ADotNet/Models/Pipelines/GithubPipelines/DotNets/WorkflowDispatchEvent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| { } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.