Skip to content

Commit 3e111c9

Browse files
authored
Merge branch 'GitTools:main' into main
2 parents 8a6e973 + 636cc72 commit 3e111c9

File tree

18 files changed

+242
-231
lines changed

18 files changed

+242
-231
lines changed

build/build/Tasks/Package/PackageArchive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public override void Run(BuildContext context)
1212
{
1313
context.EnsureDirectoryExists(Paths.Native);
1414

15-
var platform = context.Environment.Platform.Family;
15+
var platform = context.Platform;
1616
var runtimes = context.NativeRuntimes[platform];
1717

1818
foreach (var runtime in runtimes)

build/build/Tasks/Package/PackagePrepare.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public override void Run(BuildContext context)
2525
private static void PackPrepareNative(BuildContext context)
2626
{
2727
// publish single file for all native runtimes (self contained)
28-
var platform = context.Environment.Platform.Family;
28+
var platform = context.Platform;
2929
var runtimes = context.NativeRuntimes[platform];
3030

3131
foreach (var runtime in runtimes)
@@ -34,7 +34,7 @@ private static void PackPrepareNative(BuildContext context)
3434

3535
// testing windows and macos artifacts, the linux is tested with docker
3636
if (platform == PlatformFamily.Linux) continue;
37-
if (runtime.EndsWith("arm64")) continue;
37+
if (runtime.EndsWith("arm64")) continue; // TODO: enable when we have arm64 macos agent
3838

3939
context.Information("Validating native lib:");
4040
var nativeExe = outputPath.CombineWithFilePath(context.IsOnWindows ? "gitversion.exe" : "gitversion");
@@ -44,7 +44,7 @@ private static void PackPrepareNative(BuildContext context)
4444

4545
private static DirectoryPath PackPrepareNative(BuildContext context, string runtime)
4646
{
47-
var platform = context.Environment.Platform.Family;
47+
var platform = context.Platform;
4848
var outputPath = Paths.Native.Combine(platform.ToString().ToLower()).Combine(runtime);
4949

5050
var settings = new DotNetPublishSettings

build/build/Tasks/Test/UnitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public override void Finally(BuildContext context)
5353
var data = new AzurePipelinesPublishTestResultsData
5454
{
5555
TestResultsFiles = testResultsFiles.ToArray(),
56-
Platform = context.Environment.Platform.Family.ToString(),
56+
Platform = context.Platform.ToString(),
5757
TestRunner = AzurePipelinesTestRunnerType.JUnit
5858
};
5959
context.BuildSystem().AzurePipelines.Commands.PublishTestResults(data);

build/common/Utilities/BuildContextBase.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ namespace Common.Utilities;
22

33
public class BuildContextBase : FrostingContext
44
{
5-
protected BuildContextBase(ICakeContext context) : base(context)
6-
{
7-
}
5+
protected BuildContextBase(ICakeContext context) : base(context) => Platform = Environment.Platform.Family;
6+
public PlatformFamily Platform { get; set; }
87
public BuildVersion? Version { get; set; }
9-
108
public bool IsOriginalRepo { get; set; }
119
public string BranchName { get; set; } = string.Empty;
1210
public string RepositoryName { get; set; } = string.Empty;

build/common/Utilities/DockerContextExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private static void DockerTestRun(this BuildContextBase context, string image, A
153153
{
154154
var settings = GetDockerRunSettings(context, arch);
155155
context.Information($"Testing image: {image}");
156-
var output = context.DockerRunImage(settings, image, command, args);
156+
var output = context.DockerRun(settings, image, command, args);
157157
context.Information("Output : " + output);
158158

159159
Assert.NotNull(context.Version?.GitVersion);
@@ -235,7 +235,7 @@ private static DockerContainerRunSettings GetDockerRunSettings(this BuildContext
235235

236236
return settings;
237237
}
238-
private static string DockerRunImage(this ICakeContext context, DockerContainerRunSettings settings, string image, string command, params string[] args)
238+
/*private static string DockerRunImage(this ICakeContext context, DockerContainerRunSettings settings, string image, string command, params string[] args)
239239
{
240240
if (string.IsNullOrEmpty(image))
241241
{
@@ -257,5 +257,5 @@ private static string DockerRunImage(this ICakeContext context, DockerContainerR
257257
258258
var result = runner.RunWithResult("run", settings, r => r.ToArray(), arguments.ToArray());
259259
return string.Join("\n", result);
260-
}
260+
}*/
261261
}

src/GitVersion.App.Tests/Helpers/ExecutionResults.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public virtual GitVersionVariables OutputVariables
1919
{
2020
get
2121
{
22-
var jsonStartIndex = Output.IndexOf("{", StringComparison.Ordinal);
23-
var jsonEndIndex = Output.IndexOf("}", StringComparison.Ordinal);
22+
var jsonStartIndex = Output.IndexOf('{');
23+
var jsonEndIndex = Output.IndexOf('}');
2424
var json = Output.Substring(jsonStartIndex, jsonEndIndex - jsonStartIndex + 1);
2525

2626
return VersionVariablesHelper.FromJson(json);

src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs

Lines changed: 118 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class GitVersionExecutorTests : TestBase
1616
{
1717
private IFileSystem fileSystem;
1818
private ILog log;
19-
private IGitVersionCache gitVersionCache;
19+
private GitVersionCache gitVersionCache;
2020
private IServiceProvider sp;
2121

2222
[Test]
@@ -91,33 +91,35 @@ public void CacheKeyForWorktree()
9191
[Test]
9292
public void CacheFileExistsOnDisk()
9393
{
94-
const string versionCacheFileContent = @"
95-
Major: 4
96-
Minor: 10
97-
Patch: 3
98-
PreReleaseTag: test.19
99-
PreReleaseTagWithDash: -test.19
100-
PreReleaseLabel: test
101-
PreReleaseLabelWithDash: -test
102-
PreReleaseNumber: 19
103-
WeightedPreReleaseNumber: 19
104-
BuildMetaData:
105-
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
106-
MajorMinorPatch: 4.10.3
107-
SemVer: 4.10.3-test.19
108-
AssemblySemVer: 4.10.3.0
109-
AssemblySemFileVer: 4.10.3.0
110-
FullSemVer: 4.10.3-test.19
111-
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
112-
BranchName: feature/test
113-
EscapedBranchName: feature-test
114-
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
115-
ShortSha: dd2a29af
116-
VersionSourceSha: 4.10.2
117-
CommitsSinceVersionSource: 19
118-
CommitDate: 2015-11-10
119-
UncommittedChanges: 0
120-
";
94+
const string versionCacheFileContent = """
95+
{
96+
"Major": 4,
97+
"Minor": 10,
98+
"Patch": 3,
99+
"PreReleaseTag": "test.19",
100+
"PreReleaseTagWithDash": "-test.19",
101+
"PreReleaseLabel": "test",
102+
"PreReleaseLabelWithDash": "-test",
103+
"PreReleaseNumber": 19,
104+
"WeightedPreReleaseNumber": 19,
105+
"BuildMetaData": null,
106+
"FullBuildMetaData": "Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
107+
"MajorMinorPatch": "4.10.3",
108+
"SemVer": "4.10.3-test.19",
109+
"AssemblySemVer": "4.10.3.0",
110+
"AssemblySemFileVer": "4.10.3.0",
111+
"FullSemVer": "4.10.3-test.19",
112+
"InformationalVersion": "4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
113+
"BranchName": "feature/test",
114+
"EscapedBranchName": "feature-test",
115+
"Sha": "dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
116+
"ShortSha": "dd2a29af",
117+
"VersionSourceSha": "4.10.2",
118+
"CommitsSinceVersionSource": 19,
119+
"CommitDate": "2015-11-10T00:00:00.000Z",
120+
"UncommittedChanges": 0
121+
}
122+
""";
121123

122124
var stringBuilder = new StringBuilder();
123125
void Action(string s) => stringBuilder.AppendLine(s);
@@ -145,37 +147,39 @@ public void CacheFileExistsOnDisk()
145147

146148
var logsMessages = stringBuilder.ToString();
147149

148-
logsMessages.ShouldContain("Deserializing version variables from cache file", Case.Insensitive, logsMessages);
150+
logsMessages.ShouldContain("Loading version variables from disk cache file", Case.Insensitive, logsMessages);
149151
}
150152

151153
[Test]
152154
public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDynamicallyCalculatedWithoutSavingInCache()
153155
{
154-
const string versionCacheFileContent = @"
155-
Major: 4
156-
Minor: 10
157-
Patch: 3
158-
PreReleaseTag: test.19
159-
PreReleaseTagWithDash: -test.19
160-
PreReleaseLabel: test
161-
PreReleaseLabelWithDash: -test
162-
PreReleaseNumber: 19
163-
BuildMetaData:
164-
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
165-
MajorMinorPatch: 4.10.3
166-
SemVer: 4.10.3-test.19
167-
AssemblySemVer: 4.10.3.0
168-
AssemblySemFileVer: 4.10.3.0
169-
FullSemVer: 4.10.3-test.19
170-
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
171-
BranchName: feature/test
172-
EscapedBranchName: feature-test
173-
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
174-
ShortSha: dd2a29af
175-
CommitsSinceVersionSource: 19
176-
CommitDate: 2015-11-10
177-
UncommittedChanges: 0
178-
";
156+
const string versionCacheFileContent = """
157+
{
158+
"Major": 4,
159+
"Minor": 10,
160+
"Patch": 3,
161+
"PreReleaseTag": "test.19",
162+
"PreReleaseTagWithDash": "-test.19",
163+
"PreReleaseLabel": "test",
164+
"PreReleaseLabelWithDash": "-test",
165+
"PreReleaseNumber": 19,
166+
"BuildMetaData": null,
167+
"FullBuildMetaData": "Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
168+
"MajorMinorPatch": "4.10.3",
169+
"SemVer": "4.10.3-test.19",
170+
"AssemblySemVer": "4.10.3.0",
171+
"AssemblySemFileVer": "4.10.3.0",
172+
"FullSemVer": "4.10.3-test.19",
173+
"InformationalVersion": "4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
174+
"BranchName": "feature/test",
175+
"EscapedBranchName": "feature-test",
176+
"Sha": "dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
177+
"ShortSha": "dd2a29af",
178+
"CommitsSinceVersionSource": 19,
179+
"CommitDate": "2015-11-10T00:00:00.000Z",
180+
"UncommittedChanges": 0
181+
}
182+
""";
179183

180184
using var fixture = new EmptyRepositoryFixture();
181185
fixture.Repository.MakeACommit();
@@ -228,40 +232,42 @@ public void CacheFileIsMissing()
228232
gitVersionCalculator.CalculateVersionVariables();
229233

230234
var logsMessages = stringBuilder.ToString();
231-
logsMessages.ShouldContain("yml not found", Case.Insensitive, logsMessages);
235+
logsMessages.ShouldContain(".json not found", Case.Insensitive, logsMessages);
232236
}
233237

234238
[TestCase(ConfigurationFileLocator.DefaultFileName)]
235239
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName)]
236240
public void ConfigChangeInvalidatesCache(string configFileName)
237241
{
238-
const string versionCacheFileContent = @"
239-
Major: 4
240-
Minor: 10
241-
Patch: 3
242-
PreReleaseTag: test.19
243-
PreReleaseTagWithDash: -test.19
244-
PreReleaseLabel: test
245-
PreReleaseLabelWithDash: -test
246-
PreReleaseNumber: 19
247-
WeightedPreReleaseNumber: 19
248-
BuildMetaData:
249-
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
250-
MajorMinorPatch: 4.10.3
251-
SemVer: 4.10.3-test.19
252-
AssemblySemVer: 4.10.3.0
253-
AssemblySemFileVer: 4.10.3.0
254-
FullSemVer: 4.10.3-test.19
255-
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
256-
BranchName: feature/test
257-
EscapedBranchName: feature-test
258-
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
259-
ShortSha: dd2a29af
260-
VersionSourceSha: 4.10.2
261-
CommitsSinceVersionSource: 19
262-
CommitDate: 2015-11-10
263-
UncommittedChanges: 0
264-
";
242+
const string versionCacheFileContent = """
243+
{
244+
"Major": 4,
245+
"Minor": 10,
246+
"Patch": 3,
247+
"PreReleaseTag": "test.19",
248+
"PreReleaseTagWithDash": "-test.19",
249+
"PreReleaseLabel": "test",
250+
"PreReleaseLabelWithDash": "-test",
251+
"PreReleaseNumber": 19,
252+
"WeightedPreReleaseNumber": 19,
253+
"BuildMetaData": null,
254+
"FullBuildMetaData": "Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
255+
"MajorMinorPatch": "4.10.3",
256+
"SemVer": "4.10.3-test.19",
257+
"AssemblySemVer": "4.10.3.0",
258+
"AssemblySemFileVer": "4.10.3.0",
259+
"FullSemVer": "4.10.3-test.19",
260+
"InformationalVersion": "4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
261+
"BranchName": "feature/test",
262+
"EscapedBranchName": "feature-test",
263+
"Sha": "dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
264+
"ShortSha": "dd2a29af",
265+
"VersionSourceSha": "4.10.2",
266+
"CommitsSinceVersionSource": 19,
267+
"CommitDate": "2015-11-10T00:00:00.000Z",
268+
"UncommittedChanges": 0
269+
}
270+
""";
265271

266272
using var fixture = new EmptyRepositoryFixture();
267273

@@ -295,33 +301,35 @@ public void ConfigChangeInvalidatesCache(string configFileName)
295301
[Test]
296302
public void NoCacheBypassesCache()
297303
{
298-
const string versionCacheFileContent = @"
299-
Major: 4
300-
Minor: 10
301-
Patch: 3
302-
PreReleaseTag: test.19
303-
PreReleaseTagWithDash: -test.19
304-
PreReleaseLabel: test
305-
PreReleaseLabelWithDash: -test
306-
PreReleaseNumber: 19
307-
WeightedPreReleaseNumber: 19
308-
BuildMetaData:
309-
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
310-
MajorMinorPatch: 4.10.3
311-
SemVer: 4.10.3-test.19
312-
AssemblySemVer: 4.10.3.0
313-
AssemblySemFileVer: 4.10.3.0
314-
FullSemVer: 4.10.3-test.19
315-
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
316-
BranchName: feature/test
317-
EscapedBranchName: feature-test
318-
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
319-
ShortSha: dd2a29af
320-
VersionSourceSha: 4.10.2
321-
CommitsSinceVersionSource: 19
322-
CommitDate: 2015-11-10
323-
UncommittedChanges: 0
324-
";
304+
const string versionCacheFileContent = """
305+
{
306+
"Major": 4,
307+
"Minor": 10,
308+
"Patch": 3,
309+
"PreReleaseTag": "test.19",
310+
"PreReleaseTagWithDash": "-test.19",
311+
"PreReleaseLabel": "test",
312+
"PreReleaseLabelWithDash": "-test",
313+
"PreReleaseNumber": 19,
314+
"WeightedPreReleaseNumber": 19,
315+
"BuildMetaData": null,
316+
"FullBuildMetaData": "Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
317+
"MajorMinorPatch": "4.10.3",
318+
"SemVer": "4.10.3-test.19",
319+
"AssemblySemVer": "4.10.3.0",
320+
"AssemblySemFileVer": "4.10.3.0",
321+
"FullSemVer": "4.10.3-test.19",
322+
"InformationalVersion": "4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
323+
"BranchName": "feature/test",
324+
"EscapedBranchName": "feature-test",
325+
"Sha": "dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f",
326+
"ShortSha": "dd2a29af",
327+
"VersionSourceSha": "4.10.2",
328+
"CommitsSinceVersionSource": 19,
329+
"CommitDate": "2015-11-10T00:00:00.000Z",
330+
"UncommittedChanges": 0
331+
}
332+
""";
325333

326334
using var fixture = new EmptyRepositoryFixture();
327335

@@ -571,7 +579,7 @@ private IGitVersionCalculateTool GetGitVersionCalculator(GitVersionOptions gitVe
571579

572580
this.fileSystem = this.sp.GetRequiredService<IFileSystem>();
573581
this.log = this.sp.GetRequiredService<ILog>();
574-
this.gitVersionCache = this.sp.GetRequiredService<IGitVersionCache>();
582+
this.gitVersionCache = (GitVersionCache)this.sp.GetRequiredService<IGitVersionCache>();
575583

576584
return this.sp.GetRequiredService<IGitVersionCalculateTool>();
577585
}

src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static void WriteVersionVariables(this RepositoryFixtureBase fixture, str
108108

109109
using var stream = File.Open(versionFile, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
110110
using var writer = new StreamWriter(stream);
111-
writer.Write(versionVariables.ToJsonString());
111+
writer.Write(versionVariables.ToJson());
112112
}
113113

114114
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver,

src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public void Json()
2929

3030
var variableProvider = serviceProvider.GetRequiredService<IVariableProvider>();
3131
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
32-
variables.ToJsonString().ShouldMatchApproved(c => c.SubFolder("Approved"));
32+
variables.ToJson().ShouldMatchApproved(c => c.SubFolder("Approved"));
3333
}
3434
}

0 commit comments

Comments
 (0)