Merge pull request #16 from unoplatform/dev/jela/version-major-compare

feat: Allow for package diff manifest to provide a partial version match
This commit is contained in:
Jérôme Laban 2022-08-29 15:30:02 -04:00 коммит произвёл GitHub
Родитель 95ddd0e9bd fe3f01b8f6
Коммит 25fe2d8d17
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 127 добавлений и 12 удалений

Просмотреть файл

@ -47,5 +47,27 @@ namespace Uno.PackageDiff.Tests
Assert.IsNotNull(context.IgnoreSet);
Assert.IsFalse(ReportAnalyzer.GenerateReport(StreamWriter.Null, comparison, context.IgnoreSet));
}
[TestMethod]
public void When_Ignore_All_Changes_With_Major_Minor_Only()
{
var context = _builder.BuildAssemblies();
var comparison = AssemblyComparer.CompareTypes(context.BaseAssembly, context.TargetAssembly);
Assert.IsNotNull(context.IgnoreSet);
Assert.IsFalse(ReportAnalyzer.GenerateReport(StreamWriter.Null, comparison, context.IgnoreSet));
}
[TestMethod]
public void When_Ignore_All_Changes_With_Major_Only()
{
var context = _builder.BuildAssemblies();
var comparison = AssemblyComparer.CompareTypes(context.BaseAssembly, context.TargetAssembly);
Assert.IsNotNull(context.IgnoreSet);
Assert.IsFalse(ReportAnalyzer.GenerateReport(StreamWriter.Null, comparison, context.IgnoreSet));
}
}
}

Просмотреть файл

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Uno.PackageDiff.Tests.Sources
{
public class When_Ignore_All_Changes_To_Type
{
public int OldProperty1 { get; }
public string OldProperty2 { get; protected set; }
public void OldMethod1(float f) { }
public double OldMethod2() => 42d;
public event Action OldEvent;
}
}

Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<DiffIgnore>
<IgnoreSets>
<IgnoreSet baseVersion="1.0">
<Types>
<Member fullName="Uno.PackageDiff.Tests.Sources.When_Ignore_All_Changes_To_Type"/>
</Types>
</IgnoreSet>
</IgnoreSets>
</DiffIgnore>

Просмотреть файл

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Uno.PackageDiff.Tests.Sources
{
public class When_Ignore_All_Changes_To_Type
{
}
}

Просмотреть файл

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Uno.PackageDiff.Tests.Sources
{
public class When_Ignore_All_Changes_To_Type
{
public int OldProperty1 { get; }
public string OldProperty2 { get; protected set; }
public void OldMethod1(float f) { }
public double OldMethod2() => 42d;
public event Action OldEvent;
}
}

Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<DiffIgnore>
<IgnoreSets>
<IgnoreSet baseVersion="1">
<Types>
<Member fullName="Uno.PackageDiff.Tests.Sources.When_Ignore_All_Changes_To_Type"/>
</Types>
</IgnoreSet>
</IgnoreSets>
</DiffIgnore>

Просмотреть файл

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Uno.PackageDiff.Tests.Sources
{
public class When_Ignore_All_Changes_To_Type
{
}
}

Просмотреть файл

@ -24,11 +24,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Mono.Cecil" Version="0.10.3" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.8.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.2.0" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -31,13 +31,28 @@ namespace Uno.PackageDiff
var dcs = new XmlSerializer(typeof(DiffIgnore));
var diffIgnore = (DiffIgnore)dcs.Deserialize(stream);
if(diffIgnore.IgnoreSets.FirstOrDefault(s => s.BaseVersion == baseVersion) is IgnoreSet set)
if(diffIgnore.IgnoreSets.FirstOrDefault(s => CompareVersion(baseVersion, s.BaseVersion)) is IgnoreSet set)
{
return set;
}
return new IgnoreSet();
}
private static bool CompareVersion(string baseVersion, string ignoreSetVersion)
{
var ignoreSetVersionDotCount = ignoreSetVersion.Count(c => c == '.') ;
var baseVersion2 = new Version(baseVersion);
var ignoreSetVersion2 = new Version(ignoreSetVersionDotCount == 0 ? ignoreSetVersion + ".0" : ignoreSetVersion);
return ignoreSetVersionDotCount switch
{
0 => baseVersion2.Major == ignoreSetVersion2.Major,
1 => baseVersion2.Major == ignoreSetVersion2.Major
&& baseVersion2.Minor == ignoreSetVersion2.Minor,
_ => ignoreSetVersion == baseVersion
};
}
}
public class IgnoreSet

Просмотреть файл

@ -16,17 +16,17 @@
</PropertyGroup>
<PropertyGroup>
<PackageProjectUrl>https://github.com/nventive/Uno.PackageDiff</PackageProjectUrl>
<PackageProjectUrl>https://github.com/unoplatform/Uno.PackageDiff</PackageProjectUrl>
<PackageIconUrl>https://nv-assets.azurewebsites.net/logos/uno.png</PackageIconUrl>
<RepositoryUrl>https://github.com/nventive/Uno.PackageDiff</RepositoryUrl>
<RepositoryUrl>https://github.com/unoplatform/Uno.PackageDiff</RepositoryUrl>
<Description>This package provides a nuget package diffing CLI tool.</Description>
<Copyright>Copyright (C) 2015-2019 nventive inc. - all rights reserved</Copyright>
<Copyright>Copyright (C) 2015-2022 Uno Platform inc. - all rights reserved</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mono.Cecil" Version="0.10.3" />
<PackageReference Include="Mono.Options" Version="5.3.0.1" />
<PackageReference Include="NuGet.Protocol" Version="4.9.3" />
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
<PackageReference Include="NuGet.Protocol" Version="6.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>