From 9cb0d2796df80af18a3d44b739047436e3f00d1a Mon Sep 17 00:00:00 2001 From: vc-ci Date: Tue, 29 Oct 2024 08:40:51 +0000 Subject: [PATCH 1/2] 3.807.0 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index d07ad69..d859281 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,7 +6,7 @@ Copyright © VirtoCommerce 2011-2022 - 3.806.0 + 3.807.0 $(VersionSuffix)-$(BuildNumber) From 999317bfc0a65ca870e4830e3f422c1ad923d22e Mon Sep 17 00:00:00 2001 From: Alexander Morogov <42555001+krankenbro@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:45:09 +0100 Subject: [PATCH 2/2] VCI-951: Fix empty error messages in Cloud targets (#152) --- .../ArtifactPackerTests.cs | 16 +- src/VirtoCommerce.Build/Build.cs | 194 ++++++++++-------- .../Cloud/Client/VirtoCloudClient.cs | 8 +- .../PlatformTools/Build.PackageManager.cs | 48 +++-- 4 files changed, 155 insertions(+), 111 deletions(-) diff --git a/src/VirtoCommerce.Build.Tests/ArtifactPackerTests.cs b/src/VirtoCommerce.Build.Tests/ArtifactPackerTests.cs index d659a76..522651f 100644 --- a/src/VirtoCommerce.Build.Tests/ArtifactPackerTests.cs +++ b/src/VirtoCommerce.Build.Tests/ArtifactPackerTests.cs @@ -9,7 +9,7 @@ namespace VirtoCommerce.Build.Tests { - public class ArtifactPackerTests + public partial class ArtifactPackerTests { [Fact] public void SkipFileByList_Returns_False_When_Not_In_IgnoreList() @@ -36,7 +36,7 @@ public void SkipFileByList_Returns_True_When_In_IgnoreList() [Fact] public void SkipFileByRegex_Returns_True_When_Matching() { - var regex = new Regex(@".+Module\..*", RegexOptions.IgnoreCase); + var regex = SkipFilesRegex(); var fileName = "TestModule.dll"; var result = ArtifactPacker.SkipFileByRegex(fileName, regex); @@ -47,7 +47,7 @@ public void SkipFileByRegex_Returns_True_When_Matching() [Fact] public void SkipFileByRegex_Returns_False_When_Not_Matching() { - var ignoreRegex = new Regex(@".+Module\..*", RegexOptions.IgnoreCase); + var ignoreRegex = SkipFilesRegex(); var fileName = "AnotherLibrary.dll"; var result = ArtifactPacker.SkipFileByRegex(fileName, ignoreRegex); @@ -80,7 +80,7 @@ public void KeepFileByList_Returns_False_When_Not_In_KeepList() [Fact] public void KeepFileByRegex_Returns_True_When_Matching() { - var regex = new Regex(@$".*SampleModule(Module)?\..*", RegexOptions.IgnoreCase); + var regex = KeepFilesRegex(); var fileName = "SampleModule.dll"; var result = ArtifactPacker.KeepFileByRegex(fileName, regex); @@ -91,12 +91,18 @@ public void KeepFileByRegex_Returns_True_When_Matching() [Fact] public void KeepFileByRegex_Returns_False_When_Not_Matching() { - var regex = new Regex(@$".*SampleModule(Module)?\..*", RegexOptions.IgnoreCase); + var regex = KeepFilesRegex(); var fileName = "NotSample.dll"; var result = ArtifactPacker.KeepFileByRegex(fileName, regex); Assert.False(result); } + + [GeneratedRegex(@".+Module\..*", RegexOptions.IgnoreCase, "en-GB")] + private static partial Regex SkipFilesRegex(); + + [GeneratedRegex(@".*SampleModule(Module)?\..*", RegexOptions.IgnoreCase, "en-GB")] + private static partial Regex KeepFilesRegex(); } } diff --git a/src/VirtoCommerce.Build/Build.cs b/src/VirtoCommerce.Build/Build.cs index 8b5e78f..5fe44df 100644 --- a/src/VirtoCommerce.Build/Build.cs +++ b/src/VirtoCommerce.Build/Build.cs @@ -607,63 +607,67 @@ private static void WebPackBuildMethod(Project webProject) .After(GetManifestGit) .Executes(() => { - var manifest = ModuleManifest; - manifest.PackageUrl = ModulePackageUrl; + UpdateManifestBody(ModuleManifest, ModulePackageUrl, ModulesLocalDirectory, ModulesJsonName, CustomVersionSuffix); + }); + + private static void UpdateManifestBody(ModuleManifest manifest, string modulePackageUrl, AbsolutePath modulesLocalDirectory, string modulesJsonName, string customVersionSuffix) + { + manifest.PackageUrl = modulePackageUrl; - var modulesJsonFilePath = ModulesLocalDirectory / ModulesJsonName; - var externalManifests = - JsonConvert.DeserializeObject>(modulesJsonFilePath.ReadAllText()); - var externalManifest = externalManifests?.Find(x => x.Id == manifest.Id); + var modulesJsonFilePath = modulesLocalDirectory / modulesJsonName; + var externalManifests = + JsonConvert.DeserializeObject>(modulesJsonFilePath.ReadAllText()); + var externalManifest = externalManifests?.Find(x => x.Id == manifest.Id); - if (externalManifest != null) + if (externalManifest != null) + { + if (!manifest.VersionTag.IsNullOrEmpty() || !customVersionSuffix.IsNullOrEmpty()) { - if (!manifest.VersionTag.IsNullOrEmpty() || !CustomVersionSuffix.IsNullOrEmpty()) - { - manifest.VersionTag = manifest.VersionTag.EmptyToNull() ?? CustomVersionSuffix; + manifest.VersionTag = manifest.VersionTag.EmptyToNull() ?? CustomVersionSuffix; - var externalPrereleaseVersion = - externalManifest.Versions.FirstOrDefault(v => !v.VersionTag.IsNullOrEmpty()); + var externalPrereleaseVersion = + externalManifest.Versions.FirstOrDefault(v => !v.VersionTag.IsNullOrEmpty()); - if (externalPrereleaseVersion != null) - { - externalPrereleaseVersion.Dependencies = manifest.Dependencies; - externalPrereleaseVersion.Incompatibilities = manifest.Incompatibilities; - externalPrereleaseVersion.PlatformVersion = manifest.PlatformVersion; - externalPrereleaseVersion.ReleaseNotes = manifest.ReleaseNotes; - externalPrereleaseVersion.Version = manifest.Version; - externalPrereleaseVersion.VersionTag = manifest.VersionTag; - externalPrereleaseVersion.PackageUrl = manifest.PackageUrl; - } - else - { - externalManifest.Versions.Add(ExternalModuleManifestVersion.FromManifest(manifest)); - } + if (externalPrereleaseVersion != null) + { + externalPrereleaseVersion.Dependencies = manifest.Dependencies; + externalPrereleaseVersion.Incompatibilities = manifest.Incompatibilities; + externalPrereleaseVersion.PlatformVersion = manifest.PlatformVersion; + externalPrereleaseVersion.ReleaseNotes = manifest.ReleaseNotes; + externalPrereleaseVersion.Version = manifest.Version; + externalPrereleaseVersion.VersionTag = manifest.VersionTag; + externalPrereleaseVersion.PackageUrl = manifest.PackageUrl; } else { - externalManifest.PublishNewVersion(manifest); + externalManifest.Versions.Add(ExternalModuleManifestVersion.FromManifest(manifest)); } - - externalManifest.Title = manifest.Title; - externalManifest.Description = manifest.Description; - externalManifest.Authors = manifest.Authors; - externalManifest.Copyright = manifest.Copyright; - externalManifest.Groups = manifest.Groups; - externalManifest.IconUrl = manifest.IconUrl; - externalManifest.Id = manifest.Id; - externalManifest.LicenseUrl = manifest.LicenseUrl; - externalManifest.Owners = manifest.Owners; - externalManifest.ProjectUrl = manifest.ProjectUrl; - externalManifest.RequireLicenseAcceptance = manifest.RequireLicenseAcceptance; - externalManifest.Tags = manifest.Tags; } else { - externalManifests?.Add(ExternalModuleManifest.FromManifest(manifest)); + externalManifest.PublishNewVersion(manifest); } - modulesJsonFilePath.WriteAllText(JsonConvert.SerializeObject(externalManifests, Formatting.Indented)); - }); + externalManifest.Title = manifest.Title; + externalManifest.Description = manifest.Description; + externalManifest.Authors = manifest.Authors; + externalManifest.Copyright = manifest.Copyright; + externalManifest.Groups = manifest.Groups; + externalManifest.IconUrl = manifest.IconUrl; + externalManifest.Id = manifest.Id; + externalManifest.LicenseUrl = manifest.LicenseUrl; + externalManifest.Owners = manifest.Owners; + externalManifest.ProjectUrl = manifest.ProjectUrl; + externalManifest.RequireLicenseAcceptance = manifest.RequireLicenseAcceptance; + externalManifest.Tags = manifest.Tags; + } + else + { + externalManifests?.Add(ExternalModuleManifest.FromManifest(manifest)); + } + + modulesJsonFilePath.WriteAllText(JsonConvert.SerializeObject(externalManifests, Formatting.Indented)); + } public Target PublishManifestGit => _ => _ .After(UpdateManifest) @@ -757,33 +761,48 @@ private static void WebPackBuildMethod(Project webProject) .SetPullRequestKey(SonarPRNumber ?? Environment.GetEnvironmentVariable("CHANGE_ID")) .SetProcessArgumentConfigurator(args => { - if (!string.IsNullOrEmpty(SonarPRProvider)) - { - args = args.Add($"/d:sonar.pullrequest.provider={SonarPRProvider}"); - } - - if (!string.IsNullOrEmpty(SonarGithubRepo)) - { - args = args.Add("/d:sonar.pullrequest.github.repository={value}", SonarGithubRepo); - } + args = AddSonarPRProvider(args); + args = AddSonarPRGithubRepo(args); return args; })) .When(!PullRequest, cc => cc .SetBranchName(branchName) - .SetProcessArgumentConfigurator(args => - { - if (!_sonarLongLiveBranches.Contains(branchName)) - { - args = args.Add($"/d:\"sonar.branch.target={branchNameTarget}\""); - } - - return args; - }) + .SetProcessArgumentConfigurator(args => AddSonarBranchTarget(args, branchName, branchNameTarget)) ) ); }); + private static Arguments AddSonarBranchTarget(Arguments args, string branchName, string branchNameTarget) + { + if (!_sonarLongLiveBranches.Contains(branchName)) + { + args = args.Add($"/d:\"sonar.branch.target={branchNameTarget}\""); + } + + return args; + } + + private static Arguments AddSonarPRGithubRepo(Arguments args) + { + if (!string.IsNullOrEmpty(SonarGithubRepo)) + { + args = args.Add("/d:sonar.pullrequest.github.repository={value}", SonarGithubRepo); + } + + return args; + } + + private static Arguments AddSonarPRProvider(Arguments args) + { + if (!string.IsNullOrEmpty(SonarPRProvider)) + { + args = args.Add($"/d:sonar.pullrequest.provider={SonarPRProvider}"); + } + + return args; + } + public Target SonarQubeEnd => _ => _ .After(SonarQubeStart) .DependsOn(Compile) @@ -854,35 +873,40 @@ await PublishRelease(GitHubUser, GitRepositoryName, GitHubToken, tag, descriptio } catch (AggregateException ex) { - foreach (var innerException in ex.Flatten().InnerExceptions.OfType()) - { - var responseString = innerException.HttpResponse?.Body.ToString() ?? string.Empty; - var responseDocument = JsonDocument.Parse(responseString); - var alreadyExistsError = false; - - if (responseDocument.RootElement.TryGetProperty("errors", out var errors)) - { - var errorCount = errors.GetArrayLength(); - - if (errorCount > 0) - { - alreadyExistsError = errors.EnumerateArray().Any(e => - e.GetProperty("code").GetString() == "already_exists"); - } - } - - if (alreadyExistsError) - { - ExitCode = (int)ExitCodes.GithubReleaseAlreadyExists; - } - - Log.Error($"Api Validation Error: {responseString}"); - } + IterateAgregatedErrors(ex); Assert.Fail("Publish Release Failed", ex); } }); + private void IterateAgregatedErrors(AggregateException ex) + { + foreach (var innerException in ex.Flatten().InnerExceptions.OfType()) + { + var responseString = innerException.HttpResponse?.Body.ToString() ?? string.Empty; + var responseDocument = JsonDocument.Parse(responseString); + var alreadyExistsError = false; + + if (responseDocument.RootElement.TryGetProperty("errors", out var errors)) + { + var errorCount = errors.GetArrayLength(); + + if (errorCount > 0) + { + alreadyExistsError = errors.EnumerateArray().Any(e => + e.GetProperty("code").GetString() == "already_exists"); + } + } + + if (alreadyExistsError) + { + ExitCode = (int)ExitCodes.GithubReleaseAlreadyExists; + } + + Log.Error($"Api Validation Error: {responseString}"); + } + } + public Target ClearTemp => _ => _ .Executes(() => ClearTempBeforeExit = true); diff --git a/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs b/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs index 43ad886..f15eb3e 100644 --- a/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs +++ b/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs @@ -41,7 +41,13 @@ public async Task UpdateEnvironmentAsync(string manifest, string appProj if (!response.IsSuccessStatusCode) { var error = VirtoCloudError.FromStringResponse(responseContent); - Assert.Fail(error.GetErrorMessage()); + var errorMessage = error.GetErrorMessage(); + if (string.IsNullOrWhiteSpace(errorMessage)) + { + errorMessage = response.ReasonPhrase; + } + + Assert.Fail(errorMessage); } Serilog.Log.Information(responseContent); diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index cb31650..1fc7b13 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -422,19 +422,7 @@ private static bool IsPlatformInstallationNeeded(string version) } } - var progress = new Progress(m => - { - if (m.Level == ProgressMessageLevel.Error) - { - ExitCode = 1; - Log.Error(m.Message); - - } - else - { - Log.Information(m.Message); - } - }); + var progress = PlatformProgressHandler(); if (!SkipDependencySolving) { @@ -447,13 +435,11 @@ private static bool IsPlatformInstallationNeeded(string version) modulesToInstall.AddRange(missingModules); } + modulesToInstall.ForEach(module => module.DependsOn.Clear()); moduleInstaller.Install(modulesToInstall, progress); - if (ExitCode > 0) - { - Assert.Fail("Errors occurred while installing modules."); - } + Assert.False(ExitCode > 0, "Errors occurred while installing modules."); foreach (var moduleSource in moduleSources) { @@ -461,12 +447,34 @@ private static bool IsPlatformInstallationNeeded(string version) await installer.Install(moduleSource, progress); } - AbsolutePath absoluteDiscoveryPath = Path.GetFullPath(discoveryPath); - var zipFiles = absoluteDiscoveryPath.GlobFiles("*/*.zip"); - zipFiles.ForEach(f => f.DeleteFile()); + CleanZipArtifacts(discoveryPath); localModuleCatalog.Reload(); }); + private Progress PlatformProgressHandler() + { + return new Progress(m => + { + if (m.Level == ProgressMessageLevel.Error) + { + ExitCode = 1; + Log.Error(m.Message); + + } + else + { + Log.Information(m.Message); + } + }); + } + + private static void CleanZipArtifacts(string discoveryPath) + { + AbsolutePath absoluteDiscoveryPath = Path.GetFullPath(discoveryPath); + var zipFiles = absoluteDiscoveryPath.GlobFiles("*/*.zip"); + zipFiles.ForEach(f => f.DeleteFile()); + } + private static ManifestModuleInfo LoadModuleInfo(ModuleItem module, ManifestModuleInfo externalModule) { if (!externalModule.Ref.Contains(externalModule.Version.ToString()))