Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ jobs:
run: dotnet build src/AggregateConfigBuildTask.sln --configuration Release -warnaserror -p:Version=${{ steps.get_version.outputs.VERSION }}

- name: Run tests for AggregateConfigBuildTask solution
run: dotnet test src/AggregateConfigBuildTask.sln --configuration Release -warnaserror -p:Version=${{ steps.get_version.outputs.VERSION }}
run: dotnet test src/AggregateConfigBuildTask.sln --configuration Release -warnaserror -p:Version=${{ steps.get_version.outputs.VERSION }} -p:CollectCoverage=true

- name: Upload NuGetPackage artifact
uses: actions/upload-artifact@v4
with:
name: NuGetPackage
path: src/Task/bin/Release/AggregateConfigBuildTask.${{ steps.get_version.outputs.VERSION }}.nupkg
path: |
src/Task/bin/Release/AggregateConfigBuildTask.${{ steps.get_version.outputs.VERSION }}.nupkg
src/Task/bin/Release/AggregateConfigBuildTask.${{ steps.get_version.outputs.VERSION }}.snupkg

integration_tests:
needs: build
Expand Down Expand Up @@ -89,7 +91,7 @@ jobs:
run: dotnet build test/IntegrationTests.sln --configuration Release -warnaserror -p:Version=${{ needs.build.outputs.VERSION }}

- name: Run IntegrationTests
run: dotnet test test/IntegrationTests.sln --configuration Release -warnaserror -p:Version=${{ needs.build.outputs.VERSION }}
run: dotnet test test/IntegrationTests.sln --configuration Release -warnaserror -p:Version=${{ needs.build.outputs.VERSION }} -p:CollectCoverage=true

- name: Upload integration results artifact
uses: actions/upload-artifact@v4
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ dotnet add package AggregateConfigBuildTask
Alternatively, add the following line to your `.csproj` file:

```xml
<PackageReference Include="AggregateConfigBuildTask" Version="{latest}">
<PrivateAssets>all</PrivateAssets>
<ExcludeAssets>native;contentFiles;analyzers;runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="AggregateConfigBuildTask" Version="{latest}" />
```

