Skip to content

Commit

Permalink
Dependency & quality updates (#43)
Browse files Browse the repository at this point in the history
* Bump SonarAnalyzer.CSharp from 9.20.0.85982 to 9.23.1.88495 (#42)

* Bump SonarAnalyzer.CSharp from 9.20.0.85982 to 9.23.1.88495

Bumps [SonarAnalyzer.CSharp](https://github.com/SonarSource/sonar-dotnet) from 9.20.0.85982 to 9.23.1.88495.
- [Release notes](https://github.com/SonarSource/sonar-dotnet/releases)
- [Commits](SonarSource/sonar-dotnet@9.20.0.85982...9.23.1.88495)

---
updated-dependencies:
- dependency-name: SonarAnalyzer.CSharp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fix S6667 and simplify logging

* Fix S2139 and allow startup exceptions to bubble up

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: elzik <[email protected]>

* Bump coverlet.collector from 6.0.1 to 6.0.2 (#39)

Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 6.0.1 to 6.0.2.
- [Release notes](https://github.com/coverlet-coverage/coverlet/releases)
- [Commits](coverlet-coverage/coverlet@v6.0.1...v6.0.2)

---
updated-dependencies:
- dependency-name: coverlet.collector
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump Polly.Testing from 8.3.0 to 8.3.1 (#38)

Bumps [Polly.Testing](https://github.com/App-vNext/Polly) from 8.3.0 to 8.3.1.
- [Release notes](https://github.com/App-vNext/Polly/releases)
- [Changelog](https://github.com/App-vNext/Polly/blob/main/CHANGELOG.md)
- [Commits](App-vNext/Polly@8.3.0...8.3.1)

---
updated-dependencies:
- dependency-name: Polly.Testing
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: elzik <[email protected]>

* Bump Polly.Extensions from 8.3.0 to 8.3.1 (#37)

Bumps [Polly.Extensions](https://github.com/App-vNext/Polly) from 8.3.0 to 8.3.1.
- [Release notes](https://github.com/App-vNext/Polly/releases)
- [Changelog](https://github.com/App-vNext/Polly/blob/main/CHANGELOG.md)
- [Commits](App-vNext/Polly@8.3.0...8.3.1)

---
updated-dependencies:
- dependency-name: Polly.Extensions
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Improve error handling and logging in config script

* Use correct app settings path

* Improve MSBUILD event naming

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
elzik and dependabot[bot] authored Apr 5, 2024
1 parent b405e1f commit e5cd741
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 79 deletions.
6 changes: 6 additions & 0 deletions Build/set-platform-specific-config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Param(
[String] $operatingSystem
)

$ErrorActionPreference = "Stop"

if ($operatingSystem -eq 'Windows_NT')
{
$platformSpecificLogPath = 'C:/ProgramData/Elzik/fmsync'
Expand All @@ -14,7 +16,11 @@ else
$platformSpecificLogPath = '~/Library/Logs/Elzik/fmsync'
}

Write-Output "Platform specific log path: $platformSpecificLogPath"

$appSettingsPath = "$outputDirectory/appSettings.json"

Write-Output "appSettings Path: $appSettingsPath"

(Get-Content $appSettingsPath).Replace('[PLATFORM_SPECIFIC_LOG_PATH]', $platformSpecificLogPath) `
| Set-Content $appSettingsPath
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Polly.Core" Version="8.3.1" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
29 changes: 12 additions & 17 deletions src/Elzik.FmSync.Application/FrontMatterFolderSynchroniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
namespace Elzik.FmSync.Application;

public class FrontMatterFolderSynchroniser(
ILogger<FrontMatterFolderSynchroniser> logger,
IDirectory directory,
IFrontMatterFileSynchroniser frontMatterFileSynchroniser,
ILogger<FrontMatterFolderSynchroniser> logger,
IDirectory directory,
IFrontMatterFileSynchroniser frontMatterFileSynchroniser,
IOptions<FileSystemOptions> options) : IFrontMatterFolderSynchroniser
{
private readonly ILogger<FrontMatterFolderSynchroniser> _logger = logger
private readonly ILogger<FrontMatterFolderSynchroniser> _logger = logger
?? throw new ArgumentNullException(nameof(logger));
private readonly IDirectory _directory = directory
private readonly IDirectory _directory = directory
?? throw new ArgumentNullException(nameof(directory));
private readonly IFrontMatterFileSynchroniser _frontMatterFileSynchroniser = frontMatterFileSynchroniser
?? throw new ArgumentNullException(nameof(frontMatterFileSynchroniser));
Expand All @@ -24,7 +24,7 @@ public void SyncCreationDates(string directoryPath)
{
var loggingInfo = (StartTime: Stopwatch.GetTimestamp(), EditedCount: 0, ErrorCount: 0, TotalCount: 0);

_logger.LogDebug("Synchronising {FilenamePattern} files in {DirectoryPath}",
_logger.LogDebug("Synchronising {FilenamePattern} files in {DirectoryPath}",
_options.FilenamePattern, directoryPath);

var markdownFiles = _directory.EnumerateFiles(directoryPath, _options.FilenamePattern ?? string.Empty,
Expand All @@ -48,13 +48,8 @@ public void SyncCreationDates(string directoryPath)
catch (Exception e)
{
loggingInfo.ErrorCount++;
var additionalMessage = string.Empty;
if (e.InnerException != null)
{
additionalMessage = $" {e.InnerException.Message}";
}
_logger.LogError("{MarkdownFilePath} - {ExceptionMessage}{AdditionalMessage}",
markDownFilePath, e.Message, additionalMessage);
_logger.LogError(e, "An error occurred whilst synchronising the creation date for {MarkdownFilePath}",
markDownFilePath);
}
}

Expand All @@ -65,10 +60,10 @@ public void SyncCreationDates(string directoryPath)
}

_logger.LogInformation("Synchronised {EditedFileCount}{ErrorsMessage} files out " +
"of a total {TotalFileCount} in {TimeTaken}.",
loggingInfo.EditedCount,
errorsMessage,
loggingInfo.TotalCount,
"of a total {TotalFileCount} in {TimeTaken}.",
loggingInfo.EditedCount,
errorsMessage,
loggingInfo.TotalCount,
Stopwatch.GetElapsedTime(loggingInfo.StartTime));
}
}
6 changes: 3 additions & 3 deletions src/Elzik.FmSync.Console/Elzik.FmSync.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -41,11 +41,11 @@
</None>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Target Name="ConsolePostBuildConfigUpdate" AfterTargets="PostBuildEvent">
<Exec Command="PowerShell -NoProfile -ExecutionPolicy unrestricted -file $(ProjectDir)../../Build/set-platform-specific-config.ps1 $(OutDir) $(OS)" />
</Target>

<Target Name="PostPublish" AfterTargets="Publish">
<Target Name="ConsolePostPublishConfigUpdate" AfterTargets="Publish">
<Exec Command="PowerShell -NoProfile -ExecutionPolicy unrestricted -file $(ProjectDir)../../Build/set-platform-specific-config.ps1 $(PublishDir) $(OS)" />
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions src/Elzik.FmSync.Worker/Elzik.FmSync.Worker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Polly.Extensions" Version="8.3.0" />
<PackageReference Include="Polly.Extensions" Version="8.3.1" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -42,11 +42,11 @@
<ProjectReference Include="..\Elzik.FmSync.Infrastructure\Elzik.FmSync.Infrastructure.csproj" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Target Name="WorkerPostBuildConfigUpdate" AfterTargets="PostBuildEvent">
<Exec Command="PowerShell -NoProfile -ExecutionPolicy unrestricted -file $(ProjectDir)../../Build/set-platform-specific-config.ps1 $(OutDir) $(OS)" />
</Target>

<Target Name="PostPublish" AfterTargets="Publish">
<Target Name="WorkerPostPublishConfigUpdate" AfterTargets="Publish">
<Exec Command="PowerShell -NoProfile -ExecutionPolicy unrestricted -file $(ProjectDir)../../Build/set-platform-specific-config.ps1 $(PublishDir) $(OS) " />
</Target>

Expand Down
19 changes: 2 additions & 17 deletions src/Elzik.FmSync.Worker/FmSyncWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,6 @@ public FmSyncWorker(ILogger<FmSyncWorker> logger, IOptions<WatcherOptions> watch
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
StartWorker();
}
catch (Exception ex)
{
_logger.LogCritical(ex, "A problem occurred whilst starting the worker. " +
"{ExceptionMessage}", ex.Message);

throw;
}

await Task.Yield();
}

private void StartWorker()
{
_logger.LogInformation("fmsync {Version} has started.", GetProductVersion());
_logger.LogDebug("File synchroniation is implemented by {SyncName}", _fileSynchroniser.GetType().Name);
Expand Down Expand Up @@ -79,6 +62,8 @@ private void StartWorker()
"the {ConfigSection}:{ConfigItem} configuration.",
nameof(WatcherOptions), nameof(WatcherOptions.WatchedDirectoryPaths));
}

await Task.Yield();
}

private static string GetProductVersion()
Expand Down
4 changes: 3 additions & 1 deletion src/Elzik.FmSync.Worker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
using Polly;
using Elzik.FmSync.Application;

var appSettingsPath = Path.Join(AppContext.BaseDirectory, "appSettings.json");

var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((_, config) =>
{
config.AddJsonFile("appSettings.json", false);
config.AddJsonFile(appSettingsPath, false);
})
.UseSerilog((context, config) => config.ReadFrom.Configuration(context.Configuration))
.ConfigureServices((hostContext, services) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<ItemGroup>
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -33,8 +33,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Polly.Testing" Version="8.3.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PackageReference Include="Polly.Testing" Version="8.3.1" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void SyncCreationDates_DirectoryPathSupplied_OnlyLogs()
{
// Arrange
var testDirectoryPath = _fixture.Create<string>();

// Act
_frontMatterFolderSynchroniser.SyncCreationDates(testDirectoryPath);

Expand Down Expand Up @@ -105,7 +105,7 @@ public void SyncCreationDates_WithMarkDownFiles_LogsSummary()
}

[Fact]
public void SyncCreationDates_SyncFailsWithInnerException_LogsError()
public void SyncCreationDates_SyncFails_LogsException()
{
// Arrange
var testDirectoryPath = _fixture.Create<string>();
Expand All @@ -119,27 +119,8 @@ public void SyncCreationDates_SyncFailsWithInnerException_LogsError()
_frontMatterFolderSynchroniser.SyncCreationDates(testDirectoryPath);

// Assert
_mockLogger.Received(1).Log( LogLevel.Error,
testFile.Key + " - " + testException.Message + " " + testException.InnerException?.Message);
}

[Fact]
public void SyncCreationDates_SyncFailsWithoutInnerException_LogsError()
{
// Arrange
var testDirectoryPath = _fixture.Create<string>();
var testFile = _fixture.Create<KeyValuePair<string, bool>>();
var testFiles = new List<KeyValuePair<string, bool>> { testFile };
SetMockDirectoryFilePaths(testDirectoryPath, testFiles);
var testException = new Exception(_fixture.Create<string>());
_mockFileSynchroniser.SyncCreationDate(testFile.Key).Throws(testException);

// Act
_frontMatterFolderSynchroniser.SyncCreationDates(testDirectoryPath);

// Assert
_mockLogger.Received(1).Log(LogLevel.Error,
testFile.Key + " - " + testException.Message);
_mockLogger.Received(1).Log(LogLevel.Error, "An error occurred whilst synchronising the creation date for "
+ testFile.Key);
}

[Fact]
Expand All @@ -148,7 +129,7 @@ public void SyncCreationDates_SyncFails_LogsSummary()
// Arrange
var testDirectoryPath = _fixture.Create<string>();
var testFailingFile = new KeyValuePair<string, bool>(_fixture.Create<string>(), false);
var testFiles = new []
var testFiles = new[]
{
testFailingFile,
new (_fixture.Create<string>(), false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -38,7 +38,7 @@
</PackageReference>
<PackageReference Include="FluentAssertions.Json" Version="6.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -56,7 +56,7 @@
</ItemGroup>


<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Target Name="ConsoleFunctionalTestsPostBuildConfigUpdate" AfterTargets="PostBuildEvent">
<Exec Command="PowerShell -NoProfile -ExecutionPolicy unrestricted -file $(ProjectDir)/../../Build/set-platform-specific-config.ps1 $(OutDir) $(OS)" />
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -35,7 +35,7 @@
</PackageReference>
<PackageReference Include="FluentAssertions.Json" Version="6.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -38,7 +38,7 @@
</PackageReference>
<PackageReference Include="FluentAssertions.Json" Version="6.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.20.0.85982">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -56,7 +56,7 @@
</ItemGroup>


<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Target Name="WorkerFunctionalTestsPostBuildConfigUpdate" AfterTargets="PostBuildEvent">
<Exec Command="PowerShell -NoProfile -ExecutionPolicy unrestricted -file $(ProjectDir)/../../Build/set-platform-specific-config.ps1 $(OutDir) $(OS)" />
</Target>

Expand Down

0 comments on commit e5cd741

Please sign in to comment.