From 118c7b1d3348cede40b43df9d6f2572df76e3d63 Mon Sep 17 00:00:00 2001 From: Alexandr Morogov <42555001+krankenbro@users.noreply.github.com> Date: Thu, 22 Feb 2024 13:09:27 +0100 Subject: [PATCH 1/2] VCI-772: Net 8 (#117) --- Directory.Build.props | 2 +- .../PackageManagerTests.cs | 6 +- .../VirtoCommerce.Build.Tests.csproj | 4 +- src/VirtoCommerce.Build/Build.cs | 67 ++++++++++--------- src/VirtoCommerce.Build/Cloud/Build.SaaS.cs | 10 +-- .../Cloud/Client/VirtoCloudClient.cs | 5 +- .../Cloud/Models/HelmParameter.cs | 4 +- .../Extensions/PathExtension.cs | 23 +++++++ .../Azure/AzureCliToolSettings.cs | 2 +- .../AzureUniversalPackagesModuleInstaller.cs | 5 +- .../Build.ConnStringValidator.cs | 10 +-- .../PlatformTools/Build.InitPlatform.cs | 5 +- .../PlatformTools/Build.MatchVerisons.cs | 30 +++++---- .../PlatformTools/Build.PackageManager.cs | 41 ++++++------ .../Github/GithubPrivateModulesInstaller.cs | 5 +- .../GitlabJobArtifactsModuleInstaller.cs | 5 +- .../PlatformTools/PackageManager.cs | 14 ++-- .../Utils/ArtifactPacker.cs | 29 +++++--- .../VirtoCommerce.Build.csproj | 22 +++--- .../src/VirtoCloud.Client/Client/ApiClient.cs | 3 - .../VirtoCloud.Client.csproj | 2 +- 21 files changed, 165 insertions(+), 129 deletions(-) create mode 100644 src/VirtoCommerce.Build/Extensions/PathExtension.cs diff --git a/Directory.Build.props b/Directory.Build.props index ca5f933..03a922c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,7 +6,7 @@ Copyright © VirtoCommerce 2011-2022 - 3.22.0 + 3.800.0 $(VersionSuffix)-$(BuildNumber) diff --git a/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs b/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs index 44ae008..5a39b91 100644 --- a/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs +++ b/src/VirtoCommerce.Build.Tests/PackageManagerTests.cs @@ -1,3 +1,5 @@ +using Extensions; +using Nuke.Common.IO; using PlatformTools; using VirtoCommerce.Build.PlatformTools; @@ -76,7 +78,7 @@ public void ToFile_SavesManifestToFile() var path = "./test-vc-package.json"; // Act - PackageManager.ToFile(manifest, path); + PackageManager.ToFile(manifest, path.ToAbsolutePath()); // Assert Assert.True(File.Exists(path)); @@ -91,7 +93,7 @@ public void FromFile_LoadsManifestFromFile() // Arrange var manifest = PackageManager.CreatePackageManifest("1.0.0"); var path = "./test-vc-package.json"; - PackageManager.ToFile(manifest, path); + PackageManager.ToFile(manifest, path.ToAbsolutePath()); // Act var loadedManifest = PackageManager.FromFile(path); diff --git a/src/VirtoCommerce.Build.Tests/VirtoCommerce.Build.Tests.csproj b/src/VirtoCommerce.Build.Tests/VirtoCommerce.Build.Tests.csproj index 52cf136..ad74b8f 100644 --- a/src/VirtoCommerce.Build.Tests/VirtoCommerce.Build.Tests.csproj +++ b/src/VirtoCommerce.Build.Tests/VirtoCommerce.Build.Tests.csproj @@ -1,7 +1,7 @@ - + - net6.0 + net8.0 enable enable diff --git a/src/VirtoCommerce.Build/Build.cs b/src/VirtoCommerce.Build/Build.cs index a28d650..9c37bfe 100644 --- a/src/VirtoCommerce.Build/Build.cs +++ b/src/VirtoCommerce.Build/Build.cs @@ -9,6 +9,7 @@ using System.Text.Json; using System.Threading.Tasks; using System.Xml; +using Extensions; using Microsoft.Build.Locator; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -45,9 +46,9 @@ internal partial class Build : NukeBuild /// - JetBrains Rider https://nuke.build/rider /// - Microsoft VisualStudio https://nuke.build/visualstudio /// - Microsoft VSCode https://nuke.build/vscode - private static readonly string[] _moduleContentFolders = { "dist", "Localizations", "Scripts", "Content" }; + private static readonly string[] _moduleContentFolders = ["dist", "Localizations", "Scripts", "Content"]; - private static readonly string[] _sonarLongLiveBranches = { "master", "develop", "dev", "main" }; + private static readonly string[] _sonarLongLiveBranches = ["master", "develop", "dev", "main"]; private static readonly HttpClient _httpClient = new(); private static int? _exitCode; @@ -67,9 +68,9 @@ public static Solution Solution get { var solutions = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln", SearchOption.TopDirectoryOnly); - if (solutions.Any()) + if (solutions.Length > 0) { - return ProjectModelTasks.ParseSolution(solutions[0]); + return SolutionModelTasks.ParseSolution(solutions[0]); } Log.Warning("No solution files found in the current directory"); @@ -233,12 +234,13 @@ public static Solution Solution protected static bool IsModule => ModuleManifestFile.FileExists(); + private static readonly string[] cleanSearchPattern = new[] { "**/bin", "**/obj" }; + public Target Clean => _ => _ .Before(Restore) .Executes(() => { - var searchPattern = new[] { "**/bin", "**/obj" }; - CleanSolution(searchPattern); + CleanSolution(cleanSearchPattern); }); public Target Restore => _ => _ @@ -271,7 +273,7 @@ public static Solution Solution .DependsOn(Compile) .Executes(() => { - var testProjects = Solution.GetProjects("*.Test|*.Tests|*.Testing"); + var testProjects = Solution.GetAllProjects("*.Test|*.Tests|*.Testing"); var outPath = RootDirectory / ".tmp"; foreach (var testProjectPath in testProjects.Select(p=> p.Path).ToArray()) @@ -294,7 +296,7 @@ public static Solution Solution if (coberturaReports.Count > 0) { - var reportGenerator = ToolResolver.GetPackageTool("dotnet-reportgenerator-globaltool", + var reportGenerator = ToolResolver.GetNuGetTool("dotnet-reportgenerator-globaltool", "ReportGenerator.dll", "4.8.8", "netcoreapp3.0"); reportGenerator.Invoke( $"-reports:{outPath / "**/coverage.cobertura.xml"} -targetdir:{outPath} -reporttypes:SonarQube"); @@ -532,7 +534,7 @@ private static void WebPackBuildMethod(Project webProject) var modulesJsonFilePath = ModulesLocalDirectory / ModulesJsonName; var externalManifests = - JsonConvert.DeserializeObject>(TextTasks.ReadAllText(modulesJsonFilePath)); + JsonConvert.DeserializeObject>(modulesJsonFilePath.ReadAllText()); var externalManifest = externalManifests?.Find(x => x.Id == manifest.Id); if (externalManifest != null) @@ -582,8 +584,7 @@ private static void WebPackBuildMethod(Project webProject) externalManifests?.Add(ExternalModuleManifest.FromManifest(manifest)); } - TextTasks.WriteAllText(modulesJsonFilePath, - JsonConvert.SerializeObject(externalManifests, Formatting.Indented)); + modulesJsonFilePath.WriteAllText(JsonConvert.SerializeObject(externalManifests, Formatting.Indented)); }); public Target PublishManifestGit => _ => _ @@ -603,7 +604,7 @@ private static void WebPackBuildMethod(Project webProject) .Requires(() => !IsModule) .Executes(async () => { - var swashbuckle = ToolResolver.GetPackageTool("Swashbuckle.AspNetCore.Cli", "dotnet-swagger.dll", + var swashbuckle = ToolResolver.GetNuGetTool("Swashbuckle.AspNetCore.Cli", "dotnet-swagger.dll", framework: "netcoreapp3.0"); var projectPublishPath = ArtifactsDirectory / "publish" / $"{WebProject.Name}.dll"; var swaggerJsonPath = ArtifactsDirectory / "swagger.json"; @@ -715,14 +716,14 @@ private static void WebPackBuildMethod(Project webProject) if (OperatingSystem.IsLinux()) { const string sonarScript = "sonar-scanner"; - var sonarScannerShPath = ToolPathResolver.GetPackageExecutable("dotnet-sonarscanner", + var sonarScannerShPath = NuGetToolPathResolver.GetPackageExecutable("dotnet-sonarscanner", sonarScript, framework: framework) .Replace("netcoreapp2.0", "net5.0") .Replace("netcoreapp3.0", "net5.0"); var sonarScannerShRightPath = Directory.GetParent(sonarScannerShPath)?.Parent?.FullName ?? string.Empty; var tmpFile = TemporaryDirectory / sonarScript; FileSystemTasks.MoveFile(sonarScannerShPath, tmpFile); - FileSystemTasks.DeleteDirectory(sonarScannerShRightPath); + sonarScannerShRightPath.ToAbsolutePath().DeleteDirectory(); var sonarScriptDestinationPath = Path.Combine(sonarScannerShRightPath, sonarScript); FileSystemTasks.MoveFile(tmpFile, sonarScriptDestinationPath); Log.Information($"{sonarScript} path: {sonarScriptDestinationPath}"); @@ -748,7 +749,7 @@ private static void WebPackBuildMethod(Project webProject) foreach (var moduleDirectory in Directory.GetDirectories(ModulesFolderPath)) { var isGitRepository = - FileSystemTasks.FindParentDirectory(moduleDirectory, x => x.GetDirectories(".git").Any()) != + moduleDirectory.ToAbsolutePath().FindParentOrSelf(x => x.GetDirectories(".git").Any()) != null; if (isGitRepository) @@ -831,7 +832,7 @@ private static void ClearTempOnExit() { if (ClearTempBeforeExit) { - FileSystemTasks.DeleteDirectory(TemporaryDirectory); + TemporaryDirectory.DeleteDirectory(); } } @@ -841,7 +842,7 @@ private static void CreateNukeDirectory() var nukeFiles = Directory.GetFiles(currentDirectory, ".nuke"); - if (!nukeFiles.Any() && !Directory.Exists(Path.Join(currentDirectory, ".nuke"))) + if (nukeFiles.Length == 0 && !Directory.Exists(Path.Join(currentDirectory, ".nuke"))) { Console.WriteLine("No .nuke file found!"); var solutions = Directory.GetFiles(currentDirectory, "*.sln"); @@ -857,7 +858,7 @@ private static void CreateNukeDirectory() CreateDotNuke(currentDirectory); } } - else if (nukeFiles.Any()) + else if (nukeFiles.Length > 0) { var nukeFile = nukeFiles[0]; ConvertDotNukeFile(nukeFile); @@ -893,11 +894,11 @@ private static void RegisterMSBuildLocator() } } - private static void ConvertDotNukeFile(string path) + private static void ConvertDotNukeFile(AbsolutePath path) { var directory = Path.GetDirectoryName(path); var solutionPath = File.ReadLines(path).FirstOrDefault(); - FileSystemTasks.DeleteFile(path); + path.DeleteFile(); CreateDotNuke(directory, solutionPath); } @@ -905,9 +906,9 @@ private static void CreateDotNuke(string path, string solutionPath = "") { var dotnukeDir = Path.Join(path, ".nuke"); var paramsFilePath = Path.Join(dotnukeDir, "parameters.json"); - FileSystemTasks.EnsureExistingDirectory(dotnukeDir); + dotnukeDir.ToAbsolutePath().CreateDirectory(); var parameters = new NukeParameters { Solution = solutionPath }; - SerializationTasks.JsonSerializeToFile(parameters, paramsFilePath); + JsonExtensions.WriteJson(paramsFilePath, parameters); } public static void CustomDotnetLogger(OutputType type, string text) @@ -925,9 +926,9 @@ public static void ChangeProjectVersion(string versionPrefix = null, string vers //theme if (IsTheme) { - var jObject = SerializationTasks.JsonDeserializeFromFile(PackageJsonPath); + var jObject = JsonExtensions.ReadJson(PackageJsonPath); jObject["version"] = versionPrefix; - SerializationTasks.JsonSerializeToFile(jObject, Path.GetFullPath(PackageJsonPath)); + JsonExtensions.WriteJson(Path.GetFullPath(PackageJsonPath), jObject); return; } @@ -1172,7 +1173,7 @@ private void CompressExecuteMethod() if (ModuleIgnoreFile.FileExists()) { - ignoredFiles = ignoredFiles.Concat(TextTasks.ReadAllLines(ModuleIgnoreFile)).ToArray(); + ignoredFiles = ignoredFiles.Concat(ModuleIgnoreFile.ReadAllLines()).ToArray(); } ignoredFiles = ignoredFiles.Select(x => x.Trim()).Distinct().ToArray(); @@ -1180,7 +1181,7 @@ private void CompressExecuteMethod() var keepFiles = Array.Empty(); if (ModuleKeepFile.FileExists()) { - keepFiles = TextTasks.ReadAllLines(ModuleKeepFile).ToArray(); + keepFiles = ModuleKeepFile.ReadAllLines().ToArray(); } ArtifactPacker.CompressModule(options => options.WithSourceDirectory(ModuleOutputDirectory) @@ -1202,33 +1203,33 @@ private static void CleanSolution(string[] searchPattern, AbsolutePath[] ignoreP { if (SourceDirectory.DirectoryExists()) { - if (ignorePaths?.Any() == true) + if (ignorePaths?.Length > 0) { SourceDirectory .GlobDirectories(searchPattern) .Where(directory => !ignorePaths.Any(p => p.Contains(directory))) - .ForEach(FileSystemTasks.DeleteDirectory); + .ForEach(p => p.DeleteDirectory()); } else { - SourceDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory); + SourceDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory()); } if (TestsDirectory.DirectoryExists()) { - TestsDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory); + TestsDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory()); } if (SamplesDirectory.DirectoryExists()) { - SamplesDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory); + SamplesDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory()); } } else { - RootDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory); + RootDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory()); } - FileSystemTasks.EnsureCleanDirectory(ArtifactsDirectory); + ArtifactsDirectory.CreateOrCleanDirectory(); } } diff --git a/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs b/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs index d12eb65..93d0e1e 100644 --- a/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs +++ b/src/VirtoCommerce.Build/Cloud/Build.SaaS.cs @@ -144,7 +144,7 @@ private async Task PrepareDockerContextMethod() var modulesPath = platformDirectory / "modules"; var dockerfilePath = dockerBuildContext / "Dockerfile"; - FileSystemTasks.EnsureCleanDirectory(dockerBuildContext); + dockerBuildContext.CreateOrCleanDirectory(); await HttpTasks.HttpDownloadFileAsync(DockerfileUrl, dockerfilePath); @@ -196,7 +196,7 @@ private static void CopyModules(AbsolutePath modulesPath, AbsolutePath modulesSo var solutions = Directory.EnumerateFiles(solutionDir, "*.sln"); Assert.True(solutions.Count() == 1, $"Solutions found: {solutions.Count()}"); var solutionPath = solutions.FirstOrDefault(); - var solution = ProjectModelTasks.ParseSolution(solutionPath); + var solution = SolutionModelTasks.ParseSolution(solutionPath); var webProject = solution.AllProjects.First(p => p.Name.EndsWith(".Web")); WebPackBuildMethod(webProject); @@ -271,7 +271,6 @@ private static void CopyPlatformDirectory(AbsolutePath platformDirectory, Absolu }; listener.Start(); - Log.Information("Openning browser window"); var authUrl = $"{CloudUrl}/externalsignin?authenticationType={CloudAuthProvider}&returnUrl=/api/saas/token/{port}"; Process.Start(new ProcessStartInfo(authUrl) { UseShellExecute = true }); @@ -303,7 +302,8 @@ private async Task GetCloudTokenAsync() private void SaveCloudToken(string token) { - FileSystemTasks.EnsureExistingDirectory(Path.GetDirectoryName(CloudTokenFile)); + AbsolutePath cloudTokenDir = Path.GetDirectoryName(CloudTokenFile); + cloudTokenDir.CreateDirectory(); File.WriteAllText(CloudTokenFile, token); } @@ -378,7 +378,7 @@ private void SaveCloudToken(string token) public Target CloudUp => _ => _ .DependsOn(CloudInit, CloudDeploy); - private static ISaaSDeploymentApi CreateVirtocloudClient(string url, string token) + private static SaaSDeploymentApi CreateVirtocloudClient(string url, string token) { var config = new VirtoCloud.Client.Client.Configuration(); config.BasePath = url; diff --git a/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs b/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs index 36169c9..8e0c093 100644 --- a/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs +++ b/src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs @@ -6,6 +6,7 @@ using Cloud.Models; using Nuke.Common; using Nuke.Common.IO; +using Nuke.Common.Utilities; namespace Cloud.Client; @@ -42,7 +43,7 @@ public async Task UpdateEnvironmentAsync(string manifest, string appProj public async Task UpdateEnvironmentAsync(CloudEnvironment environment) { - var jsonString = SerializationTasks.JsonSerialize(environment); + var jsonString = JsonExtensions.ToJson(environment); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); var response = await _client.PutAsync(new Uri("api/saas/environments", UriKind.Relative), content); if (!response.IsSuccessStatusCode) @@ -65,7 +66,7 @@ public async Task GetEnvironment(string environmentName, strin } var responseContent = await response.Content.ReadAsStringAsync(); - var env = SerializationTasks.JsonDeserialize(responseContent); + var env = JsonExtensions.GetJson(responseContent); return env; } } diff --git a/src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs b/src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs index 0b655ed..8a869c3 100644 --- a/src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs +++ b/src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs @@ -2,7 +2,7 @@ using System.ComponentModel; using System.Globalization; using Newtonsoft.Json; -using Nuke.Common.IO; +using Nuke.Common.Utilities; namespace Cloud.Models { @@ -17,7 +17,7 @@ public HelmParameter(bool? forceString = default, string name = default, string public override string ToString() { var parameter = new V1alpha1HelmParameter(null, Name, Value); - return SerializationTasks.JsonSerialize(parameter); + return parameter.ToJson(); } public class HelmJsonConverter : JsonConverter diff --git a/src/VirtoCommerce.Build/Extensions/PathExtension.cs b/src/VirtoCommerce.Build/Extensions/PathExtension.cs new file mode 100644 index 0000000..e93d309 --- /dev/null +++ b/src/VirtoCommerce.Build/Extensions/PathExtension.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Nuke.Common.IO; +using System.IO; + +namespace Extensions +{ + public static class PathExtension + { + public static AbsolutePath ToAbsolutePath(this string path) + { + if(path == null) + { + return null; + } + + return AbsolutePath.Create(Path.GetFullPath(path)); + } + } +} diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureCliToolSettings.cs b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureCliToolSettings.cs index aea4567..579bc69 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureCliToolSettings.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureCliToolSettings.cs @@ -6,6 +6,6 @@ namespace PlatformTools.Azure [Serializable] internal class AzureCliToolSettings : ToolSettings { - public override Action ProcessCustomLogger => ProcessTasks.DefaultLogger; + public override Action ProcessLogger => ProcessTasks.DefaultLogger; } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs index 8f185c2..44fd341 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs @@ -3,6 +3,7 @@ using System.IO.Compression; using System.Linq; using System.Threading.Tasks; +using Extensions; using Nuke.Common.IO; using Nuke.Common.Tooling; using VirtoCommerce.Build.PlatformTools; @@ -27,9 +28,9 @@ protected override Task InnerInstall(ModuleSource source, IProgress _ => _ .Executes(() => diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs index 238fb18..87c665e 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs @@ -13,13 +13,14 @@ namespace VirtoCommerce.Build { internal partial class Build { - private Regex _moduleNameRegEx = new Regex(@"(VirtoCommerce.+)Module", RegexOptions.Compiled); + [GeneratedRegex(@"(VirtoCommerce.+)Module", RegexOptions.Compiled)] + private static partial Regex ModuleNameRegEx(); public Target MatchVersions => _ => _ .Executes(() => { var allPackages = new List(); - var allProjects = Solution.GetProjects("*"); + var allProjects = Solution.GetAllProjects("*"); foreach (var project in allProjects) { @@ -38,7 +39,7 @@ internal partial class Build var missedDependenciesErrors = ValidateForMissedDependencies(allPackages); errors.AddRange(missedDependenciesErrors); - if (errors.Any()) + if (errors.Count > 0) { Assert.Fail(errors.Join(Environment.NewLine)); } @@ -47,14 +48,14 @@ internal partial class Build /// /// Get list of VirtoCommerce packages (platform and module) /// - private IEnumerable GetProjectPackages(Project project) + private static IEnumerable GetProjectPackages(Project project) { var msBuildProject = project.GetMSBuildProject(); // find all VirtoCommerce references return msBuildProject.Items .Where(x => x.ItemType == "PackageReference" - && (x.EvaluatedInclude.StartsWith("VirtoCommerce.Platform.") || _moduleNameRegEx.IsMatch(x.EvaluatedInclude))) + && (x.EvaluatedInclude.StartsWith("VirtoCommerce.Platform.") || ModuleNameRegEx().IsMatch(x.EvaluatedInclude))) .Select(x => { var versionMetadata = x.Metadata.FirstOrDefault(x => x.Name == "Version"); @@ -79,18 +80,19 @@ private IEnumerable GetProjectPackages(Project project) /// /// Check match between manifest platform version and platform packages /// - private IEnumerable ValdatePlatformVersion(IEnumerable packages) + private static List ValdatePlatformVersion(IEnumerable packages) { return packages .Where(package => package.IsPlatformPackage && SemanticVersion.Parse(package.Version) != SemanticVersion.Parse(ModuleManifest.PlatformVersion)) .Select(x => - $"Mismatched platform dependency version found. Platform version: {ModuleManifest.PlatformVersion}, Platform package name: {x.Name}, platform package version: {x.Version}, project name: {x.ProjectName}"); + $"Mismatched platform dependency version found. Platform version: {ModuleManifest.PlatformVersion}, Platform package name: {x.Name}, platform package version: {x.Version}, project name: {x.ProjectName}") + .ToList(); } /// /// Check dependencies for module packages versions mismatch /// - private IEnumerable ValidateModuleDependenciesVersions(IEnumerable packages) + private static List ValidateModuleDependenciesVersions(IEnumerable packages) { var result = new List(); @@ -117,7 +119,7 @@ private IEnumerable ValidateModuleDependenciesVersions(IEnumerable /// Check project packages for missed dependency in manifest /// - private IEnumerable ValidateForMissedDependencies(IEnumerable packages) + private static List ValidateForMissedDependencies(IEnumerable packages) { var result = new List(); @@ -126,20 +128,20 @@ private IEnumerable ValidateForMissedDependencies(IEnumerable !x.IsPlatformPackage).GroupBy(x => x.Name)) + foreach (var packageGroupKey in packages.Where(x => !x.IsPlatformPackage).GroupBy(x => x.Name).Select(packageGroup => packageGroup.Key)) { - if (!ModuleManifest.Dependencies.Any(dependency => HasNameMatch(packageGroup.Key, dependency.Id))) + if (!ModuleManifest.Dependencies.Any(dependency => HasNameMatch(packageGroupKey, dependency.Id))) { - result.Add($"Dependency in module.manifest is missing. Package name: {packageGroup.Key}"); + result.Add($"Dependency in module.manifest is missing. Package name: {packageGroupKey}"); } } return result; } - private bool HasNameMatch(string packageName, string dependencyName) + private static bool HasNameMatch(string packageName, string dependencyName) { - var match = _moduleNameRegEx.Match(packageName); + var match = ModuleNameRegEx().Match(packageName); return match.Groups.Values.Any(x => x.Value == dependencyName); } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index 2cb3481..eb318e4 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -5,8 +5,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Extensions; using Nuke.Common; using Nuke.Common.IO; +using Nuke.Common.Utilities; using Nuke.Common.Utilities.Collections; using PlatformTools; using PlatformTools.Azure; @@ -56,7 +58,7 @@ internal partial class Build [Parameter("Url to Bundles file")] public static string BundlesUrl { get; set; } = "https://raw.githubusercontent.com/VirtoCommerce/vc-modules/master/bundles/stable.json"; - [Parameter("Backup file path")] public static string BackupFile { get; set; } = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + [Parameter("Backup file path")] public static AbsolutePath BackupFile { get; set; } = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); public Target Init => _ => _ .Executes(async () => @@ -71,7 +73,7 @@ internal partial class Build .DependsOn(Backup) .Executes(async () => { - var packageManifest = await OpenOrCreateManifest(PackageManifestPath, Edge); + var packageManifest = await OpenOrCreateManifest(PackageManifestPath.ToAbsolutePath(), Edge); var githubModuleSources = PackageManager.GetGithubModuleManifests(packageManifest); var modules = PackageManager.GetGithubModules(packageManifest); @@ -82,7 +84,7 @@ internal partial class Build { UpdateModules(Module, externalModuleCatalog, modules); } - else if (!PlatformParameter && !modules.Any() && !FileSystemTasks.FileExists((AbsolutePath)Path.GetFullPath(PackageManifestPath))) + else if (!PlatformParameter && modules.IsEmpty() && !File.Exists(Path.GetFullPath(PackageManifestPath))) { AddCommerceModules(externalModuleCatalog, modules); } @@ -160,7 +162,7 @@ private static IEnumerable ParseModuleParameter(string[] moduleStrin if (parts.Length > 1) { moduleId = parts[0]; - moduleVersion = parts.Last(); + moduleVersion = parts[parts.Length - 1]; } else if (moduleStrings.Length == 1 && !string.IsNullOrEmpty(VersionToInstall)) { @@ -201,16 +203,15 @@ private static bool PlatformVersionChanged() modulesDirs = Directory.EnumerateDirectories(discoveryPath).ToList(); } var symlinks = modulesDirs.Where(m => new DirectoryInfo(m).LinkTarget != null).ToList(); - CompressionTasks.CompressTarGZip(RootDirectory, BackupFile, filter: f => !f.FullName.StartsWith(RootDirectory / ".nuke") && !symlinks.Any(s => f.FullName.StartsWith(s))); - + CompressionExtensions.TarGZipTo(RootDirectory, BackupFile, filter: f => !f.ToFileInfo().FullName.StartsWith(RootDirectory / ".nuke") && !symlinks.Any(s => f.ToFileInfo().FullName.StartsWith(s))); }); public Target Rollback => _ => _ .DependsOn(Backup) .After(Backup, Install, Update, InstallPlatform, InstallModules) - .OnlyWhenDynamic(() => FailedTargets.Any() && SucceededTargets.Contains(Backup)) + .OnlyWhenDynamic(() => FailedTargets.Count > 0 && SucceededTargets.Contains(Backup)) .AssuredAfterFailure() - .Executes(() => CompressionTasks.UncompressTarGZip(BackupFile, RootDirectory)); + .Executes(() => CompressionExtensions.UnTarGZipTo(BackupFile, RootDirectory)); public Target RemoveBackup => _ => _ .After(Backup, Rollback) @@ -218,14 +219,14 @@ private static bool PlatformVersionChanged() .AssuredAfterFailure() .Unlisted() .DependsOn(Backup) - .Executes(() => FileSystemTasks.DeleteFile(BackupFile)); + .Executes(() => BackupFile.DeleteFile()); public Target InstallPlatform => _ => _ .OnlyWhenDynamic(() => PlatformVersionChanged() && !IsModulesInstallation()) .Executes(async () => { var packageManifest = PackageManager.FromFile(PackageManifestPath); - var mixedManifest = SerializationTasks.JsonDeserializeFromFile(PackageManifestPath); + var mixedManifest = PackageManifestPath.ToAbsolutePath().ReadJson(); var platformAssetUrlFromManifest = mixedManifest.PlatformAssetUrl; var platformAssetUrl = string.IsNullOrWhiteSpace(PlatformAssetUrl) ? platformAssetUrlFromManifest @@ -263,8 +264,8 @@ private static async Task InstallPlatformAsync(string platformVersion, string pl FileSystemTasks.MoveFile(AppsettingsPath, tempFile, FileExistsPolicy.Overwrite); } - CompressionTasks.Uncompress(platformZip, RootDirectory); - FileSystemTasks.DeleteFile(platformZip); + platformZip.UncompressTo(RootDirectory); + platformZip.DeleteFile(); // return appsettings.json back if (!string.IsNullOrEmpty(tempFile)) @@ -272,7 +273,7 @@ private static async Task InstallPlatformAsync(string platformVersion, string pl var bakFileName = new StringBuilder("appsettings.") .Append(DateTime.Now.ToString("MMddyyHHmmss")) .Append(".bak"); - var destinationSettingsPath = !Force ? AppsettingsPath : Path.Join(Path.GetDirectoryName(AppsettingsPath), bakFileName.ToString()); + AbsolutePath destinationSettingsPath = !Force ? AppsettingsPath : Path.Join(Path.GetDirectoryName(AppsettingsPath), bakFileName.ToString()); FileSystemTasks.MoveFile(tempFile, destinationSettingsPath, FileExistsPolicy.Overwrite); if (Force) @@ -397,9 +398,9 @@ private static bool IsPlatformInstallationNeeded(string version) await installer.Install(moduleSource, progress); } - var absoluteDiscoveryPath = (AbsolutePath)Path.GetFullPath(discoveryPath); + AbsolutePath absoluteDiscoveryPath = Path.GetFullPath(discoveryPath); var zipFiles = absoluteDiscoveryPath.GlobFiles("*/*.zip"); - zipFiles.ForEach(f => FileSystemTasks.DeleteFile(f)); + zipFiles.ForEach(f => f.DeleteFile()); localModuleCatalog.Reload(); }); @@ -466,8 +467,8 @@ private static ManifestModuleInfo LoadModuleInfo(ModuleItem module, ManifestModu var packageManifest = PackageManager.FromFile(PackageManifestPath); var localModulesCatalog = LocalModuleCatalog.GetCatalog(discoveryPath, ProbingPath); var githubModules = PackageManager.GetGithubModules(packageManifest); - FileSystemTasks.DeleteDirectory(ProbingPath); - Module.ForEach(m => FileSystemTasks.DeleteDirectory(Path.Combine(discoveryPath, m))); + ProbingPath.DeleteDirectory(); + Module.ForEach(m => AbsolutePath.Create(Path.Combine(discoveryPath, m)).DeleteDirectory()); githubModules.RemoveAll(m => Module.Contains(m.Id)); PackageManager.ToFile(packageManifest, PackageManifestPath); if (PlatformVersion.CurrentVersion == null) @@ -606,7 +607,7 @@ private static async Task OpenOrCreateManifest(string packageManif else if (!File.Exists(packageManifestPath) && File.Exists(platformWebDllPath)) { var discoveryAbsolutePath = Path.GetFullPath(GetDiscoveryPath()); - return CreateManifestFromEnvironment(RootDirectory, (AbsolutePath)discoveryAbsolutePath); + return CreateManifestFromEnvironment(RootDirectory, discoveryAbsolutePath.ToAbsolutePath()); } else if (!File.Exists(packageManifestPath)) { @@ -625,7 +626,7 @@ private static async Task OpenOrCreateManifest(string packageManif private static async Task DownloadBundleManifest(string bundleName, string outFile) { var rawBundlesFile = await HttpTasks.HttpDownloadStringAsync(BundlesUrl); - var bundlesDictionary = SerializationTasks.JsonDeserialize>(rawBundlesFile); + var bundlesDictionary = JsonExtensions.GetJson>(rawBundlesFile); KeyValuePair bundle; if (string.IsNullOrEmpty(bundleName)) { @@ -643,7 +644,7 @@ private static async Task DownloadBundleManifest(string bundleName, string outFi private static ManifestBase CreateManifestFromEnvironment(AbsolutePath platformPath, AbsolutePath discoveryPath) { var platformWebDllPath = platformPath / "VirtoCommerce.Platform.Web.dll"; - if (!FileSystemTasks.FileExists(platformWebDllPath)) + if (!File.Exists(platformWebDllPath)) { Assert.Fail($"{platformWebDllPath} can't be found!"); } diff --git a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs index 0a62f7f..103f9bb 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs @@ -30,10 +30,9 @@ protected override async Task InnerInstall(ModuleSource source, IProgress(path); + var absolutePath = path.ToAbsolutePath(); + var baseManifest = absolutePath.ReadJson(); ManifestBase result; if (string.IsNullOrEmpty(baseManifest.ManifestVersion) || new Version(baseManifest.ManifestVersion) < new Version("2.0")) { - result = SerializationTasks.JsonDeserializeFromFile(path); + result = absolutePath.ReadJson(); } else { - result = SerializationTasks.JsonDeserializeFromFile(path); + result = absolutePath.ReadJson(); } return result; diff --git a/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs b/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs index 8d6ab25..8066db4 100644 --- a/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs +++ b/src/VirtoCommerce.Build/Utils/ArtifactPacker.cs @@ -3,16 +3,17 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; +using Extensions; using Nuke.Common.IO; namespace Utils { - public static class ArtifactPacker + public static partial class ArtifactPacker { - public static void CompressPlatform(string sourceDirectory, string outputZipPath) + public static void CompressPlatform(AbsolutePath sourceDirectory, AbsolutePath outputZipPath) { - FileSystemTasks.DeleteFile(outputZipPath); - CompressionTasks.CompressZip(sourceDirectory, outputZipPath); + outputZipPath.DeleteFile(); + sourceDirectory.ZipTo(outputZipPath); } public static void CompressModule(Action optionsBuilderAction) @@ -25,7 +26,7 @@ public static void CompressModule(Action option FileExistsPolicy.Overwrite); //Exclude all ignored files and *module files not related to compressed module - var ignoreModuleFilesRegex = new Regex(@".+Module\..*", RegexOptions.IgnoreCase); + var ignoreModuleFilesRegex = IgnoreModuleFilesRegex(); var includeModuleFilesRegex = new Regex(@$".*{options.ModuleId}(Module)?\..*", RegexOptions.IgnoreCase); @@ -40,13 +41,16 @@ public static void CompressModule(Action option } } - bool FilesFilter(FileInfo x) => - (!SkipFileByList(x.Name, options.IgnoreList) && - !SkipFileByRegex(x.Name, ignoreModuleFilesRegex)) || KeepFileByList(x.Name, options.KeepList) || - KeepFileByRegex(x.Name, includeModuleFilesRegex); + bool FilesFilter(AbsolutePath path) + { + var fileInfo = path.ToFileInfo(); + return (!SkipFileByList(fileInfo.Name, options.IgnoreList) && + !SkipFileByRegex(fileInfo.Name, ignoreModuleFilesRegex)) || KeepFileByList(fileInfo.Name, options.KeepList) || + KeepFileByRegex(fileInfo.Name, includeModuleFilesRegex); + } - FileSystemTasks.DeleteFile(options.OutputZipPath); - CompressionTasks.CompressZip(options.SourceDirectory, options.OutputZipPath, FilesFilter); + options.OutputZipPath.ToAbsolutePath().DeleteFile(); + options.SourceDirectory.ToAbsolutePath().ZipTo(options.OutputZipPath, FilesFilter); } @@ -69,5 +73,8 @@ public static bool KeepFileByRegex(string name, Regex keepRegex) { return keepRegex.IsMatch(name); } + + [GeneratedRegex(@".+Module\..*", RegexOptions.IgnoreCase)] + private static partial Regex IgnoreModuleFilesRegex(); } } diff --git a/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj b/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj index 9f5435c..f28a73e 100644 --- a/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj +++ b/src/VirtoCommerce.Build/VirtoCommerce.Build.csproj @@ -2,7 +2,7 @@ VirtoCommerce.GlobalTool Exe - net6.0 + net8.0 LatestMajor false @@ -30,18 +30,18 @@ - - + + - + - + all - - + + @@ -51,10 +51,10 @@ all - - - - + + + + diff --git a/src/Virtocloud.Client/src/VirtoCloud.Client/Client/ApiClient.cs b/src/Virtocloud.Client/src/VirtoCloud.Client/Client/ApiClient.cs index 720a56e..4de2e49 100644 --- a/src/Virtocloud.Client/src/VirtoCloud.Client/Client/ApiClient.cs +++ b/src/Virtocloud.Client/src/VirtoCloud.Client/Client/ApiClient.cs @@ -7,7 +7,6 @@ * Generated by: https://github.com/openapitools/openapi-generator.git */ - using System; using System.Collections; using System.Collections.Generic; @@ -386,8 +385,6 @@ private HttpRequestMessage NewRequest( } } - - // TODO provide an alternative that allows cookies per request instead of per API client if (options.Cookies != null && options.Cookies.Count > 0) { diff --git a/src/Virtocloud.Client/src/VirtoCloud.Client/VirtoCloud.Client.csproj b/src/Virtocloud.Client/src/VirtoCloud.Client/VirtoCloud.Client.csproj index af1160c..3a09e73 100644 --- a/src/Virtocloud.Client/src/VirtoCloud.Client/VirtoCloud.Client.csproj +++ b/src/Virtocloud.Client/src/VirtoCloud.Client/VirtoCloud.Client.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 VirtoCloud.Client 1.0.0.0 VirtoCloud.Client From 57fabda0f083d252c84a3c11fcee2386e28c74a8 Mon Sep 17 00:00:00 2001 From: Alexandr Morogov <42555001+krankenbro@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:42:25 +0100 Subject: [PATCH 2/2] VCI-818: Increased default http timeout to 180sec (#119) --- src/VirtoCommerce.Build/Build.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VirtoCommerce.Build/Build.cs b/src/VirtoCommerce.Build/Build.cs index 9c37bfe..e8069f6 100644 --- a/src/VirtoCommerce.Build/Build.cs +++ b/src/VirtoCommerce.Build/Build.cs @@ -181,7 +181,7 @@ public static Solution Solution [Parameter("Main branch")] public static string MainBranch { get; set; } = "master"; [Parameter("Http tasks timeout in seconds")] - public static int HttpTimeout { get; set; } = 15; + public static int HttpTimeout { get; set; } = 180; protected static GitRepository GitRepository => GitRepository.FromLocalDirectory(RootDirectory / ".git");