diff --git a/ADotNet.sln b/ADotNet.sln index c201826..34a200e 100644 --- a/ADotNet.sln +++ b/ADotNet.sln @@ -14,6 +14,10 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{16CB1804-3040-41F0-9C1F-99A139B24873}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig + .gitattributes = .gitattributes + .gitignore = .gitignore + gitHubPipelines.yaml = gitHubPipelines.yaml + README.md = README.md EndProjectSection EndProject Global diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/Builders/DotNetBuildTaskBuilder.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/Builders/DotNetBuildTaskBuilder.cs new file mode 100644 index 0000000..8c9a184 --- /dev/null +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/Builders/DotNetBuildTaskBuilder.cs @@ -0,0 +1,46 @@ +// --------------------------------------------------------------------------- +// 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.Builders +{ + public class DotNetBuildTaskBuilder + { + private DotNetBuildTask dotnetBuildTask; + + public DotNetBuildTaskBuilder() + { + this.dotnetBuildTask = new DotNetBuildTask(); + this.dotnetBuildTask.Run = "dotnet build"; + } + + public static implicit operator DotNetBuildTask(DotNetBuildTaskBuilder dotnetBuildTaskBuilder) => + dotnetBuildTaskBuilder.Build(); + + public DotNetBuildTaskBuilder Name(string name) + { + this.dotnetBuildTask.Name = name; + + return this; + } + + public DotNetBuildTaskBuilder Restore(bool restore = true) + { + this.dotnetBuildTask.Restore = restore; + + return this; + } + + private DotNetBuildTask Build() + { + if (this.dotnetBuildTask.Restore is false) + { + this.dotnetBuildTask.Run += " --no-restore"; + } + + return this.dotnetBuildTask; + } + } +} diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/Builders/NuGetPushTaskBuilder.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/Builders/NuGetPushTaskBuilder.cs new file mode 100644 index 0000000..3a40ddf --- /dev/null +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/Builders/NuGetPushTaskBuilder.cs @@ -0,0 +1,67 @@ +// --------------------------------------------------------------------------- +// 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.Builders +{ + public class NuGetPushTaskBuilder + { + private NuGetPushTask nugetPushTask; + + public NuGetPushTaskBuilder() => + this.nugetPushTask = new NuGetPushTask(); + + public static implicit operator NuGetPushTask(NuGetPushTaskBuilder nugetPushTaskBuilder) => + nugetPushTaskBuilder.Build(); + + public NuGetPushTaskBuilder Name(string name) + { + this.nugetPushTask.Name = name; + + return this; + } + + public NuGetPushTaskBuilder SearchPath(string searchPath) + { + this.nugetPushTask.SearchPath = searchPath; + + return this; + } + + public NuGetPushTaskBuilder ApiKey(string apiKey) + { + this.nugetPushTask.ApiKey = apiKey; + + return this; + } + + public NuGetPushTaskBuilder Destination(string destination) + { + this.nugetPushTask.Destination = destination; + + return this; + } + + private NuGetPushTask Build() + { + if (!string.IsNullOrEmpty(this.nugetPushTask.SearchPath)) + { + this.nugetPushTask.Run += $" \"{this.nugetPushTask.SearchPath}\""; + } + + if (!string.IsNullOrEmpty(this.nugetPushTask.ApiKey)) + { + this.nugetPushTask.Run += $" --api-key {this.nugetPushTask.ApiKey}"; + } + + if (!string.IsNullOrEmpty(this.nugetPushTask.Destination)) + { + this.nugetPushTask.Run += $" --source \"{this.nugetPushTask.Destination}\""; + } + + return this.nugetPushTask; + } + } +} diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/DotNetBuildTask.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/DotNetBuildTask.cs index fbaec5a..7996553 100644 --- a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/DotNetBuildTask.cs +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/DotNetBuildTask.cs @@ -12,5 +12,7 @@ public class DotNetBuildTask : GithubTask { [YamlMember(Order = 1)] public string Run = "dotnet build --no-restore"; + + internal bool Restore { get; set; } } } diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/NuGetPushTask.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/NuGetPushTask.cs new file mode 100644 index 0000000..43f8607 --- /dev/null +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/NuGetPushTask.cs @@ -0,0 +1,20 @@ +// --------------------------------------------------------------------------- +// 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 NuGetPushTask : GithubTask + { + [YamlMember(Order = 1)] + public string Run = "dotnet nuget push"; + + internal string SearchPath { get; set; } + internal string ApiKey { get; set; } + internal string Destination { get; set; } + } +} diff --git a/AdoNet.Tests.Console/Program.cs b/AdoNet.Tests.Console/Program.cs index 5e63637..26f363c 100644 --- a/AdoNet.Tests.Console/Program.cs +++ b/AdoNet.Tests.Console/Program.cs @@ -12,6 +12,7 @@ using ADotNet.Models.Pipelines.AdoPipelines.AspNets.Tasks.UseDotNetTasks; using ADotNet.Models.Pipelines.GithubPipelines.DotNets; using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks; +using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.Builders; using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV1s; namespace ADotNet.Tests.Console @@ -175,7 +176,13 @@ static void Main(string[] args) { Name = "Provision", Run = "dotnet run --project .\\OtripleS.Api.Infrastructure.Provision\\OtripleS.Web.Api.Infrastructure.Provision.csproj" - } + }, + + new NuGetPushTaskBuilder() + .Name("Publish") + .SearchPath(@"**\*.nupkg") + .ApiKey("${{ secrets.NUGET_API_KEY }}") + .Destination("https://api.nuget.org/v3/index.json") } } }