Skip to content

Commit

Permalink
VCI-629: Add Organization parameter for SetEnvParameter target (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro authored Aug 22, 2023
1 parent e1e2eb6 commit 518ea38
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/VirtoCommerce.Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ private void CompressExecuteMethod()
keepFiles = TextTasks.ReadAllLines(ModuleKeepFile).ToArray();
}

ArtifactPacker.CompressModuleAsync(ModuleOutputDirectory, ZipFilePath, ModuleManifest.Id, ModuleManifestFile, WebProject.Directory, ignoredFiles, keepFiles, _moduleContentFolders);
ArtifactPacker.CompressModule(ModuleOutputDirectory, ZipFilePath, ModuleManifest.Id, ModuleManifestFile, WebProject.Directory, ignoredFiles, keepFiles, _moduleContentFolders);
}
else
{
Expand Down
5 changes: 4 additions & 1 deletion src/VirtoCommerce.Build/Cloud/Build.SaaS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ internal partial class Build
[Parameter("App Project Name")] public string AppProject { get; set; }
[Parameter("Cloud Environment Name")] public string EnvironmentName { get; set; }

[Parameter("Organization name", Name = "Organization")] public string SaaSOrganizationName { get; set; }

public Target WaitFor => _ => _
.Executes(async () =>
{
Expand Down Expand Up @@ -125,7 +127,8 @@ internal partial class Build
.Executes(async () =>
{
var cloudClient = new VirtoCloudClient(CloudUrl, CloudToken);
var env = await cloudClient.GetEnvironment(EnvironmentName);
var env = await cloudClient.GetEnvironment(EnvironmentName, SaaSOrganizationName);
var envHelmParameters = env.Helm.Parameters;
foreach (var parameter in HelmParameters)
{
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 @@ -51,12 +51,13 @@ public async Task UpdateEnvironmentAsync(CloudEnvironment environment)
}
}

public async Task<CloudEnvironment> GetEnvironment(string environmentName)
public async Task<CloudEnvironment> GetEnvironment(string environmentName, string orgName = null)
{
var relativeUri = string.IsNullOrWhiteSpace(orgName) ? $"api/saas/environments/{environmentName}" : $"api/saas/environments/{orgName}/{environmentName}";
var response = await _client.SendAsync(new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri($"api/saas/environments/{environmentName}", UriKind.Relative)
RequestUri = new Uri(relativeUri, UriKind.Relative)
});
if (!response.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ 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}");
}

Log.Information($"Extracting {zipPath}");
ZipFile.ExtractToDirectory(zipPath, moduleDestination);
Expand Down
4 changes: 3 additions & 1 deletion src/VirtoCommerce.Build/PlatformTools/GithubManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public static Tuple<string, string> GetRepoFromUrl(string url)
var regex = new Regex(@"http[s]{0,1}:\/\/github.com\/([A-z0-9]*)\/([A-z0-9\-]*)\/", RegexOptions.IgnoreCase);
var match = regex.Match(url);
var groups = match.Groups;
return new Tuple<string, string>(groups[1].Value, groups[2].Value);
const int repoOwnerGroupIndex = 1;
const int repoNameGroupIndex = 2;
return new Tuple<string, string>(groups[repoOwnerGroupIndex].Value, groups[repoNameGroupIndex].Value);
}

public static Task<Release> GetModuleRelease(string token, string moduleRepo, string releaseTag)
Expand Down
40 changes: 23 additions & 17 deletions src/VirtoCommerce.Build/PlatformTools/LocalCatalog.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Exceptions;
using VirtoCommerce.Platform.Core.Modularity;
Expand Down Expand Up @@ -32,10 +32,14 @@ public LocalCatalog(IOptions<LocalStorageModuleCatalogOptions> options, IInterna
protected override void InnerLoad()
{
if (string.IsNullOrEmpty(_options.ProbingPath))
{
throw new InvalidOperationException("The ProbingPath cannot contain a null value or be empty");
}

if (string.IsNullOrEmpty(_options.DiscoveryPath))
{
throw new InvalidOperationException("The DiscoveryPath cannot contain a null value or be empty");

}

var manifests = GetModuleManifests();

Expand Down Expand Up @@ -156,24 +160,26 @@ private IDictionary<string, ModuleManifest> GetModuleManifests()
}
private void CopyAssemblies(string sourceParentPath, string targetDirectoryPath)
{
if (sourceParentPath != null)
if (sourceParentPath == null)
{
var sourceDirectoryPath = Path.Combine(sourceParentPath, "bin");
return;
}

var sourceDirectoryPath = Path.Combine(sourceParentPath, "bin");

if (Directory.Exists(sourceDirectoryPath))
if (Directory.Exists(sourceDirectoryPath))
{
foreach (var sourceFilePath in Directory.EnumerateFiles(sourceDirectoryPath, "*.*", SearchOption.AllDirectories))
{
foreach (var sourceFilePath in Directory.EnumerateFiles(sourceDirectoryPath, "*.*", SearchOption.AllDirectories))
// Copy all assembly related files except assemblies that are inlcuded in TPA list
if (IsAssemblyRelatedFile(sourceFilePath))
{
// Copy all assembly related files except assemblies that are inlcuded in TPA list
if (IsAssemblyRelatedFile(sourceFilePath))
{
// Copy localization resource files to related subfolders
var targetFilePath = Path.Combine(
IsLocalizationFile(sourceFilePath) ? Path.Combine(targetDirectoryPath, Path.GetFileName(Path.GetDirectoryName(sourceFilePath)))
: targetDirectoryPath,
Path.GetFileName(sourceFilePath));
CopyFile(sourceFilePath, targetFilePath);
}
// Copy localization resource files to related subfolders
var targetFilePath = Path.Combine(
IsLocalizationFile(sourceFilePath) ? Path.Combine(targetDirectoryPath, Path.GetFileName(Path.GetDirectoryName(sourceFilePath)))
: targetDirectoryPath,
Path.GetFileName(sourceFilePath));
CopyFile(sourceFilePath, targetFilePath);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public class ModuleSourceSpecifiedConcreteClassConverter : DefaultContractResolv
protected override JsonConverter ResolveContractConverter(Type objectType)
{
if (typeof(ModuleSource).IsAssignableFrom(objectType) && !objectType.IsAbstract)
{
return null; // pretend TableSortRuleConvert is not specified (thus avoiding a stack overflow)
}

return base.ResolveContractConverter(objectType);
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/VirtoCommerce.Build/Utils/ArtifactPacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NuGet.Packaging;
using Nuke.Common.IO;
using Octokit;
using VirtoCommerce.Platform.Core.Modularity;

namespace Utils
{
Expand All @@ -20,7 +15,7 @@ public static void CompressPlatform(string sourceDirectory, string outputZipPath
CompressionTasks.CompressZip(sourceDirectory, outputZipPath);
}

public static void CompressModuleAsync(string sourceDirectory, string outputZipPath, string moduleId, string moduleManifestPath, string webProjectDirectory, IEnumerable<string> ignoreList, IEnumerable<string> keepList, string[] moduleContentFolders)
public static void CompressModule(string sourceDirectory, string outputZipPath, string moduleId, string moduleManifestPath, string webProjectDirectory, IEnumerable<string> ignoreList, IEnumerable<string> keepList, string[] moduleContentFolders)
{
FileSystemTasks.CopyFileToDirectory(moduleManifestPath, sourceDirectory,
FileExistsPolicy.Overwrite);
Expand Down

0 comments on commit 518ea38

Please sign in to comment.