Skip to content

Commit

Permalink
Merge branch 'fix/3.21.1' of https://github.com/VirtoCommerce/vc-build
Browse files Browse the repository at this point in the history
…into fix/3.21.1
  • Loading branch information
krankenbro committed Mar 11, 2024
2 parents a084aeb + 774b316 commit d95e064
Show file tree
Hide file tree
Showing 50 changed files with 602 additions and 513 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Copyright>Copyright © VirtoCommerce 2011-2022</Copyright>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>3.21.4</VersionPrefix>
<VersionPrefix>3.800.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
</PropertyGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/VirtoCommerce.Build.Tests/PackageManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Extensions;
using PlatformTools;
using PlatformTools.Modules;
using VirtoCommerce.Build.PlatformTools;

namespace VirtoCommerce.Build.Tests
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
69 changes: 35 additions & 34 deletions src/VirtoCommerce.Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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");
Expand Down Expand Up @@ -180,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");

Expand Down Expand Up @@ -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 => _ => _
Expand Down Expand Up @@ -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())
Expand All @@ -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");
Expand Down Expand Up @@ -532,7 +534,7 @@ private static void WebPackBuildMethod(Project webProject)

var modulesJsonFilePath = ModulesLocalDirectory / ModulesJsonName;
var externalManifests =
JsonConvert.DeserializeObject<List<ExternalModuleManifest>>(TextTasks.ReadAllText(modulesJsonFilePath));
JsonConvert.DeserializeObject<List<ExternalModuleManifest>>(modulesJsonFilePath.ReadAllText());
var externalManifest = externalManifests?.Find(x => x.Id == manifest.Id);

if (externalManifest != null)
Expand Down Expand Up @@ -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 => _ => _
Expand All @@ -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";
Expand Down Expand Up @@ -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}");
Expand All @@ -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)
Expand Down Expand Up @@ -832,7 +833,7 @@ private static void ClearTempOnExit()
{
if (ClearTempBeforeExit)
{
FileSystemTasks.DeleteDirectory(TemporaryDirectory);
TemporaryDirectory.DeleteDirectory();
}
}

Expand All @@ -842,7 +843,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");
Expand All @@ -858,7 +859,7 @@ private static void CreateNukeDirectory()
CreateDotNuke(currentDirectory);
}
}
else if (nukeFiles.Any())
else if (nukeFiles.Length > 0)
{
var nukeFile = nukeFiles[0];
ConvertDotNukeFile(nukeFile);
Expand Down Expand Up @@ -894,21 +895,21 @@ 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);
}

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)
Expand All @@ -926,9 +927,9 @@ public static void ChangeProjectVersion(string versionPrefix = null, string vers
//theme
if (IsTheme)
{
var jObject = SerializationTasks.JsonDeserializeFromFile<JObject>(PackageJsonPath);
var jObject = JsonExtensions.ReadJson<JObject>(PackageJsonPath);
jObject["version"] = versionPrefix;
SerializationTasks.JsonSerializeToFile(jObject, Path.GetFullPath(PackageJsonPath));
JsonExtensions.WriteJson(Path.GetFullPath(PackageJsonPath), jObject);
return;
}

Expand Down Expand Up @@ -1173,15 +1174,15 @@ 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();

var keepFiles = Array.Empty<string>();
if (ModuleKeepFile.FileExists())
{
keepFiles = TextTasks.ReadAllLines(ModuleKeepFile).ToArray();
keepFiles = ModuleKeepFile.ReadAllLines().ToArray();
}

ArtifactPacker.CompressModule(options => options.WithSourceDirectory(ModuleOutputDirectory)
Expand All @@ -1203,33 +1204,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();
}
}
10 changes: 5 additions & 5 deletions src/VirtoCommerce.Build/Cloud/Build.SaaS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private async Task PrepareDockerContextMethod()
var dockerfilePath = dockerBuildContext / "Dockerfile";
var waitScriptPath = dockerBuildContext / "wait-for-it.sh";

FileSystemTasks.EnsureCleanDirectory(dockerBuildContext);
dockerBuildContext.CreateOrCleanDirectory();

await HttpTasks.HttpDownloadFileAsync(DockerfileUrl, dockerfilePath);
await HttpTasks.HttpDownloadFileAsync(WaitScriptUrl, waitScriptPath);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -303,7 +302,8 @@ private async Task<string> GetCloudTokenAsync()

private void SaveCloudToken(string token)
{
FileSystemTasks.EnsureExistingDirectory(Path.GetDirectoryName(CloudTokenFile));
AbsolutePath cloudTokenDir = Path.GetDirectoryName(CloudTokenFile);
cloudTokenDir.CreateDirectory();
File.WriteAllText(CloudTokenFile, token);
}

Expand Down Expand Up @@ -389,7 +389,7 @@ private void SaveCloudToken(string token)
public Target CloudUp => _ => _
.DependsOn(PrepareDockerContext, BuildAndPush, CloudInit);

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;
Expand Down
5 changes: 3 additions & 2 deletions src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Cloud.Models;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Utilities;

namespace Cloud.Client;

Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task<string> 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)
Expand All @@ -65,7 +66,7 @@ public async Task<CloudEnvironment> GetEnvironment(string environmentName, strin
}

var responseContent = await response.Content.ReadAsStringAsync();
var env = SerializationTasks.JsonDeserialize<CloudEnvironment>(responseContent);
var env = JsonExtensions.GetJson<CloudEnvironment>(responseContent);
return env;
}
}
4 changes: 2 additions & 2 deletions src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.ComponentModel;
using System.Globalization;
using Newtonsoft.Json;
using Nuke.Common.IO;
using Nuke.Common.Utilities;

namespace Cloud.Models
{
Expand All @@ -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
Expand Down
Loading

0 comments on commit d95e064

Please sign in to comment.