Skip to content

EXPOSERS: Fluent GitHub Pipeline Builder#147

Merged
cjdutoit merged 7 commits intomainfrom
users/mabroukmahdhi/exposers-fluent-pipeline-builder
Jan 27, 2025
Merged

EXPOSERS: Fluent GitHub Pipeline Builder#147
cjdutoit merged 7 commits intomainfrom
users/mabroukmahdhi/exposers-fluent-pipeline-builder

Conversation

@mabroukmahdhi
Copy link
Contributor

closes #146

ShouldSetPipelineName -> PASS
ShouldAddPushTrigger -> PASS
ShouldAddPullRequestTrigger -> PASS
ShouldAddJobToPipeline -> PASS
ShouldSavePipelineToFile -> PASS
@mabroukmahdhi mabroukmahdhi self-assigned this Jan 27, 2025
@github-actions github-actions bot added the EXPOSERS The exposers category label Jan 27, 2025
@mabroukmahdhi
Copy link
Contributor Author

Summary

This pull request introduces a comprehensive refactor and feature set for the GitHubPipelineBuilder class, making it more extensible, testable, and user-friendly. The key features include:

  • Dependency Injection Support: Replaced the direct dependency on ADotNetClient with an interface IADotNetClient, enabling easier testing and extensibility.
  • Fluent API Enhancements:
    • Added support for defining environment variables in pipeline jobs.
    • Added a generic task builder method to allow custom tasks.
  • Interface Implementation: Updated the ADotNetClient class to implement the IADotNetClient interface.
  • Code Refactor: Refactored methods to improve readability and maintainability.
  • Improved Testing: Updated unit tests to mock the IADotNetClient interface and validate behavior.

Features

Fluent API Enhancements

  1. Environment Variables Support:

    • Added methods to configure environment variables for jobs:
      job.AddEnvironmentVariable("AzureClientId", "${{ secrets.AZURECLIENTID }}")
         .AddEnvironmentVariables(new Dictionary<string, string>
         {
             { "AzureClientId", "${{ secrets.AZURECLIENTID }}" },
             { "AzureTenantId", "${{ secrets.AZURETENANTID }}" }
         });
  2. Generic Task Builder:

    • Added support for custom tasks using AddGenericStep:
      job.AddGenericStep(
          name: "Provision",
          runCommand: "dotnet run --project ./Project.csproj");
  3. Improved Pipeline Definition:

    • Simplified the creation of pipelines with triggers, jobs, and tasks:
      GitHubPipelineBuilder.CreateNewPipeline()
          .SetName("Github")
          .OnPush("master")
          .OnPullRequest("master")
          .AddJob("build", job => job
              .WithName("Build")
              .RunsOn(BuildMachines.WindowsLatest)
              .AddEnvironmentVariables(new Dictionary<string, string>
              {
                  { "AzureClientId", "${{ secrets.AZURECLIENTID }}" },
                  { "AzureTenantId", "${{ secrets.AZURETENANTID }}" },
                  { "AzureClientSecret", "${{ secrets.AZURECLIENTSECRET }}" },
                  { "AzureAdminName", "${{ secrets.AZUREADMINNAME }}" },
                  { "AzureAdminAccess", "${{ secrets.AZUREADMINACCESS }}" }
              })
              .AddCheckoutStep("Check Out")
              .AddSetupDotNetStep(
                  version: "6.0.101",
                  includePrerelease: true)
              .AddRestoreStep()
              .AddBuildStep()
              .AddGenericStep(
                  name: "Provision",
                  runCommand: "dotnet run --project .\OtripleS.Api.Infrastructure.Provision\OtripleS.Web.Api.Infrastructure.Provision.csproj"))
          .SaveToFile("github-pipelines-2.yaml");

Interface Implementation

  • Used IADotNetClient interface to abstract the ADotNetClient class.
  • Updated ADotNetClient to implement this interface without changing existing functionality.

Dependency Injection

  • Refactored GitHubPipelineBuilder to accept IADotNetClient via dependency injection, enabling mocking in unit tests and better modularity.

@mabroukmahdhi mabroukmahdhi marked this pull request as ready for review January 27, 2025 18:05
@cjdutoit cjdutoit merged commit 5b39330 into main Jan 27, 2025
5 checks passed
@cjdutoit cjdutoit deleted the users/mabroukmahdhi/exposers-fluent-pipeline-builder branch January 27, 2025 18:39
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.

EXPOSURES: Fluent GitHub Pipeline Builder

2 participants