Skip to content

Improve config provider logs #4496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void NoWarnOnCustomYmlFile()
var configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();

configurationProvider.ProvideForDirectory(this.repoPath);
stringLogger.Length.ShouldBe(0);
stringLogger.ShouldMatch("No configuration file found, using default configuration");
}

[Test]
Expand All @@ -244,7 +244,7 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath()
var configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();

configurationProvider.ProvideForDirectory(this.repoPath);
stringLogger.Length.ShouldBe(0);
stringLogger.ShouldMatch("No configuration file found, using default configuration");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void NoWarnOnGitVersionYmlFile()
this.configurationProvider.ProvideForDirectory(this.repoPath);

var filePath = PathHelper.Combine(this.repoPath, ConfigurationFileLocator.DefaultFileName);
stringLogger.ShouldContain($"Found configuration file at '{filePath}'");
stringLogger.ShouldContain($"Using configuration file '{filePath}'");
}

[Test]
Expand Down
1 change: 1 addition & 0 deletions src/GitVersion.Configuration/ConfigurationFileLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
string? customConfigurationFile = GetCustomConfigurationFilePathIfEligable(directoryPath);
if (!string.IsNullOrWhiteSpace(customConfigurationFile))
{
this.log.Info($"Found configuration file at '{customConfigurationFile}'");
return customConfigurationFile;
}

Expand Down
17 changes: 16 additions & 1 deletion src/GitVersion.Configuration/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO.Abstractions;
using GitVersion.Configuration.Workflows;
using GitVersion.Extensions;
using GitVersion.Logging;
using Microsoft.Extensions.Options;
using YamlDotNet.Core;

Expand All @@ -9,12 +10,14 @@ namespace GitVersion.Configuration;
internal class ConfigurationProvider(
IConfigurationFileLocator configFileLocator,
IFileSystem fileSystem,
ILog log,
IConfigurationSerializer configurationSerializer,
IOptions<GitVersionOptions> options)
: IConfigurationProvider
{
private readonly IConfigurationFileLocator configFileLocator = configFileLocator.NotNull();
private readonly IFileSystem fileSystem = fileSystem.NotNull();
private readonly ILog log = log.NotNull();
private readonly IConfigurationSerializer configurationSerializer = configurationSerializer.NotNull();
private readonly IOptions<GitVersionOptions> options = options.NotNull();

Expand Down Expand Up @@ -72,7 +75,19 @@ private IGitVersionConfiguration ProvideConfiguration(string? configFile,

private IReadOnlyDictionary<object, object?>? ReadOverrideConfiguration(string? configFilePath)
{
if (configFilePath == null || !fileSystem.File.Exists(configFilePath)) return null;
if (configFilePath == null)
{
this.log.Info("No configuration file found, using default configuration");
return null;
}

if (!this.fileSystem.File.Exists(configFilePath))
{
this.log.Info($"Configuration file '{configFilePath}' not found");
return null;
}

this.log.Info($"Using configuration file '{configFilePath}'");
var content = fileSystem.File.ReadAllText(configFilePath);
return configurationSerializer.Deserialize<Dictionary<object, object?>>(content);
}
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.sln
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "root", "root", "{7D3A83B4-9
..\.editorconfig = ..\.editorconfig
..\.gitattributes = ..\.gitattributes
..\.gitignore = ..\.gitignore
..\GitVersion.yml = ..\GitVersion.yml
..\.gitversion.yml = ..\.gitversion.yml
..\global.json = ..\global.json
..\GitReleaseManager.yml = ..\GitReleaseManager.yml
EndProjectSection
Expand Down