Skip to content

Commit

Permalink
Merge pull request #21548 from abpframework/issue-21546
Browse files Browse the repository at this point in the history
CLI: Update command should also update LeptonX Theme package versions
  • Loading branch information
yekalkan authored Dec 5, 2024
2 parents e67a004 + 3968c79 commit 2755bee
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using NuGet.Versioning;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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))
{
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -153,7 +165,8 @@ private async Task<string> UpdateVoloPackagesAsync(string content,
SemanticVersion latestNugetVersion = null,
SemanticVersion latestNugetReleaseCandidateVersion = null,
string latestMyGetVersion = null,
string specifiedVersion = null)
string specifiedVersion = null,
List<PackageVersionCheckerService.LatestStableVersionResult> latestStableVersions = null)
{
string packageId = null;

Expand Down Expand Up @@ -206,29 +219,39 @@ private async Task<string> 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
{
Expand All @@ -252,7 +275,7 @@ private async Task<string> UpdateVoloPackagesAsync(string content,
}
else
{
latestVersion = latestMyGetVersion == null ? await GetLatestVersionFromMyGet(packageId) : latestMyGetVersion;
latestVersion = latestMyGetVersion ?? await GetLatestVersionFromMyGet(packageId);
}

if(latestVersion == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,6 +112,11 @@ public async Task<LatestVersionInfo> GetLatestStableVersionFromGithubAsync()
? new LatestVersionInfo(semanticVersion, latestStableVersionResult.Message)
: null;
}

public async Task<List<LatestStableVersionResult>> GetLatestStableVersionsAsync()
{
return await GetLatestStableVersionsInternalAsync();
}

private static ConcurrentDictionary<string, bool> CommercialPackagesCache { get; } = new ();

Expand Down Expand Up @@ -225,7 +231,7 @@ private async Task SetApiKeyResultAsync()
_apiKeyResult ??= await _apiKeyService.GetApiKeyOrNullAsync();
}

private async Task<LatestStableVersionResult> GetLatestStableVersionOrNullAsync()
private async Task<List<LatestStableVersionResult>> GetLatestStableVersionsInternalAsync()
{
try
{
Expand All @@ -241,16 +247,24 @@ private async Task<LatestStableVersionResult> GetLatestStableVersionOrNullAsync(

var content = await responseMessage.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<List<LatestStableVersionResult>>(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<LatestStableVersionResult> GetLatestStableVersionOrNullAsync()
{
var latestStableVersionsResult = await GetLatestStableVersionsInternalAsync();

return latestStableVersionsResult.Count <= 0
? null
: latestStableVersionsResult.FirstOrDefault();
}

public class NuGetSearchResultDto
{
public int TotalHits { get; set; }
Expand All @@ -270,6 +284,11 @@ public class NuGetVersionResultDto
public List<string> Versions { get; set; }
}

public class LeptonXThemeInfo
{
public string Version { get; set; }
}

public class LatestStableVersionResult
{
public string Version { get; set; }
Expand All @@ -279,5 +298,8 @@ public class LatestStableVersionResult
public string Type { get; set; }

public string Message { get; set; }

[CanBeNull]
public LeptonXThemeInfo LeptonX { get; set; }
}
}
23 changes: 22 additions & 1 deletion latest-versions.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]

0 comments on commit 2755bee

Please sign in to comment.