diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs index 9f23645fb98..4ece393913b 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/VoloNugetPackagesVersionUpdater.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using NuGet.Versioning; using System.IO; using System.Linq; @@ -39,6 +40,7 @@ public async Task UpdateSolutionAsync(string solutionPath, bool includePreviews var latestVersionInfo = await _packageVersionCheckerService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates: includeReleaseCandidates); var latestReleaseCandidateVersionInfo = await _packageVersionCheckerService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates: true); var latestVersionFromMyGet = await GetLatestVersionFromMyGet("Volo.Abp.Core"); + var latestStableVersions = await _packageVersionCheckerService.GetLatestStableVersionsAsync(); async Task UpdateAsync(string filePath) { @@ -55,7 +57,8 @@ async Task UpdateAsync(string filePath) latestVersionInfo.Version, latestReleaseCandidateVersionInfo.Version, latestVersionFromMyGet, - version); + version, + latestStableVersions: latestStableVersions); fs.Seek(0, SeekOrigin.Begin); fs.SetLength(0); @@ -83,6 +86,7 @@ public async Task UpdateProjectAsync(string projectPath, bool includeNightlyPrev var latestVersionInfo = await _packageVersionCheckerService.GetLatestVersionOrNullAsync("Volo.Abp.Core"); var latestReleaseCandidateVersionInfo = await _packageVersionCheckerService.GetLatestVersionOrNullAsync("Volo.Abp.Core", includeReleaseCandidates: true); var latestVersionFromMyGet = await GetLatestVersionFromMyGet("Volo.Abp.Core"); + var latestStableVersions = await _packageVersionCheckerService.GetLatestStableVersionsAsync(); using (var fs = File.Open(projectPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { @@ -97,7 +101,8 @@ public async Task UpdateProjectAsync(string projectPath, bool includeNightlyPrev latestVersionInfo.Version, latestReleaseCandidateVersionInfo.Version, latestVersionFromMyGet, - version); + version, + latestStableVersions: latestStableVersions); fs.Seek(0, SeekOrigin.Begin); fs.SetLength(0); @@ -114,13 +119,20 @@ public async Task UpdateProjectAsync(string projectPath, bool includeNightlyPrev protected virtual async Task UpdateInternalAsync(string projectPath, bool includeNightlyPreviews = false, bool includeReleaseCandidates = false, bool switchToStable = false) { + var latestStableVersions = await _packageVersionCheckerService.GetLatestStableVersionsAsync(); + using (var fs = File.Open(projectPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { using (var sr = new StreamReader(fs, Encoding.Default, true)) { var fileContent = await sr.ReadToEndAsync(); - var updatedContent = await UpdateVoloPackagesAsync(fileContent, includeNightlyPreviews, includeReleaseCandidates, switchToStable); + var updatedContent = await UpdateVoloPackagesAsync( + fileContent, + includeNightlyPreviews, + includeReleaseCandidates, + switchToStable, + latestStableVersions: latestStableVersions); fs.Seek(0, SeekOrigin.Begin); fs.SetLength(0); @@ -153,7 +165,8 @@ private async Task UpdateVoloPackagesAsync(string content, SemanticVersion latestNugetVersion = null, SemanticVersion latestNugetReleaseCandidateVersion = null, string latestMyGetVersion = null, - string specifiedVersion = null) + string specifiedVersion = null, + List latestStableVersions = null) { string packageId = null; @@ -206,29 +219,39 @@ private async Task UpdateVoloPackagesAsync(string content, if (!specifiedVersion.IsNullOrWhiteSpace()) { - if (isLeptonXPackage || isStudioPackage) + var leptonXPackageVersion = latestStableVersions? + .FirstOrDefault(v => v.Version.Equals(specifiedVersion, StringComparison.InvariantCultureIgnoreCase))?.LeptonX?.Version; + + if ((isLeptonXPackage && string.IsNullOrWhiteSpace(leptonXPackageVersion)) || isStudioPackage) { Logger.LogWarning("Package: {PackageId} could not be updated. Please manually update the package version yourself to prevent version mismatches!", packageId); continue; } - if (await SpecifiedVersionExists(specifiedVersion, packageId)) + var isLeptonXPackageWithVersion = isLeptonXPackage && !string.IsNullOrWhiteSpace(leptonXPackageVersion); + + if (isLeptonXPackageWithVersion || await SpecifiedVersionExists(specifiedVersion, packageId)) + { + TryUpdatingPackage(isLeptonXPackageWithVersion ? leptonXPackageVersion : specifiedVersion); + } + else { - var specifiedSemanticVersion = SemanticVersion.Parse(specifiedVersion); + Logger.LogWarning("Package \"{PackageId}\" specified version v{SpecifiedVersion} does not exist!", packageId, specifiedVersion); + } + + void TryUpdatingPackage(string versionToUpdate) + { + var specifiedSemanticVersion = SemanticVersion.Parse(versionToUpdate); if (specifiedSemanticVersion > currentSemanticVersion) { - Logger.LogInformation("Updating package \"{PackageId}\" from v{CurrentVersion} to v{SpecifiedVersion}", packageId, currentVersion, specifiedVersion); - versionAttribute.Value = specifiedVersion; + Logger.LogInformation("Updating package \"{PackageId}\" from v{CurrentVersion} to v{SpecifiedVersion}", packageId, currentVersion, versionToUpdate); + versionAttribute.Value = versionToUpdate; } else { - Logger.LogWarning("Unable to update package \"{PackageId}\" version v{CurrentVersion} to v{SpecifiedVersion}", packageId, currentVersion, specifiedVersion); + Logger.LogWarning("Unable to update package \"{PackageId}\" version v{CurrentVersion} to v{SpecifiedVersion}", packageId, currentVersion, versionToUpdate); } } - else - { - Logger.LogWarning("Package \"{PackageId}\" specified version v{SpecifiedVersion} does not exist!", packageId, specifiedVersion); - } } else { @@ -252,7 +275,7 @@ private async Task UpdateVoloPackagesAsync(string content, } else { - latestVersion = latestMyGetVersion == null ? await GetLatestVersionFromMyGet(packageId) : latestMyGetVersion; + latestVersion = latestMyGetVersion ?? await GetLatestVersionFromMyGet(packageId); } if(latestVersion == null) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Version/PackageVersionCheckerService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Version/PackageVersionCheckerService.cs index d5764c1c0e8..316c53e01e6 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Version/PackageVersionCheckerService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Version/PackageVersionCheckerService.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net; using System.Threading.Tasks; +using JetBrains.Annotations; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Http; @@ -111,6 +112,11 @@ public async Task GetLatestStableVersionFromGithubAsync() ? new LatestVersionInfo(semanticVersion, latestStableVersionResult.Message) : null; } + + public async Task> GetLatestStableVersionsAsync() + { + return await GetLatestStableVersionsInternalAsync(); + } private static ConcurrentDictionary CommercialPackagesCache { get; } = new (); @@ -225,7 +231,7 @@ private async Task SetApiKeyResultAsync() _apiKeyResult ??= await _apiKeyService.GetApiKeyOrNullAsync(); } - private async Task GetLatestStableVersionOrNullAsync() + private async Task> GetLatestStableVersionsInternalAsync() { try { @@ -241,16 +247,24 @@ private async Task GetLatestStableVersionOrNullAsync( var content = await responseMessage.Content.ReadAsStringAsync(); var result = JsonSerializer.Deserialize>(content); - - return result.FirstOrDefault(x => x.Type.ToLowerInvariant() == "stable"); + return result.OrderBy(q => q.Type.ToLowerInvariant() == "stable").ThenBy(q => SemanticVersion.Parse(q.Version)).ToList(); } } catch { - return null; + return []; } } + private async Task GetLatestStableVersionOrNullAsync() + { + var latestStableVersionsResult = await GetLatestStableVersionsInternalAsync(); + + return latestStableVersionsResult.Count <= 0 + ? null + : latestStableVersionsResult.FirstOrDefault(); + } + public class NuGetSearchResultDto { public int TotalHits { get; set; } @@ -270,6 +284,11 @@ public class NuGetVersionResultDto public List Versions { get; set; } } + public class LeptonXThemeInfo + { + public string Version { get; set; } + } + public class LatestStableVersionResult { public string Version { get; set; } @@ -279,5 +298,8 @@ public class LatestStableVersionResult public string Type { get; set; } public string Message { get; set; } + + [CanBeNull] + public LeptonXThemeInfo LeptonX { get; set; } } } diff --git a/latest-versions.json b/latest-versions.json index 0eff05a8919..e2c60800a3d 100644 --- a/latest-versions.json +++ b/latest-versions.json @@ -1,8 +1,29 @@ [ + { + "version": "9.0.1", + "releaseDate": "", + "type": "stable", + "message": "", + "leptonx": { + "version": "4.0.1" + } + }, + { + "version": "9.0.0", + "releaseDate": "", + "type": "stable", + "message": "", + "leptonx": { + "version": "4.0.0" + } + }, { "version": "8.3.1", "releaseDate": "", "type": "stable", - "message": "" + "message": "", + "leptonx": { + "version": "3.3.1" + } } ] \ No newline at end of file