`{latest}` can be found [here](https://www.nuget.org/packages/AggregateConfigBuildTask#versions-body-tab).
Expand Down
1 change: 1 addition & 0 deletions src/AggregateConfigBuildTask.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{29D0AE56-C184-4741-824F-521198552928}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Packages.props = Directory.Packages.props
EndProjectSection
EndProject
Global
Expand Down
1 change: 1 addition & 0 deletions src/Contracts/Contracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Contracts/InputOutputEnums.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AggregateConfig.Contracts
namespace AggregateConfigBuildTask.Contracts
{
public enum OutputTypeEnum
{
Expand Down
30 changes: 30 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<!-- Build packages-->
<ItemGroup>
<PackageVersion Include="Microsoft.Build.Framework" Version="17.11.4" PrivateAssets="all" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.11.4" PrivateAssets="all" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
</ItemGroup>
<!-- Runtime packages -->
<ItemGroup>
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" PrivateAssets="all" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" PrivateAssets="all" />
<PackageVersion Include="YamlDotNet" Version="16.1.0" PrivateAssets="all" GeneratePathProperty="true" />
<PackageVersion Include="YamlDotNet.System.Text.Json" Version="1.5.0" PrivateAssets="all" />
</ItemGroup>
<!-- Test packages -->
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>
<!-- Global packages -->
<ItemGroup>
<GlobalPackageReference Include="ReferenceTrimmer" Version="3.3.6" />
</ItemGroup>
</Project>
74 changes: 18 additions & 56 deletions src/Task/AggregateConfig.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using AggregateConfig.Contracts;
using AggregateConfig.FileHandlers;
using AggregateConfigBuildTask;
using AggregateConfigBuildTask.Contracts;
using AggregateConfigBuildTask.FileHandlers;
using Microsoft.Build.Framework;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Task = Microsoft.Build.Utilities.Task;

[assembly: InternalsVisibleTo("AggregateConfig.Tests.UnitTests")]

namespace AggregateConfig
namespace AggregateConfigBuildTask
{
public class AggregateConfig : Task
{
Expand Down Expand Up @@ -46,8 +44,7 @@ public override bool Execute()
{
try
{
bool hasError = false;
JsonElement? finalResult = null;
EmitHeader();

OutputFile = Path.GetFullPath(OutputFile);

Expand All @@ -74,48 +71,7 @@ public override bool Execute()
fileSystem.CreateDirectory(directoryPath);
}

var expectedExtensions = FileHandlerFactory.GetExpectedFileExtensions(inputType);
var files = fileSystem.GetFiles(InputDirectory, "*.*")
.Where(file => expectedExtensions.Contains(Path.GetExtension(file).ToLower()))
.ToList();

foreach (var file in files)
{
Log.LogMessage(MessageImportance.High, "- Found file {0}", file);

IInputReader outputWriter;
try
{
outputWriter = FileHandlerFactory.GetInputReader(fileSystem, inputType);
}
catch (ArgumentException ex)
{
hasError = true;
Log.LogError("No reader found for file {0}: {1} Stacktrace: {2}", file, ex.Message, ex.StackTrace);
continue;
}

JsonElement fileData;
try
{
fileData = outputWriter.ReadInput(file);
}
catch (Exception ex)
{
hasError = true;
Log.LogError("Could not parse {0}: {1}", file, ex.Message);
Log.LogErrorFromException(ex, true, true, file);
continue;
}

// Merge the deserialized object into the final result
finalResult = ObjectManager.MergeObjects(finalResult, fileData, file, AddSourceProperty);
}

if (hasError)
{
return false;
}
var finalResult = ObjectManager.MergeFileObjects(InputDirectory, inputType, AddSourceProperty, fileSystem, Log).GetAwaiter().GetResult();

if (finalResult == null)
{
Expand All @@ -124,11 +80,7 @@ public override bool Execute()
}

var additionalPropertiesDictionary = JsonHelper.ParseAdditionalProperties(AdditionalProperties);
if (!ObjectManager.InjectAdditionalProperties(ref finalResult, additionalPropertiesDictionary))
{
Log.LogError("Additional properties could not be injected since the top-level is not a JSON object.");
return false;
}
finalResult = ObjectManager.InjectAdditionalProperties(finalResult, additionalPropertiesDictionary, Log).GetAwaiter().GetResult();

var writer = FileHandlerFactory.GetOutputWriter(fileSystem, outputType);
writer.WriteOutput(finalResult, OutputFile);
Expand All @@ -138,10 +90,20 @@ public override bool Execute()
}
catch (Exception ex)
{
Log.LogError("An unknown exception occured: {0}", ex.Message);
Log.LogError("An unknown exception occurred: {0}", ex.Message);
Log.LogErrorFromException(ex, true, true, null);
return false;
}
}

private void EmitHeader()
{
var assembly = Assembly.GetExecutingAssembly();
var informationalVersion = assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion;

Log.LogMessage($"AggregateConfig Version: {informationalVersion}");
}
}
}
37 changes: 25 additions & 12 deletions src/Task/AggregateConfigBuildTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Deterministic>true</Deterministic>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<SourceLinkCreate>true</SourceLinkCreate>
<NoWarn>NU5100</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -20,6 +29,10 @@
<PackageReleaseNotes>https://github.com/richardsondev/AggregateConfigBuildTask/releases/tag/v$(Version)</PackageReleaseNotes>
<PackageReadmeFile>docs/README.md</PackageReadmeFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<NoPackageAnalysis>true</NoPackageAnalysis>
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,28 +41,28 @@

<!-- Build time packages-->
<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="17.11.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.11.4" PrivateAssets="all" />
<PackageReference Include="ReferenceTrimmer" Version="3.3.6" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Framework" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
</ItemGroup>

<!-- Runtime packages -->
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="System.Text.Json" Version="8.0.4" PrivateAssets="all" />
<PackageReference Include="YamlDotNet" Version="16.1.0" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="YamlDotNet.System.Text.Json" Version="1.5.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" PrivateAssets="all" />
<PackageReference Include="System.Text.Json" PrivateAssets="all" />
<PackageReference Include="YamlDotNet" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="YamlDotNet.System.Text.Json" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<None Include="$(OutputPath)/Contracts.dll" Pack="true" PackagePath="/lib/netstandard2.0/" />
<None Include="$(OutputPath)/Microsoft.Bcl.AsyncInterfaces.dll" Pack="true" PackagePath="/lib/netstandard2.0/" />
<None Include="$(OutputPath)/System.Text.Json.dll" Pack="true" PackagePath="/lib/netstandard2.0/" />
<None Include="$(OutputPath)/YamlDotNet.dll" Pack="true" PackagePath="/lib/netstandard2.0/" />
<None Include="$(OutputPath)/Contracts.dll" Pack="true" PackagePath="/tasks/netstandard2.0/" />
<None Include="$(OutputPath)/Microsoft.Bcl.AsyncInterfaces.dll" Pack="true" PackagePath="/tasks/netstandard2.0/" />
<None Include="$(OutputPath)/System.Text.Json.dll" Pack="true" PackagePath="/tasks/netstandard2.0/" />
<None Include="$(OutputPath)/YamlDotNet.dll" Pack="true" PackagePath="/tasks/netstandard2.0/" />
<None Include="$(PkgYamlDotNet)/LICENSE.txt" Pack="true" PackagePath="/licenses/YamlDotNet">
<Link>licenses/YamlDotNet/LICENSE.txt</Link>
</None>
<None Include="$(OutputPath)/YamlDotNet.System.Text.Json.dll" Pack="true" PackagePath="/lib/netstandard2.0/" />
<None Include="$(OutputPath)/YamlDotNet.System.Text.Json.dll" Pack="true" PackagePath="/tasks/netstandard2.0/" />
<None Include="build/AggregateConfigBuildTask.targets" Pack="true" PackagePath="/build/AggregateConfigBuildTask.targets" />
<None Include="../../LICENSE" Pack="true" PackagePath="/licenses/">
<Link>licenses/LICENSE</Link>
Expand Down
11 changes: 6 additions & 5 deletions src/Task/FileHandlers/ArmParametersFileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace AggregateConfig.FileHandlers
namespace AggregateConfigBuildTask.FileHandlers
{
public class ArmParametersFileHandler : IOutputWriter, IInputReader
{
IFileSystem fileSystem;
readonly IFileSystem fileSystem;

internal ArmParametersFileHandler(IFileSystem fileSystem)
{
this.fileSystem = fileSystem;
}

/// <inheritdoc/>
public JsonElement ReadInput(string inputPath)
public ValueTask<JsonElement> ReadInput(string inputPath)
{
using (var stream = fileSystem.OpenRead(inputPath))
{
Expand All @@ -40,10 +41,10 @@ public JsonElement ReadInput(string inputPath)
}

var modifiedJson = modifiedParameters.ToJsonString();
return JsonSerializer.Deserialize<JsonElement>(modifiedJson);
return new ValueTask<JsonElement>(Task.FromResult(JsonSerializer.Deserialize<JsonElement>(modifiedJson)));
}

return jsonDoc.RootElement.Clone();
return new ValueTask<JsonElement>(Task.FromResult(jsonDoc.RootElement.Clone()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Task/FileHandlers/FileHandlerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using AggregateConfig.Contracts;
using AggregateConfigBuildTask.Contracts;
using System;
using System.Collections.Generic;

namespace AggregateConfig.FileHandlers
namespace AggregateConfigBuildTask.FileHandlers
{
public static class FileHandlerFactory
{
Expand Down
5 changes: 3 additions & 2 deletions src/Task/FileHandlers/IInputReader.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Text.Json;
using System.Threading.Tasks;

namespace AggregateConfig.FileHandlers
namespace AggregateConfigBuildTask.FileHandlers
{
public interface IInputReader
{
JsonElement ReadInput(string inputPath);
ValueTask<JsonElement> ReadInput(string inputPath);
}
}
2 changes: 1 addition & 1 deletion src/Task/FileHandlers/IOutputWriter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;

namespace AggregateConfig.FileHandlers
namespace AggregateConfigBuildTask.FileHandlers
{
public interface IOutputWriter
{
Expand Down
9 changes: 5 additions & 4 deletions src/Task/FileHandlers/JsonFileHandler.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using System.Text.Json;
using System.Threading.Tasks;

namespace AggregateConfig.FileHandlers
namespace AggregateConfigBuildTask.FileHandlers
{
public class JsonFileHandler : IOutputWriter, IInputReader
{
IFileSystem fileSystem;
readonly IFileSystem fileSystem;

internal JsonFileHandler(IFileSystem fileSystem)
{
this.fileSystem = fileSystem;
}

/// <inheritdoc/>
public JsonElement ReadInput(string inputPath)
public ValueTask<JsonElement> ReadInput(string inputPath)
{
using (var json = fileSystem.OpenRead(inputPath))
{
return JsonSerializer.Deserialize<JsonElement>(json);
return JsonSerializer.DeserializeAsync<JsonElement>(json);
}
}

Expand Down
Loading