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 3 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,41 @@
// ---------------------------------------------------------------------------
// 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()
{
dotnetBuildTask = new DotNetBuildTask
icnocop marked this conversation as resolved.
Show resolved Hide resolved
icnocop marked this conversation as resolved.
Show resolved Hide resolved
{
Run = "dotnet build"
};
}

public DotNetBuildTaskBuilder WithName(string name)
{
dotnetBuildTask.Name = name;
return this;
icnocop marked this conversation as resolved.
Show resolved Hide resolved
}

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

public DotNetBuildTask Build()
{
if (!dotnetBuildTask.Restore)
icnocop marked this conversation as resolved.
Show resolved Hide resolved
dotnetBuildTask.Run += " --no-restore";

return dotnetBuildTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// ---------------------------------------------------------------------------
// 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()
{
nugetPushTask = new NuGetPushTask();
}

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

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

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

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

public NuGetPushTask Build()
{
if (!string.IsNullOrEmpty(nugetPushTask.SearchPath))
nugetPushTask.Run += $" \"{nugetPushTask.SearchPath}\"";

if (!string.IsNullOrEmpty(nugetPushTask.ApiKey))
nugetPushTask.Run += $" --api-key {nugetPushTask.ApiKey}";

if (!string.IsNullOrEmpty(nugetPushTask.Destination))
nugetPushTask.Run += $" --source \"{nugetPushTask.Destination}\"";

return 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,22 @@
// ---------------------------------------------------------------------------
// 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; }

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