A starter development kit to script your CI/CD using Nuke.
⭐ If you like or are using this project please give it a star. Thanks! ⭐
This project adheres to semantic versioning. Major version zero (0.y.z) is for initial development.
Anything MAY change at any time.
The public API SHOULD NOT be considered stable.
Most of the time, to set up a CI/CD for your .NET project, you have two options :
This approach is nice and helpful to get started. But most of the time, the history of changes made to the pipeline is separated from the history of the code base.
Most of the time in YAML, the file that describes the steps required to build a project are providers specific. So even though you can write YAML, knowing how to write an Azure DevOps pipeline does not really help when it comes to writing a pipeline for GitHub Actions.
Nuke is a library written by Matthias Koch that helps to create builds.
This project offers an opinionated way at writing pipelines by giving a set of components (more on that later) with the following benefits :
- no need to go your code management tool to set up your project CI/CD.
- no more YAML file : yeah YAML is great but the tooling is not great and the structure itself is error-prone.
- it's just a C# project that every team member can contribute to !
- it sits right with your source code so that each change to the pipeline is just a commit into your codebase.
To get started you'll have to :
- install Nuke.GlobalTool dotnet tool (locally or globally)
- run
dotnet nuke :setup
to set up your pipeline project - replace the
Nuke.Common
nuget dependency with Candoumbe.Pipelines
From this point, you should be able to customize your pipeline by adding [components] \o/.
This library is built on top of Nuke, an open source library started by Matthias Koch. It provides a set of components that, when added to a pipeline, bring clever default features.
Components are C# interfaces that come with a default / opinionated implementation. They are grouped in namespaces which correspond to their main task.
Candoumbe.Pipelines.Components
: contains the core components needed for general required tasks.
Let's say you have the following Build.cs
class as your starting pipeline
class Build : NukeBuild
{
public static void Main() => Execute<Build>(x => x.Compile());
Target Compile => _ => _
.Executes(() => {
// Code omitted for brievity
});
}
you can get rid of the Compile
property and use the ICompile component instead.
class Build : NukeBuild, ICompile
{
public static void Main() => Execute<Build>(x => ((ICompile)x).Compile());
}
In the example above, the build pipeline benefits from the ICompile component which comes with a default implementation of the Compile
target.
This workspace contains components related to branching strategies and providing tools that can help normalize how teams works.
IGitFlow and IGitHubFlow are two main components that helps handle branching strategy locally.
Some components are used to set the workflow to use throughout a repository and streamline the work of a developer and a team.
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart
A((start)) --> B[["./build feature"]]
A -->O[["./build hotfix"]]
O --> P{is on 'hotfix' branch ?}
P -- yes --> finish-hotfix
P -- no --> Q{{computes semver}}
Q --> R{{creates 'hotfix/<semver>' branch}}
R --> S[work on your hotfix]
S --> T{Are you done}
T -- yes --> O
T -- not yet --> S
B --> C{is on 'feature/*' branch ?}
C -- yes --> finish-feature
C -- no --> D[Creates a new feature/* branch]
D --> E[Work on your feature]
E --> F{Are you done ?}
F --yes --> B
F -- not yet --> E
subgraph finish-feature[Finish feature]
N{{Merges changes to develop branch}}
end
subgraph finish-hotfix[Finish hotfix]
Y{{Merges changes to main branch}}
end
finish-hotfix --> Z
finish-feature --> Z((end))
using IGitFlowWithPullRequest or IGitHubFlowWithPullRequest components, the library can automagically create a pull request once you're done working on your feature / hotfix.
class Build : NukeBuild, IGitFlowWithPullRequest
{
public static void Main() => Execute<Build>(x => x.Compile());
Target Compile => _ => _
.Executes(() => {
// Code omitted for brievity
});
}
or
class Build : NukeBuild, IGitHubFlowWithPullRequest
{
public static void Main() => Execute<Build>(x => x.Compile());
Target Compile => _ => _
.Executes(() => {
// Code omitted for brievity
});
}
depending on the workflow that better suits you.
To start working on a release, simply call ./build.cmd release
and your pipeline will trigger the appropriate commands to get you started.
Calling ./build.cmd release
from the release branch created will trigger
the appropriate command to finish your release.
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart
A((start)) --> B["./build release"]
B --> C{is on 'release/*' branch ?}
C -- no --> create-branch
subgraph create-branch[Create a release branch]
G{{computes semver version}} --> H{{create release/version branch}}
end
create-branch --> D[Work on your release]
C -- yes --> finish-release
D --> E{Are you done ?}
E --yes --> B
E -- not yet --> D
subgraph finish-release[Finish release]
J[Update changelog] --> K{{validate changelog modifications}}
K --> M{{create tag}}
M --> N{{Merges changes to main branch}}
N --> O{{Merges changes to develop branch}}
end
finish-release --> Z((end))
Contains classes required to push nuget packages to repositories.
Contains classes and components needed to interact with GitHub repositories (creating pull requests).
Contains classes and components needed to build and push docker images.
Stryker
to run mutation tests.
You can refer to Nuke's documentation to see how to reference required tools.
You can contribute by opening an issue or submitting a feature request.
PRs are welcome, check out the contribution guidelines if you want to contribute to this project !
- Matthias Koch for the marvelous Nuke library. This project would never exist without its work.