ADotNet icon indicating copy to clipboard operation
ADotNet copied to clipboard

EXPOSURES: DotNetBuildTaskBuilder

Open icnocop opened this issue 1 year ago • 7 comments

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

icnocop avatar Mar 26 '23 23:03 icnocop

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.

icnocop avatar Mar 26 '23 23:03 icnocop

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.

icnocop avatar Mar 27 '23 00:03 icnocop

Thank you for the code review.

I have resolved all the code review comments.

icnocop avatar Mar 27 '23 04:03 icnocop

Should I continue and create the following tests?

  1. ADotNet.Tests.Unit.Models.Pipelines.GithubPipelines.DotNets.Tasks.Builders.DotNetBuildTaskBuilderTests a. ~~ShouldThrowValidationExceptionIfNameIsNotSet~~ I found out the name is not required b. ShouldIncludeNoRestoreIfRestoreIsFalse c. ShouldNotIncludeNoRestoreIfRestoreIsTrue
  2. 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 avatar Mar 27 '23 05:03 icnocop

@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.

hassanhabib avatar Mar 27 '23 07:03 hassanhabib

@cjdutoit do you have any feedback for us on this?

hassanhabib avatar Mar 29 '23 18:03 hassanhabib

@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();

cjdutoit avatar May 11 '23 12:05 cjdutoit