From 01755f69f6f5ebfc9ed29693c9d5921221fd9a70 Mon Sep 17 00:00:00 2001 From: moljac Date: Fri, 13 Sep 2024 16:02:25 +0200 Subject: [PATCH] bumping fixed --- .../Commands/BumpCommand.cs | 60 ++++++++++++++++++- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Commands/BumpCommand.cs b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Commands/BumpCommand.cs index 6c075a250..0896a2ce8 100644 --- a/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Commands/BumpCommand.cs +++ b/util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Commands/BumpCommand.cs @@ -1,7 +1,12 @@ +using System; +using System.Collections.Generic; using System.CommandLine; using System.Linq; +using System.Net.Http; using System.Threading.Tasks; using AndroidBinderator; +using Newtonsoft.Json; +using NuGet.Versioning; namespace Xamarin.AndroidBinderator.Tool; @@ -39,6 +44,10 @@ static async Task RunBumpCommand (string configFile) str = str.Substring (0, str.LastIndexOf ('-')); } + Console.WriteLine($" Artifact {art.ArtifactId}"); + Console.WriteLine($" Version {art.Version}"); + Console.WriteLine($" DependencyOnly {art.DependencyOnly}"); + var period_count = str.Count (c => c == '.'); if (period_count == 2) { @@ -47,12 +56,57 @@ static async Task RunBumpCommand (string configFile) } else if (period_count == 3) { version = str.Substring (0, str.LastIndexOf ('.')); revision = int.Parse (str.Substring (str.LastIndexOf ('.') + 1)); - revision++; - } - art.NugetVersion = $"{version}.{revision}{release}"; + if (art.DependencyOnly == false) + { + revision++; + art.NugetVersion = $"{version}.{revision}{release}"; + } + else + { + string package = art.NugetPackageId.ToLower (); + string url = $"https://api.nuget.org/v3-flatcontainer/{package}/index.json"; + HttpClient? client = new HttpClient (); + Package p; + try + { + HttpResponseMessage result = await client.GetAsync (url); + string response_content = await result.Content.ReadAsStringAsync (); + p = JsonConvert.DeserializeObject(response_content); + } + catch (Exception e) + { + Console.WriteLine (e); + Console.WriteLine ($"url = {url}"); + Console.WriteLine ($"package = {package}"); + + throw; + } + NuGetVersion latest = p.NugetVersions.FirstOrDefault (); + art.NugetVersion = latest.ToString (); + + Console.WriteLine ($" url = {url}"); + } + } + Console.WriteLine($" NugetVersion {art.NugetVersion}"); } config.Save (configFile); } } + +internal class Package +{ + public List versions { get; set; } + + public List NugetVersions + { + get + { + return versions.Select (v => new NuGetVersion (v)) + .OrderByDescending( v => v, VersionComparer.VersionReleaseMetadata) + .ToList(); + } + } +} +