Skip to content

Commit

Permalink
VCI-870: Support of modules update when platform is in source code (#137
Browse files Browse the repository at this point in the history
)
  • Loading branch information
krankenbro authored May 8, 2024
1 parent 7d5ac37 commit d3e0725
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
7 changes: 4 additions & 3 deletions src/VirtoCommerce.Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public static Solution Solution
protected static GitRepository GitRepository => GitRepository.FromLocalDirectory(RootDirectory / ".git");

protected static AbsolutePath SourceDirectory => RootDirectory / "src";
protected static bool IsPlatformSource => SourceDirectory.Exists();
protected static AbsolutePath TestsDirectory => RootDirectory / "tests";
protected static AbsolutePath SamplesDirectory => RootDirectory / "samples";

Expand Down Expand Up @@ -301,13 +302,13 @@ protected override void OnTargetFailed(string target)
.Before(Restore)
.Executes(() =>
{
AbsolutePath[] ignorePaths = null;
List<AbsolutePath> ignorePaths = [WebProject.Directory / "modules"];
if (ThereAreCustomApps)
{
ignorePaths = [WebProject.Directory / "App"];
ignorePaths.Add(WebProject.Directory / "App");
}

CleanSolution(cleanSearchPattern, ignorePaths);
CleanSolution(cleanSearchPattern, ignorePaths.ToArray());
});

public Target Restore => _ => _
Expand Down
74 changes: 47 additions & 27 deletions src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal partial class Build
public static string[] Module { get; set; }

[Parameter("Skip dependency solving")]
public static bool SkipDependencySolving { get; set; }
public static bool SkipDependencySolving { get; set; } = true;

[Parameter("Install the platform", Name = "Platform")]
public static bool PlatformParameter { get; set; }
Expand Down Expand Up @@ -67,10 +67,11 @@ internal partial class Build
public static string DiscoveryPath { get; set; }

[Parameter("Probing path")]
public static AbsolutePath ProbingPath { get; set; } = RootDirectory / "app_data" / "modules";
public static AbsolutePath ProbingPath { get; set; } = PlatformRootDirectory / "app_data" / "modules";

[Parameter("appsettings.json path")]
public static AbsolutePath AppsettingsPath { get; set; } = RootDirectory / "appsettings.json";
public static AbsolutePath AppsettingsPath { get; set; } = PlatformRootDirectory / "appsettings.json";
public static AbsolutePath PlatformRootDirectory => IsPlatformSource ? WebDirectory : RootDirectory;

