Skip to content
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

EXPOSURES: DotNetBuildTaskBuilder #43

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
icnocop marked this conversation as resolved.
Show resolved Hide resolved
.gitignore = .gitignore
gitHubPipelines.yaml = gitHubPipelines.yaml
README.md = README.md
EndProjectSection
EndProject
Global
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ---------------------------------------------------------------------------
// 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 DotNetBuildTaskBuilder WithName(string name)
{
this.dotnetBuildTask.Name = name;

return this;
icnocop marked this conversation as resolved.
Show resolved Hide resolved
}

public DotNetBuildTaskBuilder WithRestore(bool restore = true)
{
this.dotnetBuildTask.Restore = restore;

return this;
}

public DotNetBuildTask Build()
{
if (this.dotnetBuildTask.Restore is false)
{
this.dotnetBuildTask.Run += " --no-restore";
}

return this.dotnetBuildTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// ---------------------------------------------------------------------------
// 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();
icnocop marked this conversation as resolved.
Show resolved Hide resolved
}

public NuGetPushTaskBuilder WithName(string name)
{
this.nugetPushTask.Name = name;

return this;
}

public NuGetPushTaskBuilder WithSearchPath(string searchPath)
{
this.nugetPushTask.SearchPath = searchPath;

return this;
}

public NuGetPushTaskBuilder WithApiKey(string apiKey)
{
this.nugetPushTask.ApiKey = apiKey;

return this;
}

public NuGetPushTaskBuilder WithDestination(string destination)
{
this.nugetPushTask.Destination = destination;

return this;
}

public 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public class DotNetBuildTask : GithubTask
{
[YamlMember(Order = 1)]
public string Run = "dotnet build --no-restore";

internal bool Restore { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
10 changes: 9 additions & 1 deletion AdoNet.Tests.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -175,7 +176,14 @@ static void Main(string[] args)
{
Name = "Provision",
Run = "dotnet run --project .\\OtripleS.Api.Infrastructure.Provision\\OtripleS.Web.Api.Infrastructure.Provision.csproj"
}
},

new NuGetPushTaskBuilder()
.WithName("Publish")
.WithSearchPath(@"**\*.nupkg")
.WithApiKey("${{ secrets.NUGET_API_KEY }}")
.WithDestination("https://api.nuget.org/v3/index.json")
.Build()
}
}
}
Expand Down