Skip to content

Commit

Permalink
Merge pull request #125 from BigBang1112/dev
Browse files Browse the repository at this point in the history
GBX.NET 2.0.8
  • Loading branch information
BigBang1112 authored Sep 29, 2024
2 parents 61442c3 + 43a1148 commit 7c4cd40
Show file tree
Hide file tree
Showing 28 changed files with 494 additions and 94 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/dotnet.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ name: CI
on:
push:
branches: [ "master", "dev" ]
paths: [ ".github/workflows/dotnet.yml", "Src/**", "Benchmarks/**", "Generators/**", "Resources/**", "Samples/**", "Tests/**", "Tools/**", "GBX.NET.sln" ]
paths: [ ".github/workflows/ci.yml", "Src/**", "Benchmarks/**", "Generators/**", "Resources/**", "Samples/**", "Tests/**", "Tools/**", "GBX.NET.sln" ]
pull_request:
branches: [ "master", "dev" ]
paths: [ ".github/workflows/dotnet.yml", "Src/**", "Src/**", "Benchmarks/**", "Generators/**", "Resources/**", "Samples/**", "Tests/**", "Tools/**", "GBX.NET.sln" ]
paths: [ ".github/workflows/ci.yml", "Src/**", "Src/**", "Benchmarks/**", "Generators/**", "Resources/**", "Samples/**", "Tests/**", "Tools/**", "GBX.NET.sln" ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v4
Expand All @@ -31,10 +35,12 @@ jobs:
run: dotnet build -c Release --no-restore /p:ContinuousIntegrationBuild=true

- name: Test
if: ${{ (matrix.os == 'ubuntu-latest') || (github.ref == 'refs/heads/master') }}
run: dotnet test -c Release --no-build --verbosity normal --no-build --collect:"XPlat Code Coverage" --results-directory ./coverage

- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
if: ${{ (github.ref == 'refs/heads/master') && (matrix.os == 'ubuntu-latest') }}
with:
filename: coverage/**/coverage.cobertura.xml
badge: true
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-explorer-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Deploy Explorer to Pages
on:
push:
branches: ["dev"]
paths: [ ".github/workflows/deploy-explorer-pages.yml", "Src/**", "Benchmarks/**", "Generators/**", "Resources/**", "Samples/**", "Tests/**", "Tools/**", "GBX.NET.sln" ]
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ jobs:

- name: Publish ${{ matrix.lib }} nupkg to github.com
run: dotnet nuget push ${{ matrix.lib }}/bin/Release/*.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/bigbang1112/index.json --skip-duplicate

- name: Publish ${{ matrix.lib }} nupkg to nuget.gbx.tools
run: dotnet nuget push ${{ matrix.lib }}/bin/Release/*.nupkg -k ${{ secrets.NUGET_GBXTOOLS_API_KEY }} -s https://nuget.gbx.tools/v3/index.json --skip-duplicate

- name: Upload ${{ matrix.lib }} nupkg to this release
run: gh release upload ${{ github.ref_name }} ${{ matrix.lib }}/bin/Release/*.nupkg
Expand Down
9 changes: 8 additions & 1 deletion GBX.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryCryptSwitch", "Tools\Cry
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GBX.NET.BlockInfo", "Src\GBX.NET.BlockInfo\GBX.NET.BlockInfo.csproj", "{89F6FFE5-E32A-4713-8D63-98D070A17DC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MuxCryptSwitch", "Tools\MuxCryptSwitch\MuxCryptSwitch.csproj", "{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MuxCryptSwitch", "Tools\MuxCryptSwitch\MuxCryptSwitch.csproj", "{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GBX.NET.Tool.StandardIO", "Src\GBX.NET.Tool.StandardIO\GBX.NET.Tool.StandardIO.csproj", "{55BD1330-7431-41A8-90EB-DEB20D9EB981}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -406,6 +408,10 @@ Global
{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4}.Release|Any CPU.Build.0 = Release|Any CPU
{55BD1330-7431-41A8-90EB-DEB20D9EB981}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{55BD1330-7431-41A8-90EB-DEB20D9EB981}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55BD1330-7431-41A8-90EB-DEB20D9EB981}.Release|Any CPU.ActiveCfg = Release|Any CPU
{55BD1330-7431-41A8-90EB-DEB20D9EB981}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -474,6 +480,7 @@ Global
{4327AB87-DF45-4364-9D27-1C72BA0E78FF} = {F3336145-FDA9-4517-AEDC-7F4C4D526ECB}
{89F6FFE5-E32A-4713-8D63-98D070A17DC1} = {80DCE6B7-4BD9-415C-B053-92B059D7C938}
{0B5609C6-7B10-4E8D-B41C-35CC1A2532A4} = {F3336145-FDA9-4517-AEDC-7F4C4D526ECB}
{55BD1330-7431-41A8-90EB-DEB20D9EB981} = {80DCE6B7-4BD9-415C-B053-92B059D7C938}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8EA2F0DE-BA72-486D-AB3A-9320C0CE5CFD}
Expand Down
57 changes: 57 additions & 0 deletions Src/GBX.NET.Tool.CLI/ComplexConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;

namespace GBX.NET.Tool.CLI;

internal sealed class ComplexConfig : IComplexConfig
{
private readonly string configName;
private readonly SettingsManager settings;

private readonly ConcurrentDictionary<string, object> cache = new();

public ComplexConfig(string configName, SettingsManager settings)
{
this.configName = configName;
this.settings = settings;
}

[RequiresDynamicCode(DynamicCodeMessages.JsonSerializeMessage)]
[RequiresUnreferencedCode(DynamicCodeMessages.JsonSerializeMessage)]
public T Get<T>(string filePathWithoutExtension, bool cache = false) where T : class
{
if (cache && this.cache.TryGetValue(filePathWithoutExtension, out var value))
{
return (T)value;
}

var result = settings.GetFileFromConfig<T>(configName, filePathWithoutExtension);

if (cache)
{
this.cache.TryAdd(filePathWithoutExtension, result);
}

return result;
}

[RequiresDynamicCode(DynamicCodeMessages.JsonSerializeMessage)]
[RequiresUnreferencedCode(DynamicCodeMessages.JsonSerializeMessage)]
public async Task<T> GetAsync<T>(string filePathWithoutExtension, bool cache = false, CancellationToken cancellationToken = default) where T : class
{
if (cache && this.cache.TryGetValue(filePathWithoutExtension, out var value))
{
return (T)value;
}

var result = await settings.GetFileFromConfigAsync<T>(configName, filePathWithoutExtension, cancellationToken).ConfigureAwait(false);

if (cache)
{
this.cache.TryAdd(filePathWithoutExtension, result);
}

return result;
}
}
2 changes: 1 addition & 1 deletion Src/GBX.NET.Tool.CLI/GBX.NET.Tool.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageId>GBX.NET.Tool.CLI</PackageId>
<Version>0.2.0</Version>
<VersionPrefix>0.3.0</VersionPrefix>
<Authors>BigBang1112</Authors>
<Description>CLI implementation for the GBX.NET tool framework using Spectre.Console.</Description>
<Copyright>Copyright (c) 2024 Petr Pivoňka</Copyright>
Expand Down
32 changes: 27 additions & 5 deletions Src/GBX.NET.Tool.CLI/OutputDistributor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using System.Diagnostics;

namespace GBX.NET.Tool.CLI;

Expand Down Expand Up @@ -28,20 +29,39 @@ public OutputDistributor(string runningDir, ToolSettings toolSettings, ILogger l
}
}

public async Task DistributeOutputsAsync(IEnumerable<object> outputs, CancellationToken cancellationToken)
public async Task DistributeOutputsAsync(IEnumerable<object> outputs, bool mutating, CancellationToken cancellationToken)
{
var watch = default(Stopwatch);

if (outputs is not System.Collections.ICollection)
{
watch = Stopwatch.StartNew();
}

foreach (var output in outputs)
{
await DistributeOutputAsync(output, cancellationToken);
if (watch is not null)
{
if (mutating)
{
logger.LogInformation("Mutated in {Milliseconds}ms!", watch.ElapsedMilliseconds);
}
else
{
logger.LogInformation("Produced in {Milliseconds}ms!", watch.ElapsedMilliseconds);
}
}

await DistributeOutputAsync(output, mutating, cancellationToken);
}
}

public async ValueTask DistributeOutputAsync(object? output, CancellationToken cancellationToken)
public async ValueTask DistributeOutputAsync(object? output, bool mutating, CancellationToken cancellationToken)
{
switch (output)
{
case IEnumerable<object> objList:
await DistributeOutputsAsync(objList, cancellationToken);
await DistributeOutputsAsync(objList, mutating, cancellationToken);
break;
case null:
break;
Expand All @@ -63,12 +83,14 @@ public async ValueTask DistributeOutputAsync(object? output, CancellationToken c
Directory.CreateDirectory(dirPath);
}

var watch = Stopwatch.StartNew();

await using (var fs = new FileStream(finalPath, FileMode.Create, FileAccess.Write, FileShare.None, 4096, useAsync: true))
{
gbx.Save(fs);
}

logger.LogInformation("Gbx ({FilePath}) saved.", filePath);
logger.LogInformation("Gbx ({FilePath}) saved in {Milliseconds}ms.", filePath, watch.ElapsedMilliseconds);

break;
default:
Expand Down
Loading

0 comments on commit 7c4cd40

Please sign in to comment.