ADotNet
ADotNet copied to clipboard
EXPOSURES: DotNetBuildTaskBuilder
Closes #40
I added two task builders in this PR to show a simple case and a more advanced case.
I could not remove the --no-restore
command option from the existing DotNetBuildTask
because that would break backwards compatibility.
So instead, I created a task builder which can be used with fluent syntax to specify optional parameters to the task.
For example:
new DotNetBuildTaskBuilder()
.Name("Build")
will generate the following YAML snippet:
- name: Build
run: dotnet build
As another example:
new DotNetBuildTaskBuilder()
.Name("Build")
.Restore(false)
will generate the following YAML snippet:
- name: Build
run: dotnet build --no-restore
Here's an example for the NuGetPushTaskBuilder
:
new NuGetPushTaskBuilder()
.Name("Publish")
.SearchPath(@"**\*.nupkg")
.ApiKey("${{ secrets.NUGET_API_KEY }}")
.Destination("https://api.nuget.org/v3/index.json")
will generate the following YAML snippet:
- name: Publish
run: dotnet nuget push "**\*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json"
The search path, API key, and destination parameters are optional, depending on the version of NuGet.exe being used.
I want to get feedback first before I continue down this path.
If I get approval, I will continue and add tests, validation, validation tests, and documentation, if needed.
Thank you for the code review.
I have resolved all the code review comments.
Should I continue and create the following tests?
- ADotNet.Tests.Unit.Models.Pipelines.GithubPipelines.DotNets.Tasks.Builders.DotNetBuildTaskBuilderTests a. ~~ShouldThrowValidationExceptionIfNameIsNotSet~~ I found out the name is not required b. ShouldIncludeNoRestoreIfRestoreIsFalse c. ShouldNotIncludeNoRestoreIfRestoreIsTrue
- ADotNet.Tests.Unit.Models.Pipelines.GithubPipelines.DotNets.Tasks.Builders.NuGetPushTaskBuilderTests a. ~~ShouldThrowValidationExceptionIfNameIsNotSet~~ I found out the name is not required b. ShouldIncludeSearchPathIfSet c. ShouldNotIncludeSearchPathIfNotSet d. ShouldIncludeApiKeyIfSet e. ShouldNotIncludeApiKeyIfNotSet f. ShouldIncludeDestinationIfSet g. ShouldNotIncludeDestinationIfNotSet
@icnocop this is good. We need to place this somewhere in the Exposers layers of this library. @tehwardy or @cjdutoit might have some additional thoughts here.
@elbekdeveloper feel free to chime in as well.
@cjdutoit do you have any feedback for us on this?
@hassanhabib / @icnocop sorry, I did not see there was a wait on me for this one. I like the fluent syntax.
First thoughts is that we should name the builders more closely to what we have now i.e. DotNetBuildTaskBuilder
should be renamed to GithubTask
so it is not confusing to make the transition and also so we could distinguish from other tasks AzureTask
/ AwsTask
if this ever gets extended that way.
Should we perhaps create separate issues so be can create all these builders from the top down to match a rough structure like this?
var githubPipeline = new GithubPipelineBuilder()
.Name(".Net")
.WithEvents(gitHubEventBuilders =>
{
gitHubEventBuilders.Add(new GitHubPushEventBuilder().Branches(...),
gitHubEventBuilders.Add(new GitHubPushEventBuilder().Branches(...)
})
.WithJobs(gitHubJobsBuilders =>
{
gitHubJobsBuilders.Build = new gitHubJobBuilder()
.RunsOn(BuildMachines.Windows2019)
.WithSteps(githubStepBuilders =>
{
githubStepBuilders.Add(new CheckoutTaskV2StepBuilder()),
githubStepBuilders.Add(new SetupDotNetTaskV1StepBuilder()),
githubStepBuilders.Add(new RestoreTaskStepBuilder()),
githubStepBuilders.Add(new DotNetBuildTaskStepBuilder()),
githubStepBuilders.Add(new TestTaskStepBuilder()),
githubStepBuilders.Add(new NugetDeployTaskStepBuilder()),
})
})
.Build();