Skip to content

Commit 009f000

Browse files
authored
Merge pull request #149 from The-Standard-Organization/users/mabroukmahdhi/docuemtnation-fluent-api
DOCUMENTATION: Fluent API
2 parents 5b39330 + 23d07ff commit 009f000

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,57 @@ And finally, here's the result:
344344

345345
![image](https://user-images.githubusercontent.com/89320816/137255979-8e15772e-f3f7-48e3-bc57-8b6cf32c7a09.png)
346346

347+
## Fluent API Implementation
348+
The ADotNet library provides a fluent API (Currently only for GitHub Actions) to simplify the creation of pipelines in a declarative, strongly-typed manner. The fluent API makes it intuitive and convenient to define complex pipeline configurations without the need for YAML.
349+
350+
### Example for GitHub Actions
351+
Here's an example of how to create a GitHub Actions pipeline using the fluent API:
352+
353+
```csharp
354+
GitHubPipelineBuilder.CreateNewPipeline()
355+
.SetName("Github")
356+
.OnPush("main")
357+
.OnPullRequest("main")
358+
.AddJob("build", job => job
359+
.WithName("Build")
360+
.RunsOn(BuildMachines.WindowsLatest)
361+
.AddEnvironmentVariables(new Dictionary<string, string>
362+
{
363+
{ "AzureClientId", "${{ secrets.AZURECLIENTID }}" },
364+
{ "AzureTenantId", "${{ secrets.AZURETENANTID }}" },
365+
{ "AzureClientSecret", "${{ secrets.AZURECLIENTSECRET }}" },
366+
{ "AzureAdminName", "${{ secrets.AZUREADMINNAME }}" },
367+
{ "AzureAdminAccess", "${{ secrets.AZUREADMINACCESS }}" }
368+
})
369+
.AddCheckoutStep("Check Out")
370+
.AddSetupDotNetStep(
371+
version: "6.0.101",
372+
includePrerelease: true)
373+
.AddRestoreStep()
374+
.AddBuildStep()
375+
.AddGenericStep(
376+
name: "Provision",
377+
runCommand: "dotnet run --project .\\<PROJECT_DIRECTORY>\\<PROJECT_NAME>.csproj"))
378+
.SaveToFile("github-pipelines-2.yaml");
379+
```
380+
### Environment Variables Support:
381+
- Added methods to configure environment variables for jobs:
382+
```csharp
383+
job.AddEnvironmentVariable("AzureClientId", "${{ secrets.AZURECLIENTID }}")
384+
.AddEnvironmentVariables(new Dictionary<string, string>
385+
{
386+
{ "AzureClientId", "${{ secrets.AZURECLIENTID }}" },
387+
{ "AzureTenantId", "${{ secrets.AZURETENANTID }}" }
388+
});
389+
```
390+
391+
### Generic Task Builder:
392+
- Added support for custom tasks using `AddGenericStep`:
393+
```csharp
394+
job.AddGenericStep(
395+
name: "Provision",
396+
runCommand: "dotnet run --project ./Project.csproj");
397+
```
347398
## Some Odd Decisions
348399
I have intentionally limited some of the capabilities in this library to ensure any contributions go to this repository so everyone can benefit from the updates. For instance, I could've easily made selecting a virtual machine as a string input to allow for anyone to pass in whatever vm they need. But the problem with that is for those who will need the same thing and have to do the same research to find the right VM for their build.
349400

0 commit comments

Comments
 (0)