public Target InitPlatform => _ => _
.Executes(() =>
Expand Down Expand Up @@ -252,7 +253,7 @@ private static bool SkipFile(FileInfo fileInfo)
.Executes(() => BackupFile.DeleteFile());

public Target InstallPlatform => _ => _
.OnlyWhenDynamic(() => PlatformVersionChanged && !IsModulesInstallation)
.OnlyWhenDynamic(() => PlatformVersionChanged && !IsModulesInstallation && !IsPlatformSource)
.Executes(async () =>
{
var packageManifest = PackageManager.FromFile(PackageManifestPath);
Expand Down Expand Up @@ -319,8 +320,18 @@ private static async Task InstallPlatformAsync(string platformVersion, string pl

private static string GetDiscoveryPath()
{
var configuration = AppSettings.GetConfiguration(RootDirectory, AppsettingsPath);
return DiscoveryPath.EmptyToNull() ?? configuration.GetModulesDiscoveryPath();
if (DiscoveryPath.IsNullOrEmpty())
{
var configuration = AppSettings.GetConfiguration(PlatformRootDirectory, AppsettingsPath);
var path = configuration.GetModulesDiscoveryPath();
if (!Path.IsPathRooted(path))
{
path = Path.GetFullPath(path, PlatformRootDirectory);
}
return path;
}

return DiscoveryPath;
}

private static bool IsPlatformInstallationNeeded(string version)
Expand Down Expand Up @@ -517,7 +528,7 @@ private static ManifestModuleInfo LoadModuleInfo(ModuleItem module, ManifestModu
.Executes(async () =>
{
SkipDependencySolving = true;
var manifest = await OpenOrCreateManifest(PackageManifestPath, Edge);
var manifest = await OpenOrCreateManifest(PackageManifestPath.ToAbsolutePath(), Edge);

if (Edge)
{
Expand All @@ -533,7 +544,11 @@ private static ManifestModuleInfo LoadModuleInfo(ModuleItem module, ManifestModu

private static async Task<ManifestBase> UpdateEdgeAsync(ManifestBase manifest, bool platformOnly)
{
manifest = await UpdateEdgePlatformAsync(manifest);
if (!IsPlatformSource)
{
manifest = await UpdateEdgePlatformAsync(manifest);
}

if(!platformOnly)
{
manifest = await UpdateEdgeModulesAsync(manifest);
Expand All @@ -547,7 +562,11 @@ private async Task<ManifestBase> UpdateStableAsync(ManifestBase manifest, bool p
await DownloadBundleManifest(bundleName, bundleTmpFilePath);

var bundle = PackageManager.FromFile(bundleTmpFilePath);
manifest = await UpdateStablePlatformAsync(manifest, bundle);
if (!IsPlatformSource)
{
manifest = await UpdateStablePlatformAsync(manifest, bundle);
}

if (!platformOnly)
{
manifest = await UpdateStableModulesAsync((MixedPackageManifest)manifest, (MixedPackageManifest)bundle);
Expand Down Expand Up @@ -626,33 +645,34 @@ private static async Task<ManifestBase> UpdateEdgeModulesAsync(ManifestBase mani

private static async Task<ManifestBase> OpenOrCreateManifest(string packageManifestPath, bool isEdge)
{
ManifestBase result;
var platformWebDllPath = Path.Combine(Directory.GetParent(packageManifestPath).FullName, "VirtoCommerce.Platform.Web.dll");
if (!isEdge)
if(!File.Exists(packageManifestPath))
{
SkipDependencySolving = true;
if (!File.Exists(packageManifestPath))
if (!isEdge) //Stable
{
await DownloadBundleManifest(BundleName, packageManifestPath);
result = PackageManager.FromFile(packageManifestPath);
}
else if (File.Exists(platformWebDllPath)) // There is platform
{
var discoveryAbsolutePath = Path.GetFullPath(GetDiscoveryPath());
result = await CreateManifestFromEnvironment(PlatformRootDirectory, discoveryAbsolutePath.ToAbsolutePath());
}
else // Create new
{
Log.Information("vc-package.json does not exist.");
Log.Information("Looking for the platform release");
var platformRelease = await GithubManager.GetPlatformRelease(GitHubToken, VersionToInstall);
result = PackageManager.CreatePackageManifest(platformRelease.TagName);
}
return PackageManager.FromFile(packageManifestPath);
}
else if (!File.Exists(packageManifestPath) && File.Exists(platformWebDllPath))
{
var discoveryAbsolutePath = Path.GetFullPath(GetDiscoveryPath());
return await CreateManifestFromEnvironment(RootDirectory, discoveryAbsolutePath.ToAbsolutePath());
}
else if (!File.Exists(packageManifestPath))
{
Log.Information("vc-package.json does not exist.");
Log.Information("Looking for the platform release");
var platformRelease = await GithubManager.GetPlatformRelease(GitHubToken, VersionToInstall);
return PackageManager.CreatePackageManifest(platformRelease.TagName);
}
else
{
SkipDependencySolving = true;
return PackageManager.FromFile(PackageManifestPath);
result = PackageManager.FromFile(packageManifestPath);
}

return result;
}

private static async Task DownloadBundleManifest(string bundleName, string outFile)
Expand Down
4 changes: 0 additions & 4 deletions src/VirtoCommerce.Build/Utils/ModuleCompressionOptions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Utils
{
Expand Down

0 comments on commit d3e0725

Please sign in to comment.