Skip to content

Commit e323c92

Browse files
author
Furkan Küçük
committed
Make sure custom configuration file path is returned when custom configuration is set
Introduce a new test method `ReturnConfigurationFilePathIfCustomConfigurationIsSet` in `ConfigurationFileLocatorTests.cs` to verify custom config file handling. Update `GitVersion.Configuration.Tests.csproj` to copy `Configuration/CustomConfig.yaml` to the output directory. Enhance `GetConfigurationFile` method in `ConfigurationFileLocator.cs` to return the custom config file path if set and exists. Add `CustomConfig.yaml` with various versioning settings.
1 parent acd73ad commit e323c92

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

src/GitVersion.Configuration.Tests/Configuration/ConfigurationFileLocatorTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ public void DoNotThrowWhenFileNameAreSame_WithDifferentCasing()
169169
config.ShouldNotBe(null);
170170
}
171171

172+
[Test]
173+
public void ReturnConfigurationFilePathIfCustomConfigurationIsSet()
174+
{
175+
this.workingPath = this.repoPath;
176+
177+
this.gitVersionOptions = new() { ConfigurationInfo = { ConfigurationFile = "Configuration/CustomConfig.yaml" } };
178+
var sp = GetServiceProvider(this.gitVersionOptions);
179+
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
180+
this.fileSystem = sp.GetRequiredService<IFileSystem>();
181+
182+
using var _ = this.fileSystem.SetupConfigFile(path: this.workingPath, fileName: ConfigFile);
183+
184+
var config = this.configFileLocator.GetConfigurationFile(this.workingPath);
185+
config.ShouldNotBe(Path.GetFullPath("Configuration/CustomConfig.yaml"));
186+
}
187+
172188
[Test]
173189
public void DoNotThrowWhenConfigFileIsInSubDirectoryOfRepoPath()
174190
{
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
assembly-versioning-scheme: MajorMinorPatch
2+
assembly-versioning-format: '{Major}.0.0'
3+
assembly-file-versioning-scheme: MajorMinorPatchTag
4+
assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}'
5+
mode: ContinuousDelivery
6+
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
7+
tag-prefix: ''
8+
major-version-bump-message: '\[semver:\s?(realbreaking|realmajor)]'
9+
minor-version-bump-message: '\[semver:\s?(realfeature|realminor)]'
10+
patch-version-bump-message: '\[semver:\s?(rfix|rpatch)]'
11+
no-bump-message: '\[semver:\s?(realnone|realskip)]'
12+
tag-pre-release-weight: 60000
13+
commit-date-format: yyyy-MM-dd
14+
merge-message-formats: {}
15+
semantic-version-format: Strict
16+
strategies:
17+
- ConfiguredNextVersion
18+
- Mainline
19+
increment: Inherit
20+
prevent-increment:
21+
of-merged-branch: false
22+
when-branch-merged: false
23+
when-current-commit-tagged: true
24+
track-merge-target: false
25+
track-merge-message: false
26+
tracks-release-branches: false
27+
commit-message-incrementing: Enabled
28+
is-release-branch: false
29+
is-main-branch: false
30+
label: ''
31+
branches:
32+
main:
33+
regex: ^dev(elop)?(ment)?$
34+
mode: ContinuousDeployment
35+
label: alpha
36+
increment: Minor
37+
prevent-increment:
38+
of-merged-branch: true
39+
track-merge-target: false
40+
track-merge-message: false
41+
source-branches: []
42+
is-source-branch-for: []
43+
tracks-release-branches: false
44+
is-release-branch: false
45+
is-main-branch: true
46+
pre-release-weight: 0
47+
release:
48+
regex: ^release?[/-]
49+
mode: ContinuousDeployment
50+
label: ''
51+
increment: Patch
52+
prevent-increment:
53+
of-merged-branch: true
54+
when-branch-merged: false
55+
when-current-commit-tagged: false
56+
track-merge-target: false
57+
track-merge-message: false
58+
source-branches: []
59+
is-source-branch-for: []
60+
tracks-release-branches: false
61+
is-release-branch: false
62+
is-main-branch: true
63+
pre-release-weight: 60000
64+
feature:
65+
# Match nothing
66+
regex: ^\b$
67+
pull-request:
68+
# Match nothing
69+
regex: ^\b$
70+
hotfix:
71+
# Match nothing
72+
regex: ^\b$
73+
support:
74+
# Match nothing
75+
regex: ^\b$

src/GitVersion.Configuration.Tests/GitVersion.Configuration.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
<ProjectReference Include="..\GitVersion.Core.Tests\GitVersion.Core.Tests.csproj" />
55
</ItemGroup>
66

7+
<ItemGroup>
8+
<None Update="Configuration\CustomConfig.yaml">
9+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
10+
</None>
11+
</ItemGroup>
12+
713
<!-- Add the following target to copy the workflow files to the docs folder.
814
Whenever the Workflow changes, the docs folder will be updated with the latest version.
915
-->

src/GitVersion.Configuration/ConfigurationFileLocator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
4040

4141
public string? GetConfigurationFile(string? directory)
4242
{
43+
// If configuration file overriden and its exists, return it
44+
if (!string.IsNullOrWhiteSpace(this.ConfigurationFile) &&
45+
PathHelper.IsPathRooted(this.ConfigurationFile) &&
46+
fileSystem.File.Exists(this.ConfigurationFile))
47+
{
48+
return this.ConfigurationFile;
49+
}
50+
4351
if (directory is null) return null;
4452

4553
string[] candidates = !string.IsNullOrWhiteSpace(this.ConfigurationFile)

0 commit comments

Comments
 (0)