Skip to content

Commit 287b20f

Browse files
committed
initial commit
0 parents  commit 287b20f

31 files changed

+1691
-0
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "nuget"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"

.github/workflows/build.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: windows-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 1
21+
22+
- name: Restore NuGet packages for src/AggregateConfigBuildTask.sln
23+
run: dotnet restore src/AggregateConfigBuildTask.sln
24+
25+
- name: Build AggregateConfigBuildTask solution in Release mode
26+
run: dotnet build src/AggregateConfigBuildTask.sln --configuration Release -warnaserror
27+
28+
- name: Run tests for AggregateConfigBuildTask solution
29+
run: dotnet test src/AggregateConfigBuildTask.sln --configuration Release -warnaserror
30+
31+
- name: Upload NuGetPackage artifact
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: NuGetPackage
35+
path: src/Task/bin/Release/AggregateConfigBuildTask.1.0.0.nupkg
36+
37+
integration_tests:
38+
needs: build
39+
strategy:
40+
matrix:
41+
os: [ubuntu-latest, windows-latest]
42+
runs-on: ${{ matrix.os }}
43+
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 1
49+
50+
- name: Setup .NET Core SDK
51+
uses: actions/setup-dotnet@v4
52+
with:
53+
dotnet-version: '8.0.x'
54+
55+
- name: Download NuGetPackage artifact
56+
uses: actions/download-artifact@v4
57+
with:
58+
name: NuGetPackage
59+
path: ./nuget/local
60+
61+
- name: Add local NuGet source
62+
run: dotnet nuget add source ${{ github.workspace }}/nuget/local --name AggregateConfigBuildTask
63+
64+
- name: Restore IntegrationTests with custom AggregateConfigBuildTask package
65+
run: dotnet restore test/IntegrationTests/IntegrationTests.csproj
66+
67+
- name: Build IntegrationTests in Release mode
68+
run: dotnet build test/IntegrationTests/IntegrationTests.csproj --configuration Release -warnaserror
69+
70+
- name: Run IntegrationTests
71+
run: dotnet test test/IntegrationTests/IntegrationTests.csproj --configuration Release -warnaserror
72+
73+
- name: Upload integration results artifact
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: IntegrationTestResults-${{ matrix.os }}
77+
path: test/IntegrationTests/out/

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/bin/**
2+
**/obj/**
3+
**/out/
4+
**/.vs/**
5+
*.nupkg
6+
output*.json

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 richardsondev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# AggregateConfigBuildTask
2+
3+
**AggregateConfigBuildTask** is an MSBuild task that aggregates and transforms configuration files (such as YAML) into more consumable formats like JSON, Azure ARM template parameters, or YAML itself during the build process.
4+
5+
## Links
6+
7+
* NuGet.org: https://www.nuget.org/packages/AggregateConfigBuildTask
8+
* GitHub: https://github.com/richardsondev/AggregateConfigBuildTask
9+
10+
## Features
11+
12+
- Merge multiple YAML configuration files into a single output format (JSON, Azure ARM parameters, or YAML).
13+
- Support for injecting custom metadata (e.g., `ResourceGroup`, `Environment`) into the output.
14+
- Optionally include the source file name in each configuration entry.
15+
- Embed output files as resources in the assembly for easy inclusion in your project.
16+
17+
## Installation
18+
19+
To install the `AggregateConfigBuildTask` NuGet package, run the following command:
20+
21+
```bash
22+
dotnet add package AggregateConfigBuildTask
23+
```
24+
25+
Alternatively, add the following line to your `.csproj` file:
26+
27+
```xml
28+
<PackageReference Include="AggregateConfigBuildTask" Version="1.0.0" />
29+
```
30+
31+
## Usage
32+
33+
### Basic Example
34+
35+
In your `.csproj` file, use the task to aggregate YAML files and output them in a specific format. Here’s an example of aggregating YAML files and generating JSON output:
36+
37+
```xml
38+
<Project Sdk="Microsoft.NET.Sdk">
39+
40+
<ItemGroup>
41+
<PackageReference Include="AggregateConfigBuildTask" Version="1.0.0" />
42+
</ItemGroup>
43+
44+
<Target Name="AggregateConfigs" BeforeTargets="PrepareForBuild">
45+
<ItemGroup>
46+
<AdditionalProperty Include="ResourceGroup=TestRG" />
47+
<AdditionalProperty Include="Environment=Production" />
48+
</ItemGroup>
49+
50+
<AggregateConfigBuildTask
51+
InputDirectory="Configs"
52+
OutputFile="$(MSBuildProjectDirectory)\out\output.json"
53+
AddSourceProperty="true"
54+
OutputType="Json"
55+
AdditionalProperties="@(AdditionalProperty)" />
56+
</Target>
57+
58+
</Project>
59+
```
60+
61+
In this example:
62+
- The `Configs` directory contains the YAML files to be aggregated.
63+
- The output will be generated as `out/output.json`.
64+
- The `AddSourceProperty` flag adds the source file name to each configuration entry.
65+
- The `AdditionalProperties` are injected into the top-level of the output as custom metadata.
66+
67+
### ARM Template Parameters Output Example
68+
69+
You can also generate Azure ARM template parameters. Here's how to modify the configuration to output in the ARM parameter format:
70+
71+
```xml
72+
<Project Sdk="Microsoft.NET.Sdk">
73+
74+
<ItemGroup>
75+
<PackageReference Include="AggregateConfigBuildTask" Version="1.0.0" />
76+
</ItemGroup>
77+
78+
<Target Name="AggregateConfigsForARM" BeforeTargets="PrepareForBuild">
79+
<ItemGroup>
80+
<AdditionalProperty Include="ResourceGroup=TestRG" />
81+
<AdditionalProperty Include="Environment=Production" />
82+
</ItemGroup>
83+
84+
<AggregateConfigBuildTask
85+
InputDirectory="Configs"
86+
OutputFile="$(MSBuildProjectDirectory)\out\output.parameters.json"
87+
OutputType="ArmParameter"
88+
AdditionalProperties="@(AdditionalProperty)" />
89+
</Target>
90+
91+
</Project>
92+
```
93+
94+
### YAML Output Example
95+
96+
You can also output the aggregated configuration back into YAML format:
97+
98+
```xml
99+
<Project Sdk="Microsoft.NET.Sdk">
100+
101+
<ItemGroup>
102+
<PackageReference Include="AggregateConfigBuildTask" Version="1.0.0" />
103+
</ItemGroup>
104+
105+
<Target Name="AggregateConfigsToYAML" BeforeTargets="PrepareForBuild">
106+
<ItemGroup>
107+
<AdditionalProperty Include="ResourceGroup=TestRG" />
108+
<AdditionalProperty Include="Environment=Production" />
109+
</ItemGroup>
110+
111+
<AggregateConfigBuildTask
112+
InputDirectory="Configs"
113+
OutputFile="$(MSBuildProjectDirectory)\out\output.yaml"
114+
OutputType="Yaml"
115+
AdditionalProperties="@(AdditionalProperty)" />
116+
</Target>
117+
118+
</Project>
119+
```
120+
121+
### Embedding Output Files as Resources
122+
123+
You can embed the output files (such as the generated JSON) as resources in the assembly. This allows them to be accessed from within your code as embedded resources.
124+
125+
```xml
126+
<Project Sdk="Microsoft.NET.Sdk">
127+
128+
<ItemGroup>
129+
<PackageReference Include="AggregateConfigBuildTask" Version="1.0.0" />
130+
</ItemGroup>
131+
132+
<Target Name="AggregateConfigs" BeforeTargets="PrepareForBuild">
133+
<ItemGroup>
134+
<AdditionalProperty Include="ResourceGroup=TestRG" />
135+
<AdditionalProperty Include="Environment=Production" />
136+
</ItemGroup>
137+
138+
<AggregateConfigBuildTask
139+
InputDirectory="Configs"
140+
OutputFile="$(MSBuildProjectDirectory)\out\output.json"
141+
OutputType="Json"
142+
AdditionalProperties="@(AdditionalProperty)" />
143+
</Target>
144+
145+
<!-- Embed output.json as a resource in the assembly -->
146+
<ItemGroup>
147+
<EmbeddedResource Include="$(MSBuildProjectDirectory)\out\output.json" />
148+
</ItemGroup>
149+
150+
</Project>
151+
```
152+
153+
In this example:
154+
- The generated output file `output.json` is embedded in the resulting assembly as a resource.
155+
- You can access this resource programmatically using the `System.Reflection` API.
156+
157+
## Parameters
158+
159+
- **InputDirectory** *(required)*: The directory containing YAML files to be aggregated.
160+
- **OutputFile** *(required)*: The path to the output file. Can be a JSON, ARM parameter, or YAML file.
161+
- **AddSourceProperty** *(optional, default=false)*: Adds a `source` property to each object in the output, indicating the YAML file it originated from.
162+
- **OutputType** *(required)*: Determines the output format. Supported values:
163+
- `Json`: Outputs a regular JSON file.
164+
- `ArmParameter`: Outputs an Azure ARM template parameter file.
165+
- `Yaml`: Outputs a YAML file.
166+
- **AdditionalProperties** *(optional)*: A collection of custom top-level properties to inject into the final output. Use the `ItemGroup` syntax to pass key-value pairs.
167+
168+
## Example YAML Input
169+
170+
Assume you have the following YAML files in the `Configs` directory:
171+
172+
```yaml
173+
resources:
174+
- id: "Resource1"
175+
type: "Compute"
176+
description: "Main compute resource"
177+
```
178+
179+
```yaml
180+
resources:
181+
- id: "Resource2"
182+
type: "Storage"
183+
description: "Storage resource"
184+
```
185+
186+
### Output JSON Example
187+
188+
```json
189+
{
190+
"resources": [
191+
{
192+
"id": "Resource1",
193+
"type": "Compute",
194+
"description": "Main compute resource",
195+
"source": "file1"
196+
},
197+
{
198+
"id": "Resource2",
199+
"type": "Storage",
200+
"description": "Storage resource",
201+
"source": "file2"
202+
}
203+
],
204+
"ResourceGroup": "TestRG",
205+
"Environment": "Production"
206+
}
207+
```
208+
209+
### ARM Parameter Output Example
210+
211+
```json
212+
{
213+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
214+
"contentVersion": "1.0.0.0",
215+
"parameters": {
216+
"resources": {
217+
"value": [
218+
{
219+
"id": "Resource1",
220+
"type": "Compute",
221+
"description": "Main compute resource",
222+
"source": "file1"
223+
},
224+
{
225+
"id": "Resource2",
226+
"type": "Storage",
227+
"description": "Storage resource",
228+
"source": "file2"
229+
}
230+
]
231+
},
232+
"ResourceGroup": {
233+
"value": "TestRG"
234+
},
235+
"Environment": {
236+
"value": "Production"
237+
}
238+
}
239+
}
240+
```
241+
242+
## License
243+
244+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
245+
246+
## Contributing
247+
248+
Contributions are welcome! Feel free to submit issues or pull requests on [GitHub](https://github.com/richardsondev/AggregateConfigBuildTask).

src/.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# CS1591: Missing XML comment for publicly visible type or member
4+
dotnet_diagnostic.CS1591.severity = suggestion

0 commit comments

Comments
 (0)