-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6245 from wli3/fix-msi-gg-release/3.1.1xx
Fix msi gg release/3.1.1xx
- Loading branch information
Showing
8 changed files
with
185 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// 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 Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using NuGet.Versioning; | ||
|
||
namespace Microsoft.DotNet.Cli.Build | ||
{ | ||
public class CalculateTemplateVersions : Task | ||
{ | ||
[Required] | ||
public string AspNetCorePackageVersionTemplate { get; set; } | ||
|
||
[Required] | ||
public string GitCommitCount { get; set; } | ||
|
||
[Required] | ||
public string VersionSuffix { get; set; } | ||
|
||
[Output] | ||
public string BundledTemplateMSIVersion { get; set; } | ||
|
||
[Output] | ||
public string BundledTemplateInstallPath { get; set; } | ||
|
||
[Output] | ||
public string BundledTemplateMajorMinorVersion { get; set; } | ||
|
||
private const int _patchVersionResetOffset = 1; | ||
|
||
public override bool Execute() | ||
{ | ||
var result = Calculate(AspNetCorePackageVersionTemplate, GitCommitCount, VersionSuffix); | ||
BundledTemplateMSIVersion = result.BundledTemplateMsiVersion; | ||
BundledTemplateInstallPath = result.BundledTemplateInstallPath; | ||
BundledTemplateMajorMinorVersion = result.BundledTemplateMajorMinorVersion; | ||
|
||
return true; | ||
} | ||
|
||
public static | ||
(string BundledTemplateMsiVersion, | ||
string BundledTemplateInstallPath, | ||
string BundledTemplateMajorMinorVersion) Calculate(string aspNetCorePackageVersionTemplate, | ||
string gitCommitCount, string versionSuffix) | ||
{ | ||
var aspNetCoreTemplate = NuGetVersion.Parse(aspNetCorePackageVersionTemplate); | ||
|
||
NuGetVersion baseMajorMinorPatch = GetBaseMajorMinorPatch(aspNetCoreTemplate); | ||
|
||
string bundledTemplateInstallPath = aspNetCoreTemplate.IsPrerelease | ||
? $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}-{versionSuffix}" | ||
: $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}"; | ||
|
||
return ( | ||
$"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}.{gitCommitCount}", | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test/core-sdk-tasks.Tests/CalculateTemplateVerionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
using Microsoft.DotNet.Cli.Build; | ||
|
||
namespace EndToEnd | ||
{ | ||
public class CalculateTemplateVersionsTests | ||
{ | ||
[Fact] | ||
public void WhenAspNetCoreTemplateMajorVersionLowerthan3ItCanCalculateTemplateVersionsInStableBuilds() | ||
{ | ||
var result = CalculateTemplateVersions.Calculate("3.1.0", "014885", "dev"); | ||
|
||
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 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.Should() | ||
.Be(("5.0.0.014885", "5.0.0-dev", "5.0")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(CoreSdkTargetFramework);net472</TargetFrameworks> | ||
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">$(CoreSdkTargetFramework)</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="4.18.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\core-sdk-tasks\core-sdk-tasks.csproj" /> | ||
</ItemGroup> | ||
</Project> |