Skip to content

Commit

Permalink
chore: resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Jul 31, 2024
1 parent caf1e27 commit 5cdef10
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 122 deletions.
10 changes: 5 additions & 5 deletions tools/Uno.Sdk.Updater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Uno.Sdk.Models;
using Uno.Sdk.Services;
using Uno.Sdk.Updater;
using Uno.Sdk.Updater.Utils;

Check failure on line 9 in tools/Uno.Sdk.Updater/Program.cs

View workflow job for this annotation

GitHub Actions / manifest-update

The type or namespace name 'Utils' does not exist in the namespace 'Uno.Sdk.Updater' (are you missing an assembly reference?)

const string UnoSdkPackageId = "Uno.Sdk.Private";

Expand Down Expand Up @@ -312,14 +313,11 @@ static async Task<ManifestGroup> UpdateGroup(ManifestGroup group, NuGetVersion u
preview = false;
}

var packageId = group.Packages.First();
var packageId = group.Packages.FirstOrDefault(x => x.Contains("WinUI", StringComparison.InvariantCultureIgnoreCase) && x.Contains("Uno", StringComparison.InvariantCultureIgnoreCase)) ??
group.Packages.First();

<<<<<<< HEAD
var version = await client.GetVersionAsync(packageId, preview);
=======
var version = await client.GetVersionAsync(packageId, preview, group.Version);
version = !string.IsNullOrEmpty(group.Version) && NuGetVersion.Parse(version) < NuGetVersion.Parse(group.Version) ? group.Version : version;
>>>>>>> 509a186 (fix: limit updates for stable to the current Major.Minor)
var newGroup = group with { Version = version };

if (group.Version != newGroup.Version)
Expand All @@ -343,6 +341,8 @@ static async Task<ManifestGroup> UpdateGroup(ManifestGroup group, NuGetVersion u
{
Console.WriteLine($"Updated Version Override for '{group.Group}' - '{key}' to '{version}'.");
}

version = NuGetVersion.Parse(version) < versionOverride ? versionOverrideString : version;
updatedOverrides.Add(key, version);
}

Expand Down
193 changes: 76 additions & 117 deletions tools/Uno.Sdk.Updater/Services/NuGetClient.cs
Original file line number Diff line number Diff line change
@@ -1,119 +1,88 @@
<<<<<<< HEAD
=======
#nullable enable
using System.Collections;
>>>>>>> e4063e6 (chore: adding additional validations to Version checks)
using System.Net.Http.Json;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using Uno.Sdk.Models;
using Uno.Sdk.Updater.Utils;

Check failure on line 8 in tools/Uno.Sdk.Updater/Services/NuGetClient.cs

View workflow job for this annotation

GitHub Actions / manifest-update

The type or namespace name 'Utils' does not exist in the namespace 'Uno.Sdk.Updater' (are you missing an assembly reference?)

namespace Uno.Sdk.Services;

