From 3ec20943f48ab3ed5be61b522f09f915159b0188 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Sat, 19 Oct 2024 22:51:06 -0400 Subject: [PATCH 1/5] feat: Add support for upgrade policy, upgrade to net8 --- .editorconfig | 96 ++++++++++++++++--- doc/nuget-updater.md | 12 +++ src/NvGet.Tests/Constants.cs | 2 +- src/NvGet.Tests/NvGet.Tests.csproj | 23 +++-- .../Resources/version_overrides.json | 4 +- .../Tools/ConsoleArgsParserTests.cs | 1 - .../Tools/Updater/PackageReferenceTests.cs | 2 +- .../Tools/Updater/UpdaterParametersTests.cs | 34 ++++++- .../NvGet.Tools.Downloader.csproj | 3 +- .../NvGet.Tools.Hierarchy.csproj | 3 +- .../Arguments/ConsoleArgsContext.cs | 6 +- .../NvGet.Tools.Updater.csproj | 3 +- src/NvGet/Extensions/DictionaryExtensions.cs | 24 ----- src/NvGet/Extensions/StringExtensions.cs | 2 +- src/NvGet/NvGet.csproj | 5 +- .../Tools/Updater/Entities/UpdateResult.cs | 2 + .../Updater/Entities/UpdaterParameters.cs | 2 +- .../Tools/Updater/Entities/UpgradePolicy.cs | 8 ++ .../Extensions/UpdaterParametersExtension.cs | 33 ++++++- src/NvGet/Tools/Updater/NuGetUpdater.cs | 3 +- 20 files changed, 201 insertions(+), 67 deletions(-) create mode 100644 src/NvGet/Tools/Updater/Entities/UpgradePolicy.cs diff --git a/.editorconfig b/.editorconfig index af08010..5ca28ea 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,4 @@ -root = true - -[*] +[*] end_of_line = crlf tab_width = 4 trim_trailing_whitespace = true @@ -43,7 +41,7 @@ csharp_new_line_before_open_brace = all csharp_new_line_between_query_expression_clauses = true # http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_prefer_braces -csharp_prefer_braces = true:suggestion +csharp_prefer_braces = true:silent # http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_prefer_simple_default_expression csharp_prefer_simple_default_expression = true:suggestion @@ -124,22 +122,22 @@ csharp_space_between_square_brackets = false csharp_style_conditional_delegate_call = true:suggestion # http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_style_expression_bodied_accessors -csharp_style_expression_bodied_accessors = true:suggestion +csharp_style_expression_bodied_accessors = true:silent # http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_style_expression_bodied_constructors -csharp_style_expression_bodied_constructors = false:suggestion +csharp_style_expression_bodied_constructors = false:silent # http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_style_expression_bodied_indexers -csharp_style_expression_bodied_indexers = true:suggestion +csharp_style_expression_bodied_indexers = true:silent # http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_style_expression_bodied_methods -csharp_style_expression_bodied_methods = true:suggestion +csharp_style_expression_bodied_methods = false:silent # http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_style_expression_bodied_operators -csharp_style_expression_bodied_operators = true:suggestion +csharp_style_expression_bodied_operators = false:silent # http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_style_expression_bodied_properties -csharp_style_expression_bodied_properties = true:suggestion +csharp_style_expression_bodied_properties = true:silent # http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers#csharp_style_inlined_variable_declaration csharp_style_inlined_variable_declaration = true:suggestion @@ -207,6 +205,22 @@ indent_style = tab [{*.ts, *.json}] indent_style = tab +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_prefer_system_threading_lock = true:suggestion +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_prefer_null_check_over_type_check = true:suggestion +csharp_style_prefer_local_over_anonymous_function = true:suggestion +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion +csharp_style_prefer_tuple_swap = true:suggestion +csharp_style_prefer_utf8_string_literals = true:suggestion [*.csproj] indent_style = tab @@ -220,4 +234,64 @@ indent_style = space indent_style = space [*.md] -indent_style = space \ No newline at end of file +indent_style = space +[*.{cs,vb}] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_style_operator_placement_when_wrapping = beginning_of_line +indent_size = 4 +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion +dotnet_style_namespace_match_folder = true:suggestion diff --git a/doc/nuget-updater.md b/doc/nuget-updater.md index 178b60b..b5e9054 100644 --- a/doc/nuget-updater.md +++ b/doc/nuget-updater.md @@ -76,6 +76,18 @@ versions.json example: { "PackageId": "Uno.Wasm.Bootstrap", "UpdatedVersion": "(,1.2.0-dev.18]" -> Resolves 1.2.0-dev.18 (-v=dev + -v=stable), 1.0.10 (-v=stable) + }, + { + "PackageId": "Uno.WinUI", + "UpgradePolicy": "Minor" -> Only upgrades when a minor version of the same major is available + }, + { + "PackageId": "Uno.Core", + "UpgradePolicy": "Major" -> Always upgrades + }, + { + "PackageId": "Uno.Core.Extensions", + "UpgradePolicy": "Patch" -> Only upgrades when a patch version of the same major,minor is available } ] ``` diff --git a/src/NvGet.Tests/Constants.cs b/src/NvGet.Tests/Constants.cs index 1d732b0..59dc8ef 100644 --- a/src/NvGet.Tests/Constants.cs +++ b/src/NvGet.Tests/Constants.cs @@ -12,7 +12,7 @@ public static class Constants public static readonly Dictionary TestPackages = new Dictionary { {"unoplatform.NuGet.Updater", new[] { "1.0-beta.1" } }, - {"Uno.UI", new[] { "2.1.39", "2.2.0", "2.3.0-dev.44", "2.3.0-dev.48", "2.3.0-dev.58", "5.0.0-feature.5x.88" } }, + {"Uno.UI", new[] { "2.1.39", "2.2.0", "2.3.0-dev.44", "2.3.0-dev.48", "2.3.0-dev.58", "3.0.0-dev.2", "5.0.0-feature.5x.88" } }, }; public static readonly TestPackageFeed TestFeed = new TestPackageFeed(TestFeedUri, TestPackages); diff --git a/src/NvGet.Tests/NvGet.Tests.csproj b/src/NvGet.Tests/NvGet.Tests.csproj index 027a0ae..6874216 100644 --- a/src/NvGet.Tests/NvGet.Tests.csproj +++ b/src/NvGet.Tests/NvGet.Tests.csproj @@ -1,15 +1,19 @@  - net5.0 + net8.0 false - - - - + + + + + + + + @@ -18,10 +22,17 @@ - PreserveNewest + Always + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/src/NvGet.Tests/Resources/version_overrides.json b/src/NvGet.Tests/Resources/version_overrides.json index 8c9164d..a557b39 100644 --- a/src/NvGet.Tests/Resources/version_overrides.json +++ b/src/NvGet.Tests/Resources/version_overrides.json @@ -1,4 +1,6 @@ [ { "PackageId": "Newtonsoft.Json", "UpdatedVersion": "12.0.1" }, - { "PackageId": "Microsoft.Extensions.Logging", "UpdatedVersion": "3.1.2" } + { "PackageId": "Microsoft.Extensions.Logging", "UpdatedVersion": "3.1.2" }, + { "PackageId": "Uno.UI", "UpgradePolicy": "Minor", "UpdatedVersion": "3.1.2" }, + { "PackageId": "Uno.WinUI", "UpgradePolicy": "Patch", "UpdatedVersion": "3.1.2" } ] diff --git a/src/NvGet.Tests/Tools/ConsoleArgsParserTests.cs b/src/NvGet.Tests/Tools/ConsoleArgsParserTests.cs index c8e0e2e..917f302 100644 --- a/src/NvGet.Tests/Tools/ConsoleArgsParserTests.cs +++ b/src/NvGet.Tests/Tools/ConsoleArgsParserTests.cs @@ -158,7 +158,6 @@ public void Given_UpdaterParametersArgument_ContextCollectionPropertyIsSet(Expre } [TestMethod] - [DeploymentItem(PinnedVersionJsonPath)] public void Given_UpdaterParametersArgument_ContextTargetVersionIsSet() { var arguments = new[] { $"--versionOverrides={PinnedVersionJsonPath}" }; diff --git a/src/NvGet.Tests/Tools/Updater/PackageReferenceTests.cs b/src/NvGet.Tests/Tools/Updater/PackageReferenceTests.cs index fc7e5e8..0f0d118 100644 --- a/src/NvGet.Tests/Tools/Updater/PackageReferenceTests.cs +++ b/src/NvGet.Tests/Tools/Updater/PackageReferenceTests.cs @@ -60,7 +60,7 @@ public async Task GivenManualUpdates_AndVersionNotInFeed_ManualVersionIsFound() Feeds = { Constants.TestFeed }, VersionOverrides = { - { reference.Identity.Id, (true, new VersionRange(reference.Identity.Version, true, reference.Identity.Version, true)) }, + { reference.Identity.Id, (true, UpgradePolicy.Major, new VersionRange(reference.Identity.Version, true, reference.Identity.Version, true)) }, }, }; diff --git a/src/NvGet.Tests/Tools/Updater/UpdaterParametersTests.cs b/src/NvGet.Tests/Tools/Updater/UpdaterParametersTests.cs index 2fe01e5..be77165 100644 --- a/src/NvGet.Tests/Tools/Updater/UpdaterParametersTests.cs +++ b/src/NvGet.Tests/Tools/Updater/UpdaterParametersTests.cs @@ -56,7 +56,7 @@ public async Task GivenSinglePartTag_NoOverride() var version = await parameters.GetLatestVersion(CancellationToken.None, reference); - Assert.AreEqual(NuGetVersion.Parse("2.3.0-dev.58"), version.Version); + Assert.AreEqual(NuGetVersion.Parse("3.0.0-dev.2"), version.Version); } [TestMethod] @@ -70,7 +70,7 @@ public async Task GivenRangeOverrides_CorrectVersionsAreResolved() Feeds = { Constants.TestFeed }, VersionOverrides = { - { reference.Identity.Id, (false, VersionRange.Parse("(,2.3.0-dev.48]")) }, + { reference.Identity.Id, (false, UpgradePolicy.Major, VersionRange.Parse("(,2.3.0-dev.48]")) }, }, }; @@ -78,7 +78,33 @@ public async Task GivenRangeOverrides_CorrectVersionsAreResolved() Assert.AreEqual(NuGetVersion.Parse("2.3.0-dev.48"), version.Version); - parameters.VersionOverrides["Uno.UI"] = (false, VersionRange.Parse("(,2.3.0-dev.48)")); + parameters.VersionOverrides["Uno.UI"] = (false, UpgradePolicy.Major, VersionRange.Parse("(,2.3.0-dev.48)")); + + version = await parameters.GetLatestVersion(CancellationToken.None, reference); + + Assert.AreEqual(NuGetVersion.Parse("2.3.0-dev.44"), version.Version); + } + + [TestMethod] + public async Task GivenRangeOverrides_KeepMinor() + { + var reference = new PackageReference("Uno.UI", "2.1.39"); + + var parameters = new UpdaterParameters + { + TargetVersions = { "dev", "stable" }, + Feeds = { Constants.TestFeed }, + VersionOverrides = + { + { reference.Identity.Id, (false, UpgradePolicy.Minor, VersionRange.Parse("0.0.0.0")) }, + }, + }; + + var version = await parameters.GetLatestVersion(CancellationToken.None, reference); + + Assert.AreEqual(NuGetVersion.Parse("2.3.0-dev.58"), version.Version); + + parameters.VersionOverrides["Uno.UI"] = (false, UpgradePolicy.Minor, VersionRange.Parse("(,2.3.0-dev.48)")); version = await parameters.GetLatestVersion(CancellationToken.None, reference); @@ -96,7 +122,7 @@ public async Task GivenRangeOverrides_CorrectVersionsAreResolved_AndTargetVersio Feeds = { Constants.TestFeed }, VersionOverrides = { - { reference.Identity.Id, (false, VersionRange.Parse("(,2.3.0-dev.48]")) }, + { reference.Identity.Id, (false, UpgradePolicy.Major, VersionRange.Parse("(,2.3.0-dev.48]")) }, }, }; diff --git a/src/NvGet.Tools.Downloader/NvGet.Tools.Downloader.csproj b/src/NvGet.Tools.Downloader/NvGet.Tools.Downloader.csproj index e2b3aa8..c208915 100644 --- a/src/NvGet.Tools.Downloader/NvGet.Tools.Downloader.csproj +++ b/src/NvGet.Tools.Downloader/NvGet.Tools.Downloader.csproj @@ -2,11 +2,10 @@ Exe - net5.0 + net8.0 true true nugetdownloader - latest $(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage diff --git a/src/NvGet.Tools.Hierarchy/NvGet.Tools.Hierarchy.csproj b/src/NvGet.Tools.Hierarchy/NvGet.Tools.Hierarchy.csproj index f206370..87f7272 100644 --- a/src/NvGet.Tools.Hierarchy/NvGet.Tools.Hierarchy.csproj +++ b/src/NvGet.Tools.Hierarchy/NvGet.Tools.Hierarchy.csproj @@ -2,11 +2,10 @@ Exe - net5.0 + net8.0 true true nugethierarchy - latest $(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage diff --git a/src/NvGet.Tools.Shared/Arguments/ConsoleArgsContext.cs b/src/NvGet.Tools.Shared/Arguments/ConsoleArgsContext.cs index 560ca1d..3d3cadd 100644 --- a/src/NvGet.Tools.Shared/Arguments/ConsoleArgsContext.cs +++ b/src/NvGet.Tools.Shared/Arguments/ConsoleArgsContext.cs @@ -102,7 +102,7 @@ Action TryParseAndSet(Func parse, Action set) public void WriteOptionDescriptions(TextWriter writer) => CreateOptionsFor(default).WriteOptionDescriptions(writer); - internal static Dictionary LoadOverrides(string inputPathOrUrl) + internal static Dictionary LoadOverrides(string inputPathOrUrl) { var results = LoadFromStreamAsync() @@ -112,14 +112,14 @@ Action TryParseAndSet(Func parse, Action set) return results.ToDictionary( r => r.PackageId, r => NuGetVersion.TryParse(r.UpdatedVersion, out var version) ? - (true, new VersionRange( + (true, r.UpgradePolicy, new VersionRange( minVersion: version, includeMinVersion: true, maxVersion: version, includeMaxVersion: true, floatRange: null, originalString: null)) : - (false, VersionRange.Parse(r.UpdatedVersion))); + (false, r.UpgradePolicy, VersionRange.Parse(r.UpdatedVersion))); async Task> LoadFromStreamAsync() { diff --git a/src/NvGet.Tools.Updater/NvGet.Tools.Updater.csproj b/src/NvGet.Tools.Updater/NvGet.Tools.Updater.csproj index 1faa0d2..4687148 100644 --- a/src/NvGet.Tools.Updater/NvGet.Tools.Updater.csproj +++ b/src/NvGet.Tools.Updater/NvGet.Tools.Updater.csproj @@ -2,11 +2,10 @@ Exe - net5.0;net6.0;net7.0 + net7.0 true true nugetupdater - latest $(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage major diff --git a/src/NvGet/Extensions/DictionaryExtensions.cs b/src/NvGet/Extensions/DictionaryExtensions.cs index f44d5ae..179bcd8 100644 --- a/src/NvGet/Extensions/DictionaryExtensions.cs +++ b/src/NvGet/Extensions/DictionaryExtensions.cs @@ -30,29 +30,5 @@ Func update dictionary.Add(key, update(default)); } } - -#if !WINDOWS_UWP - public static bool TryAdd(this IDictionary dictionary, TKey key, TValue value) - { - if(dictionary.ContainsKey(key)) - { - return false; - } - - dictionary.Add(key, value); - - return true; - } - - public static TValue GetValueOrDefault(this IDictionary dictionary, TKey key) - { - if(dictionary.ContainsKey(key)) - { - return dictionary[key]; - } - - return default; - } -#endif } } diff --git a/src/NvGet/Extensions/StringExtensions.cs b/src/NvGet/Extensions/StringExtensions.cs index 69e7387..8625bda 100644 --- a/src/NvGet/Extensions/StringExtensions.cs +++ b/src/NvGet/Extensions/StringExtensions.cs @@ -60,7 +60,7 @@ public static string GetEnumeration(this IEnumerable values) } else { - return $"{string.Join(", ", EnumerableExtensions.SkipLast(values, 1))} and {values.Last()}"; + return $"{string.Join(", ", values.SkipLast(1))} and {values.Last()}"; } } } diff --git a/src/NvGet/NvGet.csproj b/src/NvGet/NvGet.csproj index c639aa9..f789040 100644 --- a/src/NvGet/NvGet.csproj +++ b/src/NvGet/NvGet.csproj @@ -1,9 +1,8 @@ - netstandard20;net472 + net8.0 $(NoWarn);CA1068;NU1701 true - 9.0 @@ -18,7 +17,7 @@ - + diff --git a/src/NvGet/Tools/Updater/Entities/UpdateResult.cs b/src/NvGet/Tools/Updater/Entities/UpdateResult.cs index 04baa02..a3d03ef 100644 --- a/src/NvGet/Tools/Updater/Entities/UpdateResult.cs +++ b/src/NvGet/Tools/Updater/Entities/UpdateResult.cs @@ -10,6 +10,8 @@ public class UpdateResult : IEquatable public string UpdatedVersion { get; set; } + public UpgradePolicy UpgradePolicy { get; set; } + public override int GetHashCode() => PackageId?.GetHashCode() ?? 0; public bool Equals(UpdateResult other) => other == null diff --git a/src/NvGet/Tools/Updater/Entities/UpdaterParameters.cs b/src/NvGet/Tools/Updater/Entities/UpdaterParameters.cs index 40cbe7a..a00da8e 100644 --- a/src/NvGet/Tools/Updater/Entities/UpdaterParameters.cs +++ b/src/NvGet/Tools/Updater/Entities/UpdaterParameters.cs @@ -58,7 +58,7 @@ public class UpdaterParameters /// /// Gets the version range overrides for specific packages. /// - public IDictionary VersionOverrides { get; } = new Dictionary(); + public IDictionary VersionOverrides { get; } = new Dictionary(); /// /// Gets the csproj properties that should be updated for corresponding package. diff --git a/src/NvGet/Tools/Updater/Entities/UpgradePolicy.cs b/src/NvGet/Tools/Updater/Entities/UpgradePolicy.cs new file mode 100644 index 0000000..76d0099 --- /dev/null +++ b/src/NvGet/Tools/Updater/Entities/UpgradePolicy.cs @@ -0,0 +1,8 @@ +namespace NvGet.Tools.Updater.Entities; + +public enum UpgradePolicy +{ + Major, + Minor, + Patch, +} diff --git a/src/NvGet/Tools/Updater/Extensions/UpdaterParametersExtension.cs b/src/NvGet/Tools/Updater/Extensions/UpdaterParametersExtension.cs index 96b3048..2168318 100644 --- a/src/NvGet/Tools/Updater/Extensions/UpdaterParametersExtension.cs +++ b/src/NvGet/Tools/Updater/Extensions/UpdaterParametersExtension.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using NuGet.Versioning; using NvGet.Contracts; using NvGet.Entities; using NvGet.Extensions; @@ -107,9 +108,14 @@ PackageReference reference var versionsPerTarget = availableVersions .SelectMany(x => x) - .Where(v => manualVersion.range?.Satisfies(v.Version) ?? true) + .Where(v => manualVersion + .range?.Satisfies(v.Version) ?? true) + .Where(v => IsUpgradable(manualVersion.upgradePolicy, reference, v.Version)) .OrderByDescending(v => v) - .GroupBy(version => parameters.TargetVersions.FirstOrDefault(t => version.IsMatchingVersion(t, parameters.Strict))) + .GroupBy(version => parameters + .TargetVersions + .FirstOrDefault( + t => version.IsMatchingVersion(t, parameters.Strict))) .Where(g => g.Key.HasValue()); return versionsPerTarget @@ -117,5 +123,28 @@ PackageReference reference .OrderByDescending(v => v.Version) .FirstOrDefault(); } + + private static bool IsUpgradable( + UpgradePolicy upgradePolicy + , PackageReference reference + , NuGetVersion version) + { + if (upgradePolicy == UpgradePolicy.Major) + { + return true; + } + else if(upgradePolicy == UpgradePolicy.Minor) + { + return version.Version < new Version(reference.Identity.Version.Major + 1, 0, 0); + } + else if(upgradePolicy == UpgradePolicy.Patch) + { + return version.Version < new Version(reference.Identity.Version.Major, reference.Identity.Version.Minor + 1, 0); + } + else + { + throw new NotSupportedException($"Upgrade policy {upgradePolicy} is not supported"); + } + } } } diff --git a/src/NvGet/Tools/Updater/NuGetUpdater.cs b/src/NvGet/Tools/Updater/NuGetUpdater.cs index 0d1e71b..6280911 100644 --- a/src/NvGet/Tools/Updater/NuGetUpdater.cs +++ b/src/NvGet/Tools/Updater/NuGetUpdater.cs @@ -11,7 +11,6 @@ using NvGet.Tools.Updater.Entities; using NvGet.Tools.Updater.Extensions; using NvGet.Tools.Updater.Log; -using Uno.Extensions; #if WINDOWS_UWP using XmlDocument = Windows.Data.Xml.Dom.XmlDocument; @@ -71,7 +70,7 @@ public async Task> UpdatePackages(CancellationToken ct { var targetVersionText = string.Join(" or ", _parameters.TargetVersions); - if(targetVersionText.HasValue()) + if(!string.IsNullOrWhiteSpace(targetVersionText)) { targetVersionText += " "; } From f22177c1e0ecc097194920f07a3f303203744455 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Sat, 19 Oct 2024 23:00:58 -0400 Subject: [PATCH 2/5] chore: Adjust for deprecated --- .github/pull_request_template.md | 2 +- .github/workflows/main.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 841cbc9..d8ac85c 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -32,7 +32,7 @@ What kind of change does this PR introduce? Please check if your PR fulfills the following requirements: - [ ] Tested code with current [supported SDKs](../README.md#supported) -- [ ] Docs have been added/updated which fit [documentation template](https://github.com/unoplatform/Uno/blob/master/doc/.feature-template.md). (for bug fixes / features) +- [ ] Docs have been added/updated which fit [documentation template](https://github.com/unoplatform/uno/blob/master/doc/.feature-template.md). (for bug fixes / features) - [ ] [Unit Tests and/or UI Tests](doc/articles/working-with-the-samples-apps.md) for the changes have been added (for bug fixes / features) (if applicable) - [ ] [Wasm UI Tests](doc/articles/working-with-the-samples-apps.md#running-the-webassembly-ui-tests-snapshots) are not showing unexpected any differences. Validate PR `Screenshots Compare Test Run` results. - [ ] Contains **NO** breaking changes diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6fe4d34..904991c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -62,7 +62,7 @@ jobs: dotnet test - name: Upload Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: NuGet path: .\artifacts @@ -124,7 +124,7 @@ jobs: run: tfx extension create --json --no-color --output-path .\artifacts\Build.Tasks.${{ steps.gitversion.outputs.MajorMinorPatch }}.vsix --override "{""version"":""${{ steps.gitversion.outputs.MajorMinorPatch }}""}" - name: Upload Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: extensions path: extensions/azuredevops/artifacts @@ -161,7 +161,7 @@ jobs: build\SignClient sign -i artifacts\*.nupkg -c build\SignClient.json -r "${{ secrets.UNO_PLATFORM_CODESIGN_USERNAME }}" -s "${{ secrets.UNO_PLATFORM_CODESIGN_SECRET }}" -n "Uno Nuget Tools" -d "Uno Nuget Tools" -u "https://github.com/unoplatform/nuget.updater" - name: Upload Signed Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: NuGet-Signed path: .\artifacts From 053e951e5658410beb4a498736e97883fd18d095 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Sat, 19 Oct 2024 23:03:11 -0400 Subject: [PATCH 3/5] chore: Adjust net version --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 904991c..caf0948 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: '7.0.100' + dotnet-version: '8.0.100' - name: Setup GitVersion uses: gittools/actions/gitversion/setup@v0.9.9 From 5aaef9d4c934a4cb4b99b64230d0b594a3549663 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Sat, 19 Oct 2024 23:06:45 -0400 Subject: [PATCH 4/5] chore: Adjust more net8 --- src/NvGet.Tools.Updater/NvGet.Tools.Updater.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NvGet.Tools.Updater/NvGet.Tools.Updater.csproj b/src/NvGet.Tools.Updater/NvGet.Tools.Updater.csproj index 4687148..bb4098d 100644 --- a/src/NvGet.Tools.Updater/NvGet.Tools.Updater.csproj +++ b/src/NvGet.Tools.Updater/NvGet.Tools.Updater.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 true true nugetupdater From 7b4c8b4b1230f2f484859661b9be8f1abb728c39 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Sat, 19 Oct 2024 23:25:27 -0400 Subject: [PATCH 5/5] chore: Add patch upgrade test --- src/NvGet.Tests/Constants.cs | 7 +++++++ .../Tools/Updater/UpdaterParametersTests.cs | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/NvGet.Tests/Constants.cs b/src/NvGet.Tests/Constants.cs index 59dc8ef..04a9156 100644 --- a/src/NvGet.Tests/Constants.cs +++ b/src/NvGet.Tests/Constants.cs @@ -16,5 +16,12 @@ public static class Constants }; public static readonly TestPackageFeed TestFeed = new TestPackageFeed(TestFeedUri, TestPackages); + + public static readonly Dictionary TestPackages2 = new Dictionary + { + {"Uno.UI", new[] { "2.1.39", "2.2.0", "2.2.1", "2.3.0" } }, + }; + + public static readonly TestPackageFeed TestFeed2 = new TestPackageFeed(TestFeedUri, TestPackages2); } } diff --git a/src/NvGet.Tests/Tools/Updater/UpdaterParametersTests.cs b/src/NvGet.Tests/Tools/Updater/UpdaterParametersTests.cs index be77165..ad0bb10 100644 --- a/src/NvGet.Tests/Tools/Updater/UpdaterParametersTests.cs +++ b/src/NvGet.Tests/Tools/Updater/UpdaterParametersTests.cs @@ -111,6 +111,26 @@ public async Task GivenRangeOverrides_KeepMinor() Assert.AreEqual(NuGetVersion.Parse("2.3.0-dev.44"), version.Version); } + [TestMethod] + public async Task GivenRangeOverrides_KeepPatch() + { + var reference = new PackageReference("Uno.UI", "2.2.0"); + + var parameters = new UpdaterParameters + { + TargetVersions = { "dev", "stable" }, + Feeds = { Constants.TestFeed2 }, + VersionOverrides = + { + { reference.Identity.Id, (false, UpgradePolicy.Patch, VersionRange.Parse("0.0.0.0")) }, + }, + }; + + var version = await parameters.GetLatestVersion(CancellationToken.None, reference); + + Assert.AreEqual(NuGetVersion.Parse("2.2.1"), version.Version); + } + [TestMethod] public async Task GivenRangeOverrides_CorrectVersionsAreResolved_AndTargetVersionIsHonored() {