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 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.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,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;
icnocop marked this conversation as resolved.
Show resolved Hide resolved
}

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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
icnocop marked this conversation as resolved.
Show resolved Hide resolved

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;
}
}
}
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; }
}
}
9 changes: 8 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,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")
}
}
}
Expand Down