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

Conversation

icnocop
Copy link

@icnocop icnocop commented Mar 26, 2023

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
Copy link
Author

icnocop commented Mar 26, 2023

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
Copy link
Author

icnocop commented Mar 27, 2023

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 icnocop marked this pull request as ready for review March 27, 2023 01:56
@icnocop icnocop force-pushed the users/icnocop/exposers-dotnetbuildtaskbuilder-build branch 2 times, most recently from dceb79c to 46a4dba Compare March 27, 2023 03:54
@icnocop icnocop force-pushed the users/icnocop/exposers-dotnetbuildtaskbuilder-build branch from 46a4dba to 991a334 Compare March 27, 2023 03:57
@icnocop
Copy link
Author

icnocop commented Mar 27, 2023

Thank you for the code review.

I have resolved all the code review comments.

@icnocop
Copy link
Author

icnocop commented Mar 27, 2023

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

@hassanhabib
Copy link
Member

hassanhabib commented Mar 27, 2023

@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
Copy link
Member

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

Refactored fluent methods to avoid having to prefix methods with With
@cjdutoit
Copy link
Collaborator

@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 cjdutoit added the EXPOSERS The exposers category label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EXPOSERS The exposers category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optionally specify "--no-restore" in DotNetBuildTask
3 participants