Skip to content

#2484 - show warning if the configuration file is not found #3408

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 1 commit into from
Feb 28, 2023
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
19 changes: 17 additions & 2 deletions src/GitVersion.App.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData(
public void OverrideConfigWithMultipleOptions(string options, GitVersionConfiguration expected)
{
var arguments = this.argumentParser.ParseArguments(options);
ConfigurationHelper configruationHelper = new(arguments.OverrideConfiguration);
configruationHelper.Configuration.ShouldBeEquivalentTo(expected);
ConfigurationHelper configurationHelper = new(arguments.OverrideConfiguration);
configurationHelper.Configuration.ShouldBeEquivalentTo(expected);
}

private static IEnumerable<TestCaseData> OverrideConfigWithMultipleOptionsTestData()
Expand Down Expand Up @@ -740,4 +740,19 @@ public void EnsureFormatIsSet()
var arguments = this.argumentParser.ParseArguments("-format {Major}.{Minor}.{Patch}");
arguments.Format.ShouldBe("{Major}.{Minor}.{Patch}");
}

[TestCase("custom-config.yaml")]
[TestCase(@"c:\custom-config.yaml")]
public void ThrowIfConfigurationFileDoesNotExist(string configFile) =>
Should.Throw<WarningException>(() => _ = this.argumentParser.ParseArguments($"-config {configFile}"));

[Test]
public void EnsureConfigurationFileIsSet()
{
var configFile = Path.GetTempPath() + Guid.NewGuid() + ".yaml";
File.WriteAllText(configFile, "next-version: 1.0.0");
var arguments = this.argumentParser.ParseArguments($"-config {configFile}");
arguments.ConfigurationFile.ShouldBe(configFile);
File.Delete(configFile);
}
}
19 changes: 19 additions & 0 deletions src/GitVersion.App/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,28 @@ public Arguments ParseArguments(string[] commandLineArguments)
if (!arguments.EnsureAssemblyInfo) arguments.UpdateAssemblyInfoFileName = ResolveFiles(arguments.TargetPath, arguments.UpdateAssemblyInfoFileName).ToHashSet();
arguments.NoFetch = arguments.NoFetch || this.buildAgent.PreventFetch();

ValidateConfigurationFile(arguments);

return arguments;
}

private static void ValidateConfigurationFile(Arguments arguments)
{
if (arguments.ConfigurationFile.IsNullOrWhiteSpace()) return;

if (Path.IsPathRooted(arguments.ConfigurationFile))
{
if (!File.Exists(arguments.ConfigurationFile)) throw new WarningException($"Could not find config file at '{arguments.ConfigurationFile}'");
arguments.ConfigurationFile = Path.GetFullPath(arguments.ConfigurationFile);
}
else
{
var configFilePath = Path.GetFullPath(Path.Combine(arguments.TargetPath!, arguments.ConfigurationFile));
if (!File.Exists(configFilePath)) throw new WarningException($"Could not find config file at '{configFilePath}'");
arguments.ConfigurationFile = configFilePath;
}
}

private void ParseSwitchArguments(Arguments arguments, NameValueCollection switchesAndValues, int i)
{
var name = switchesAndValues.AllKeys[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace GitVersion.VersionCalculation;
public class TrackReleaseBranchesVersionStrategy : VersionStrategyBase
{
private readonly VersionInBranchNameVersionStrategy releaseVersionStrategy;
private readonly TaggedCommitVersionStrategy taggedCommitVersionStrategy;

private readonly IRepositoryStore repositoryStore;

Expand All @@ -32,7 +31,6 @@ public TrackReleaseBranchesVersionStrategy(IRepositoryStore repositoryStore, Laz
{
this.repositoryStore = repositoryStore.NotNull();
this.releaseVersionStrategy = new VersionInBranchNameVersionStrategy(repositoryStore, versionContext);
this.taggedCommitVersionStrategy = new TaggedCommitVersionStrategy(repositoryStore, versionContext);
}

public override IEnumerable<BaseVersion> GetBaseVersions(EffectiveBranchConfiguration configuration) =>
Expand Down