Skip to content

Commit

Permalink
Cap major 5
Browse files Browse the repository at this point in the history
  • Loading branch information
William Li committed Jan 28, 2020
1 parent df09f07 commit 3e8b475
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
26 changes: 19 additions & 7 deletions src/core-sdk-tasks/CalculateTemplateVersions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.Versioning;
Expand Down Expand Up @@ -49,11 +47,7 @@ public static
{
var aspNetCoreTemplate = NuGetVersion.Parse(aspNetCorePackageVersionTemplate);

// due to historical bug https://github.com/dotnet/core-sdk/issues/6243
// we need to increase patch version by one in order to "reset" existing install ComponentId
// more in the above bug's detail
var baseMajorMinorPatch = new NuGetVersion(aspNetCoreTemplate.Major, aspNetCoreTemplate.Minor,
aspNetCoreTemplate.Patch + _patchVersionResetOffset);
NuGetVersion baseMajorMinorPatch = GetBaseMajorMinorPatch(aspNetCoreTemplate);

string bundledTemplateInstallPath = aspNetCoreTemplate.IsPrerelease
? $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}-{versionSuffix}"
Expand All @@ -64,5 +58,23 @@ public static
bundledTemplateInstallPath,
$"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}");
}

private static NuGetVersion GetBaseMajorMinorPatch(NuGetVersion aspNetCoreTemplate)
{
// due to historical bug https://github.com/dotnet/core-sdk/issues/6243
// we need to increase patch version by one in order to "reset" existing install ComponentId
// more in the above bug's detail.
// There is no non-deterministic existing ComponentId under Major version 5.
// so only apply the patch bump when below 5

int basePatch =
aspNetCoreTemplate.Major < 5
? aspNetCoreTemplate.Patch + _patchVersionResetOffset
: aspNetCoreTemplate.Patch;

var baseMajorMinorPatch = new NuGetVersion(aspNetCoreTemplate.Major, aspNetCoreTemplate.Minor,
basePatch);
return baseMajorMinorPatch;
}
}
}
39 changes: 30 additions & 9 deletions test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,43 @@ namespace EndToEnd
public class CalculateTemplateVersionsTests
{
[Fact]
public void ItCanCalculateTemplateVersionsInStableBuilds()
public void WhenAspNetCoreTemplateMajorVersionLowerthan3ItCanCalculateTemplateVersionsInStableBuilds()
{
var result = CalculateTemplateVersions.Calculate("3.1.0", "014885", "dev");
result.BundledTemplateInstallPath.Should().Be("3.1.1",
"the patch is 1 higher than aspnetTemplateVersion due to https://github.com/dotnet/core-sdk/issues/6243");
result.BundledTemplateMsiVersion.Should().Be("3.1.1.014885");
result.BundledTemplateMajorMinorVersion.Should().Be("3.1");

result.Should()
.Be(("3.1.1.014885", "3.1.1", "3.1"),
"the patch is 1 higher than aspnetTemplateVersion " +
"due to https://github.com/dotnet/core-sdk/issues/6243");
}

[Fact]
public void WhenAspNetCoreTemplateMajorVersionLowerthan3ItCanCalculateTemplateVersionsInNonStableBuilds()
{
var result = CalculateTemplateVersions.Calculate("3.0.0-alpha.1.20071.6", "014885", "dev");

result.Should()
.Be(("3.0.1.014885", "3.0.1-dev", "3.0"));
}

[Fact]
public void ItCanCalculateTemplateVersionsInNonStableBuilds()
public void WhenAspNetCoreTemplateMajorVersionHigherthan3ItCanCalculateTemplateVersionsInStableBuilds()
{
var result = CalculateTemplateVersions.Calculate("5.1.0", "014885", "dev");

result.Should()
.Be(("5.1.0.014885", "5.1.0", "5.1"),
"the patch align with AspNetCoreTemplateMajorVersion again, " +
"since there is no non-deterministic existing ComponentId under Major version 5.");
}

[Fact]
public void WhenAspNetCoreTemplateMajorVersionHigherthan3ItCanCalculateTemplateVersionsInNonStableBuilds()
{
var result = CalculateTemplateVersions.Calculate("5.0.0-alpha.1.20071.6", "014885", "dev");
result.BundledTemplateInstallPath.Should().Be("5.0.1-dev");
result.BundledTemplateMsiVersion.Should().Be("5.0.1.014885");
result.BundledTemplateMajorMinorVersion.Should().Be("5.0");

result.Should()
.Be(("5.0.0.014885", "5.0.0-dev", "5.0"));
}
}
}

0 comments on commit 3e8b475

Please sign in to comment.