internal class NuGetApiClient : IDisposable
{
private HttpClient PublicNuGetClient { get; } = new HttpClient
{
BaseAddress = new Uri("https://api.nuget.org")
};

private HttpClient PrivateNuGetClient { get; } = new HttpClient
{
BaseAddress = new Uri("https://pkgs.dev.azure.com")
};

public NuGetVersion? UnoVersion { get; set; }

public async Task<Stream> DownloadPackageAsync(string packageId, string version)
{
var downloadUrl = $"/uno-platform/1dd81cbd-cb35-41de-a570-b0df3571a196/_apis/packaging/feeds/e7ce08df-613a-41a3-8449-d42784dd45ce/nuget/packages/{packageId}/versions/{version}/content";
using var response = await PrivateNuGetClient.GetAsync(downloadUrl);

if (!response.IsSuccessStatusCode)
return Stream.Null;

using var tempStream = await response.Content.ReadAsStreamAsync();
var memoryStream = new MemoryStream();
await tempStream.CopyToAsync(memoryStream);

return memoryStream;
}

internal record VersionsResponse(string[] Versions);

public async Task<IEnumerable<NuGetVersion>> GetPackageVersions(string packageId)
{
var allVersions = new List<string>();
var publicVersions = await GetPublicPackageVersions(packageId);
allVersions.AddRange(publicVersions);

if (!UnoVersion.HasValue || !UnoVersion.Value.IsPreview)
{
var privateVersions = await GetPrivatePackageVersions(packageId);
allVersions.AddRange(privateVersions);
}

var output = new List<NuGetVersion>();
foreach (var version in allVersions.Distinct())
{
if (NuGetVersion.TryParse(version, out var nugetVersion))
{
output.Add(nugetVersion);
}
}

return output.OrderByDescending(x => x);
}

private async Task<IEnumerable<string>> GetPrivatePackageVersions(string packageId)
{
try
{
var response = await PrivateNuGetClient.GetFromJsonAsync<VersionsResponse>($"/uno-platform/1dd81cbd-cb35-41de-a570-b0df3571a196/_packaging/e7ce08df-613a-41a3-8449-d42784dd45ce/nuget/v3/flat2/{packageId.ToLowerInvariant()}/index.json");
return response?.Versions ?? [];
}
catch
{
return [];
}
}

<<<<<<< HEAD
private async Task<IEnumerable<string>> GetPublicPackageVersions(string packageId)
{
try
{
var response = await PublicNuGetClient.GetFromJsonAsync<VersionsResponse>($"/v3-flatcontainer/{packageId.ToLowerInvariant()}/index.json");
return response?.Versions ?? [];
}
catch
{
return [];
}
}
=======
private const string UnoWinUIPackageId = "Uno.WinUI";
private static PackageValidationRecord _validation = new ();

Check failure on line 15 in tools/Uno.Sdk.Updater/Services/NuGetClient.cs

View workflow job for this annotation

GitHub Actions / manifest-update

The type or namespace name 'PackageValidationRecord' could not be found (are you missing a using directive or an assembly reference?)
private static Dictionary<string, IEnumerable<NuGetVersion>> _cachedVersions = [];

private HttpClient PublicNuGetClient { get; } = new HttpClient
{
BaseAddress = new Uri("https://api.nuget.org")
};

private HttpClient PrivateNuGetClient { get; } = new HttpClient
{
BaseAddress = new Uri("https://pkgs.dev.azure.com")
};

public NuGetVersion? UnoVersion { get; set; }

public async Task<Stream> DownloadPackageAsync(string packageId, string version)
{
var downloadUrl = $"/uno-platform/1dd81cbd-cb35-41de-a570-b0df3571a196/_apis/packaging/feeds/e7ce08df-613a-41a3-8449-d42784dd45ce/nuget/packages/{packageId}/versions/{version}/content";
using var response = await PrivateNuGetClient.GetAsync(downloadUrl);

if (!response.IsSuccessStatusCode)
return Stream.Null;

using var tempStream = await response.Content.ReadAsStreamAsync();
var memoryStream = new MemoryStream();
await tempStream.CopyToAsync(memoryStream);

return memoryStream;
}

internal record VersionsResponse(string[] Versions);

public async Task<IEnumerable<NuGetVersion>> GetPackageVersions(string packageId)
{
if (_cachedVersions.TryGetValue(packageId, out var cachedVersions))
{
return cachedVersions;
}

var allVersions = new List<string>();
var publicVersions = await GetPublicPackageVersions(packageId);
allVersions.AddRange(publicVersions);

if (!UnoVersion.HasValue || !UnoVersion.Value.IsPreview)
{
var privateVersions = await GetPrivatePackageVersions(packageId);
allVersions.AddRange(privateVersions);
}

var output = new List<NuGetVersion>();
foreach (var version in allVersions.Distinct())
{
if (NuGetVersion.TryParse(version, out var nugetVersion))
{
output.Add(nugetVersion);
}
}

var latestVersions = output
.GroupBy(x => GetGroupVersion(packageId, x))
.Select(FilterGroup)
.Select(g => g.OrderByDescending(x => x).First())
.OrderByDescending(x => x)
.ToArray();
>>>>>>> e4063e6 (chore: adding additional validations to Version checks)

public async Task<string> GetVersionAsync(string packageId, bool preview, string? minimumVersionString = null)
{
var versions = await GetPackageVersions(packageId);
versions = versions.Where(x => x.IsPreview == preview);

<<<<<<< HEAD
if (NuGetVersion.TryParse(minimumVersionString, out var minimumVersion))
{
versions = versions.Where(x => minimumVersion.Version <= x.Version);
}

if (!versions.Any())
{
return string.Empty;
}
=======

if (!RequiresValidation(packageId))
{
_cachedVersions[packageId] = latestVersions;
return latestVersions;
}

var validatedOutput = new List<NuGetVersion>();
Console.WriteLine($"Validating available versions for {packageId}...");
foreach(var version in latestVersions)
Expand All @@ -128,19 +97,11 @@ public async Task<string> GetVersionAsync(string packageId, bool preview, string
break;
}
}
>>>>>>> 7f698d5 (chore: merge local manifest for release branches)

return versions.OrderByDescending(x => x).First().OriginalVersion;
}

<<<<<<< HEAD
<<<<<<< HEAD
public void Dispose()
{
PublicNuGetClient.Dispose();
}
=======
=======

_cachedVersions[packageId] = validatedOutput;
return validatedOutput;
}

private static IGrouping<NuGetVersion, NuGetVersion> FilterGroup(IGrouping<NuGetVersion, NuGetVersion> group)
{
if (group.Any(x => !x.IsPreview))
Expand All @@ -160,7 +121,6 @@ private class NuGetGrouping(NuGetVersion key, IEnumerable<NuGetVersion> versions
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

>>>>>>> e4063e6 (chore: adding additional validations to Version checks)
private static NuGetVersion GetGroupVersion(string packageId, NuGetVersion packageVersion)
{
if (packageId.StartsWith("Uno", StringComparison.InvariantCultureIgnoreCase))
Expand Down Expand Up @@ -320,5 +280,4 @@ public void Dispose()
{
PublicNuGetClient.Dispose();
}
>>>>>>> 509a186 (fix: limit updates for stable to the current Major.Minor)
}
}

0 comments on commit 5cdef10

Please sign in to comment.