Skip to content

thomhurst/ModularPipelines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ModularPipelines

Define your pipeline in .NET! Strong types, intellisense, parallelisation, and the entire .NET ecosystem at your fingertips.

nuget

Nuget GitHub Workflow Status (with event) GitHub last commit (branch) Codacy Badge CodeFactor License Codacy Badge codecov

https://thomhurst.github.io/ModularPipelines

Features

  • Parallel execution
  • Dependency management
  • Familiar C# code
  • Ability to debug pipelines
  • Ability to run pipelines locally, even creating versions for setting up local development
  • Strong typing, where different modules/steps can pass data to one another
  • Dependency collision detection - Don't worry about accidentally making two modules dependent on each other
  • Numerous helpers to do things like: Search files, check checksums, (un)zip folders, download files, install files, execute CLI commands, hash data, and more
  • Easy to Skip or Ignore Failures for each individual module by passing in custom logic
  • Hooks that can run before and/or after modules
  • Pipeline requirements - Validate your requirements are met before executing your pipeline, such as a Linux operating system
  • Easy to use File and Folder classes, that can search, read, update, delete and more
  • Source controlled pipelines
  • Build agent agnostic - Can easily move to a different build system without completely recreating your pipeline
  • No need to learn new syntaxes such as YAML defined pipelines
  • Strongly typed wrappers around command line tools
  • Utilise existing .NET libraries
  • Secret obfuscation
  • Grouped logging, and the ability to extend sources by adding to the familiar ILogger
  • Run based on categories
  • Easy to read exceptions
  • Dynamic console progress reporting (if the console supports interactive mode)
  • Pretty results table

Available Modules

Package Description Version
ModularPipelines Write your pipelines in C#! nuget
ModularPipelines.AmazonWebServices Helpers for interacting with Amazon Web Services. nuget
ModularPipelines.Azure Helpers for interacting with Azure. nuget
ModularPipelines.Azure.Pipelines Helpers for interacting with Azure Pipeline agents. nuget
ModularPipelines.Chocolatey Helpers for interacting with the Chocolatey CLI. nuget
ModularPipelines.Cmd Helpers for interacting with the Windows cmd process. nuget
ModularPipelines.Docker Helpers for interacting with the Docker CLI. nuget
ModularPipelines.DotNet Helpers for interacting with dotnet CLI. nuget
ModularPipelines.Email Helpers for sending emails. nuget
ModularPipelines.Ftp Helpers for downloading and uploading via FTP. nuget
ModularPipelines.Git Helpers for interacting with git. nuget
ModularPipelines.GitHub Helpers for interacting with GitHub Actions build agents. nuget
ModularPipelines.Google Helpers for interacting with the Google gcloud CLI. nuget
ModularPipelines.Helm Helpers for interacting with Helm CLI. nuget
ModularPipelines.Kubernetes Helpers for interacting with kubectl CLI. nuget
ModularPipelines.MicrosoftTeams Helpers for sending Microsoft Teams cards. nuget
ModularPipelines.Node Helpers for interacting with node / npm CLI. nuget
ModularPipelines.Slack Helpers for sending Slack cards. nuget
ModularPipelines.TeamCity Helpers for interacting with TeamCity build agents. nuget
ModularPipelines.Terraform Helpers for interacting with Terraform CLI. nuget
ModularPipelines.WinGet Helpers for interacting with the Windows Package Manager. nuget
ModularPipelines.Yarn Helpers for interacting with Yarn CLI. nuget

Getting Started

If you want to see how to get started, or want to know more about ModularPipelines, read the Documentation here

Console Progress

image

Results

image

How does this compare to Cake / Nuke

  • Strong types! You have complete control over what data, and what shape of data to pass around from and to different modules
  • No external tooling is required. Pipelines are run with a simple dotnet run
  • Full dependency injection support for your services
  • Similar and familiar setup to frameworks like ASP.NET Core
  • Real C# - Whereas frameworks like cake are a scripted form of C#
  • Parallelism - Work will run concurrently unless it is dependent on something else
  • The style of writing pipelines is very different - Work is organised into separate module classes, keeping code organised and more closely following SRP than having all your work in one main class. This also helps multiple contributors avoid things like merge conflicts

Code Examples

Program.cs - Main method

await PipelineHostBuilder.Create()
    .ConfigureAppConfiguration((context, builder) =>
    {
        builder.AddJsonFile("appsettings.json")
            .AddUserSecrets<Program>()
            .AddEnvironmentVariables();
    })
    .ConfigureServices((context, collection) =>
    {
        collection.Configure<NuGetSettings>(context.Configuration.GetSection("NuGet"));
        collection.Configure<PublishSettings>(context.Configuration.GetSection("Publish"));
        collection.AddSingleton<ISomeService1, SomeService1>();
        collection.AddTransient<ISomeService2, SomeService2>();
    })
    .AddModule<FindNugetPackagesModule>()
    .AddModule<UploadNugetPackagesModule>()
    .ExecutePipelineAsync();

Custom Modules

public class FindNugetPackagesModule : Module<FileInfo>
{
    protected override Task<List<File>?> ExecuteAsync(IPipelineContext context, CancellationToken cancellationToken)
    {
        return context.Git()
            .RootDirectory
            .GetFiles(path => path.Extension is ".nupkg")
            .ToList()
            .AsTask();
    }
}
[DependsOn<FindNugetPackagesModule>]
public class UploadNugetPackagesModule : Module<FileInfo>
{
    private readonly IOptions<NuGetSettings> _nugetSettings;

    public UploadNugetPackagesModule(IOptions<NuGetSettings> nugetSettings)
    {
        _nugetSettings = nugetSettings;
    }

    protected override async Task<CommandResult?> ExecuteAsync(IPipelineContext context, CancellationToken cancellationToken)
    {
        var nugetFiles = await GetModule<FindNugetPackagesModule>();

        return await nugetFiles.Value!
            .SelectAsync(async nugetFile => await context.DotNet().Nuget.Push(new DotNetNugetPushOptions
            {
                Path = nugetFile,
                Source = "https://api.nuget.org/v3/index.json",
                ApiKey = _nugetSettings.Value.ApiKey!,
            }, cancellationToken), cancellationToken: cancellationToken)
            .ProcessOneAtATime();
    }
}

Breaking changes

While I will try to limit breaking changes, there may be some changes within minor versions. These will be noted on release notes.