diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleInstaller.cs index 1d725a6..c6e4875 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleInstaller.cs @@ -3,8 +3,8 @@ using System.IO.Compression; using System.Linq; using System.Threading.Tasks; -using Serilog; using VirtoCommerce.Build.PlatformTools; +using VirtoCommerce.Platform.Core.Modularity; using AzureBlobs = Azure.Storage.Blobs; namespace PlatformTools.Azure @@ -20,7 +20,7 @@ public AzureBlobModuleInstaller(string token, string destination) _destination = destination; } - protected override Task InnerInstall(ModuleSource source) + protected override Task InnerInstall(ModuleSource source, IProgress progress) { var azureBlobSource = (AzureBlob)source; var blobClientOptions = new AzureBlobs.BlobClientOptions(); @@ -29,7 +29,7 @@ protected override Task InnerInstall(ModuleSource source) Directory.CreateDirectory(_destination); foreach (var moduleBlobName in azureBlobSource.Modules.Select(m => m.BlobName)) { - Log.Information($"Installing {moduleBlobName}"); + progress.ReportInfo($"Installing {moduleBlobName}"); var zipName = moduleBlobName; if(!zipName.EndsWith(".zip")) { @@ -42,12 +42,12 @@ protected override Task InnerInstall(ModuleSource source) { moduleDestination = moduleDestination.Replace(".zip", ""); } - Log.Information($"Downloading Blob {moduleBlobName}"); + progress.ReportInfo($"Downloading Blob {moduleBlobName}"); var blobClient = containerClient.GetBlobClient(moduleBlobName); blobClient.DownloadTo(zipPath); - Log.Information($"Extracting Blob {moduleBlobName}"); + progress.ReportInfo($"Extracting Blob {moduleBlobName}"); ZipFile.ExtractToDirectory(zipPath, moduleDestination, true); - Log.Information($"Successfully installed {moduleBlobName}"); + progress.ReportInfo($"Successfully installed {moduleBlobName}"); } return Task.CompletedTask; } diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsModuleInstaller.cs index 680fc59..189a130 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Azure/AzurePipelineArtifactsModuleInstaller.cs @@ -3,8 +3,8 @@ using System.IO; using System.IO.Compression; using System.Threading.Tasks; -using Serilog; using VirtoCommerce.Build.PlatformTools; +using VirtoCommerce.Platform.Core.Modularity; namespace PlatformTools.Azure { @@ -19,7 +19,7 @@ public AzurePipelineArtifactsModuleInstaller(string token, string discoveryPath) this._discoveryPath = discoveryPath; } - protected override async Task InnerInstall(ModuleSource source) + protected override async Task InnerInstall(ModuleSource source, IProgress progress) { var artifacts = (AzurePipelineArtifacts)source; var azureClient = new AzureDevClient(artifacts.Organization, _token); @@ -27,13 +27,13 @@ protected override async Task InnerInstall(ModuleSource source) var downloadClient = new AzurePipelineArtifactsClient(clientOptions); foreach (var module in artifacts.Modules) { - Log.Information($"Installing {module.Id}"); + progress.ReportInfo($"Installing {module.Id}"); var moduleDestination = Path.Join(_discoveryPath, module.Id); Directory.CreateDirectory(moduleDestination); var zipName = $"{module.Id}.zip"; var zipDestination = Path.Join(moduleDestination, zipName); var artifactUrl = await azureClient.GetArtifactUrl(Guid.Parse(artifacts.Project), module.Branch, module.Definition); - Log.Information($"Downloading {artifactUrl}"); + progress.ReportInfo($"Downloading {artifactUrl}"); using (var stream = downloadClient.OpenRead(artifactUrl)) { using (var output = File.OpenWrite(zipDestination)) @@ -41,9 +41,9 @@ protected override async Task InnerInstall(ModuleSource source) await stream.CopyToAsync(output); } } - Log.Information($"Extracting {zipName}"); + progress.ReportInfo($"Extracting {zipName}"); ZipFile.ExtractToDirectory(zipDestination, moduleDestination); - Log.Information($"Successfully installed {module.Id}"); + progress.ReportInfo($"Successfully installed {module.Id}"); } } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs index 397909b..8f185c2 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Azure/AzureUniversalPackagesModuleInstaller.cs @@ -1,12 +1,12 @@ +using System; using System.IO; using System.IO.Compression; using System.Linq; using System.Threading.Tasks; -using Nuke.Common; using Nuke.Common.IO; using Nuke.Common.Tooling; -using Serilog; using VirtoCommerce.Build.PlatformTools; +using VirtoCommerce.Platform.Core.Modularity; namespace PlatformTools.Azure { @@ -21,12 +21,12 @@ public AzureUniversalPackagesModuleInstaller(string token, string discoveryPath) this.discoveryPath = discoveryPath; } - protected override Task InnerInstall(ModuleSource source) + protected override Task InnerInstall(ModuleSource source, IProgress progress) { var artifacts = (AzureUniversalPackages)source; foreach (var module in artifacts.Modules) { - Log.Information($"Installing {module.Id}"); + progress.ReportInfo($"Installing {module.Id}"); var moduleDestination = Path.Join(discoveryPath, module.Id); Directory.CreateDirectory(moduleDestination); FileSystemTasks.EnsureCleanDirectory(moduleDestination); @@ -49,21 +49,16 @@ protected override Task InnerInstall(ModuleSource source) var zipPath = Directory.GetFiles(moduleDestination).FirstOrDefault(p => p.EndsWith(".zip")); if (zipPath == null) { - Assert.Fail($"Can't download {module.Id} - {module.Version}"); + progress.ReportError($"Can't download {module.Id} - {module.Version}"); } - Log.Information($"Extracting {zipPath}"); + progress.ReportInfo($"Extracting {zipPath}"); ZipFile.ExtractToDirectory(zipPath, moduleDestination); - Log.Information($"Successfully installed {module.Id}"); + progress.ReportInfo($"Successfully installed {module.Id}"); } return Task.CompletedTask; } - - public override Task Install(ModuleSource source) - { - return InnerInstall((AzureUniversalPackages)source); - } } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs index b9a27a3..a02c8db 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs @@ -308,7 +308,7 @@ private static bool IsPlatformInstallationNeeded(string version) { var versionInfo = FileVersionInfo.GetVersionInfo(platformWebDllPath); - if (versionInfo.ProductVersion != null && newVersion <= Version.Parse(versionInfo.ProductVersion)) + if (versionInfo.FileVersion != null && newVersion <= Version.Parse(versionInfo.FileVersion)) { result = false; } @@ -369,7 +369,7 @@ private static bool IsPlatformInstallationNeeded(string version) { if (m.Level == ProgressMessageLevel.Error) { - Log.Error(m.Message); + Assert.Fail(m.Message); } else { @@ -404,7 +404,7 @@ private static bool IsPlatformInstallationNeeded(string version) { var installer = GetModuleInstaller(moduleSource); - await installer.Install(moduleSource); + await installer.Install(moduleSource, progress); } var absoluteDiscoveryPath = (AbsolutePath)Path.GetFullPath(discoveryPath); var zipFiles = absoluteDiscoveryPath.GlobFiles("*/*.zip"); diff --git a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs index 3d37a23..0a62f7f 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Github/GithubPrivateModulesInstaller.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.IO.Compression; using System.Linq; @@ -5,8 +6,8 @@ using System.Threading.Tasks; using Nuke.Common.IO; using Octokit; -using Serilog; using VirtoCommerce.Build.PlatformTools; +using VirtoCommerce.Platform.Core.Modularity; namespace PlatformTools.Github { @@ -24,13 +25,13 @@ public GithubPrivateModulesInstaller(string token, string discoveryPath) _client.Credentials = new Credentials(token); } - protected override async Task InnerInstall(ModuleSource source) + protected override async Task InnerInstall(ModuleSource source, IProgress progress) { var githubPrivateRepos = (GithubPrivateRepos) source; foreach (var module in githubPrivateRepos.Modules) { var moduleDestination = Path.Join(_discoveryPath, module.Id); - Log.Information($"Installing {module.Id}"); + progress.ReportInfo($"Installing {module.Id}"); Directory.CreateDirectory(moduleDestination); FileSystemTasks.EnsureCleanDirectory(moduleDestination); var zipName = $"{module.Id}.zip"; @@ -38,16 +39,16 @@ protected override async Task InnerInstall(ModuleSource source) var release = await _client.Repository.Release.Get(githubPrivateRepos.Owner, module.Id, module.Version); if (release == null) { - Log.Error($"{module.Id}:{module.Version} is not found"); + progress.ReportError($"{module.Id}:{module.Version} is not found"); continue; } var asset = release.Assets.FirstOrDefault(); if (asset == null) { - Log.Error($"{module.Id}:{module.Version} has no assets"); + progress.ReportError($"{module.Id}:{module.Version} has no assets"); continue; } - Log.Information($"Downloading {module.Id}"); + progress.ReportInfo($"Downloading {module.Id}"); await HttpTasks.HttpDownloadFileAsync(asset.Url, zipDestination, clientConfigurator: c => { c.DefaultRequestHeaders.Add("User-Agent", "VirtoCommerce.Build"); @@ -55,9 +56,9 @@ await HttpTasks.HttpDownloadFileAsync(asset.Url, zipDestination, clientConfigura c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream")); return c; }); - Log.Information($"Extracting {module.Id}"); + progress.ReportInfo($"Extracting {module.Id}"); ZipFile.ExtractToDirectory(zipDestination, moduleDestination); - Log.Information($"Successfully installed {module.Id}"); + progress.ReportInfo($"Successfully installed {module.Id}"); } } } diff --git a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleInstaller.cs b/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleInstaller.cs index e1094df..d758122 100644 --- a/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleInstaller.cs +++ b/src/VirtoCommerce.Build/PlatformTools/Gitlab/GitlabJobArtifactsModuleInstaller.cs @@ -1,9 +1,10 @@ +using System; using System.IO; using System.IO.Compression; using System.Threading.Tasks; using Nuke.Common.IO; -using Serilog; using VirtoCommerce.Build.PlatformTools; +using VirtoCommerce.Platform.Core.Modularity; namespace PlatformTools.Gitlab; @@ -18,7 +19,7 @@ public GitlabJobArtifactsModuleInstaller(string server, string token, string dis _client = new GitLabClient(token, server); } - protected override async Task InnerInstall(ModuleSource source) + protected override async Task InnerInstall(ModuleSource source, IProgress progress) { var gitlabJobArtifacts = (GitlabJobArtifacts) source; foreach (var module in gitlabJobArtifacts.Modules) @@ -26,11 +27,11 @@ protected override async Task InnerInstall(ModuleSource source) var moduleDestination = Path.Join(_discoveryPath, module.Id); Directory.CreateDirectory(moduleDestination); FileSystemTasks.EnsureCleanDirectory(moduleDestination); - Log.Information($"Downloading {module.Id}"); + progress.ReportInfo($"Downloading {module.Id}"); var artifactZipPath = await _client.DownloadArtifact(module.Id, module.JobId, module.ArtifactName, moduleDestination); - Log.Information($"Extracting {module.Id}"); + progress.ReportInfo($"Extracting {module.Id}"); ZipFile.ExtractToDirectory(artifactZipPath, moduleDestination); - Log.Information($"Successfully installed {module.Id}"); + progress.ReportInfo($"Successfully installed {module.Id}"); } } } diff --git a/src/VirtoCommerce.Build/PlatformTools/ModulesInstallerBase.cs b/src/VirtoCommerce.Build/PlatformTools/ModulesInstallerBase.cs index bdf079b..aadeddd 100644 --- a/src/VirtoCommerce.Build/PlatformTools/ModulesInstallerBase.cs +++ b/src/VirtoCommerce.Build/PlatformTools/ModulesInstallerBase.cs @@ -1,23 +1,37 @@ using System; using System.Threading.Tasks; +using VirtoCommerce.Platform.Core.Modularity; namespace VirtoCommerce.Build.PlatformTools { public abstract class ModulesInstallerBase { - public virtual Task Install(ModuleSource source) + public virtual Task Install(ModuleSource source, IProgress progress) { try { - return InnerInstall(source); + return InnerInstall(source, progress); } catch (Exception exception) { + progress.ReportError(exception.Message); throw new ModuleInstallationException("Error while module installation", exception); } } - protected abstract Task InnerInstall(ModuleSource source); + protected abstract Task InnerInstall(ModuleSource source, IProgress progress); + } + + public static class ProgressExtension + { + public static void ReportInfo(this IProgress progress, string message) + { + progress.Report(new ProgressMessage { Level = ProgressMessageLevel.Info, Message = message }); + } + public static void ReportError(this IProgress progress, string message) + { + progress.Report(new ProgressMessage { Level = ProgressMessageLevel.Error, Message = message }); + } } }