Skip to content

Commit

Permalink
VCI-821: Add check for symlinks in installmodules target
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro committed Mar 1, 2024
1 parent a7141c2 commit f2983af
Show file tree
Hide file tree
Showing 36 changed files with 411 additions and 371 deletions.
2 changes: 1 addition & 1 deletion src/VirtoCommerce.Build.Tests/PackageManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Extensions;
using Nuke.Common.IO;
using PlatformTools;
using PlatformTools.Modules;
using VirtoCommerce.Build.PlatformTools;

namespace VirtoCommerce.Build.Tests
Expand Down
11 changes: 0 additions & 11 deletions src/VirtoCommerce.Build/PlatformTools/Azure/AzureBlobModuleItem.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Nuke.Common;
using Nuke.Common.IO;
using PlatformTools;
using PlatformTools.Modules;
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.Build
Expand Down
16 changes: 10 additions & 6 deletions src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using PlatformTools;
using PlatformTools.Azure;
using PlatformTools.Github;
using PlatformTools.Gitlab;
using PlatformTools.Extensions;
using PlatformTools.Modules;
using PlatformTools.Modules.Azure;
using PlatformTools.Modules.Github;
using PlatformTools.Modules.Gitlab;
using Serilog;
using VirtoCommerce.Build.PlatformTools;
using VirtoCommerce.Platform.Core.Common;
Expand Down Expand Up @@ -312,6 +314,7 @@ private static bool IsPlatformInstallationNeeded(string version)
return result;
}


public Target InstallModules => _ => _
.After(InstallPlatform)
.OnlyWhenDynamic(() => !PlatformParameter)
Expand All @@ -322,6 +325,7 @@ private static bool IsPlatformInstallationNeeded(string version)
{
SkipDependencySolving = true;
}
var packageManifest = PackageManager.FromFile(PackageManifestPath);
var moduleSources = PackageManager.GetModuleSources(packageManifest).Where(s => s is not GithubReleases).ToList();
var githubReleases = PackageManager.GetGithubModulesSource(packageManifest);
Expand All @@ -343,7 +347,7 @@ private static bool IsPlatformInstallationNeeded(string version)
return;
}
if (alreadyInstalledModules.Any(installedModule => installedModule.ModuleName == module.Id && installedModule.Version.ToString() == module.Version))
if (alreadyInstalledModules.Exists(installedModule => installedModule.ModuleName == module.Id && installedModule.Version.ToString() == module.Version) || localModuleCatalog.IsModuleFromSourceCode(module.Id))
{
continue;
}
Expand Down Expand Up @@ -485,7 +489,7 @@ private static ManifestModuleInfo LoadModuleInfo(ModuleItem module, ManifestModu
.Executes(async () =>
{
SkipDependencySolving = true;
var manifest = PackageManager.FromFile(PackageManifestPath);
var manifest = await OpenOrCreateManifest(PackageManifestPath, Edge);
if (Edge)
{
Expand Down Expand Up @@ -638,7 +642,7 @@ private static async Task DownloadBundleManifest(string bundleName, string outFi
}

var manifestUrl = bundle.Value;
await HttpTasks.HttpDownloadFileAsync(manifestUrl, outFile);
await HttpTasks.HttpDownloadFileAsync(manifestUrl, outFile.ToAbsolutePath());
}

private static ManifestBase CreateManifestFromEnvironment(AbsolutePath platformPath, AbsolutePath discoveryPath)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.IO;
using System.Linq;
using PlatformTools.Modules;
using VirtoCommerce.Platform.Core.Modularity;

namespace PlatformTools.Extensions
{
public static class LocalModuleCatalogExtensions
{
public static bool IsModuleFromSourceCode(this ILocalModuleCatalog moduleCatalog, string moduleId)
{
var moduleInfo = moduleCatalog.Modules.OfType<ManifestModuleInfo>().FirstOrDefault(m => m.ModuleName == moduleId);
if(moduleInfo == null)
{
return false;
}

var fileInfo = new FileInfo(moduleInfo.FullPhysicalPath);

return fileInfo.LinkTarget != null;
}
}
}
2 changes: 1 addition & 1 deletion src/VirtoCommerce.Build/PlatformTools/GithubReleases.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using PlatformTools;
using PlatformTools.Modules;

namespace VirtoCommerce.Build.PlatformTools
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using PlatformTools.Modules;

namespace VirtoCommerce.Build.PlatformTools
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using VirtoCommerce.Build.PlatformTools;
using PlatformTools.Modules;

namespace PlatformTools.Azure
namespace PlatformTools.Modules.Azure
{
internal class AzureBlob : ModuleSource
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using VirtoCommerce.Build.PlatformTools;
using PlatformTools.Modules;
using VirtoCommerce.Platform.Core.Modularity;
using AzureBlobs = Azure.Storage.Blobs;

namespace PlatformTools.Azure
namespace PlatformTools.Modules.Azure
{
internal class AzureBlobModuleInstaller : ModulesInstallerBase
{
Expand All @@ -31,7 +31,7 @@ protected override Task InnerInstall(ModuleSource source, IProgress<ProgressMess
{
progress.ReportInfo($"Installing {moduleBlobName}");
var zipName = moduleBlobName;
if(!zipName.EndsWith(".zip"))
if (!zipName.EndsWith(".zip"))
{
zipName += ".zip";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using PlatformTools.Modules;

namespace PlatformTools.Modules.Azure
{
internal class AzureBlobModuleItem : ModuleItem
{
public AzureBlobModuleItem(string id, string version) : base(id, version)
{

}
public string BlobName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Nuke.Common.Tooling;

namespace PlatformTools.Azure
namespace PlatformTools.Modules.Azure
{
[Serializable]
internal class AzureCliToolSettings : ToolSettings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using Nuke.Common;

namespace PlatformTools.Azure;

public class AzureDevClient
{
private readonly VssConnection _connection;

public AzureDevClient(string orgName, string token)
{
_connection = new VssConnection(new Uri(orgName), new VssBasicCredential(string.Empty, token));
}

public async Task<Uri> GetArtifactUrl(Guid project, string branch, string definitionName)
{
var client = await _connection.GetClientAsync<BuildHttpClient>();
var build = await client.GetLatestBuildAsync(project, definitionName, branch);
var artifacts = await client.GetArtifactsAsync(project, build.Id);
Assert.NotEmpty(artifacts,
$"No builds found for the project id: {project.ToString()}{Environment.NewLine}branch: {branch}{Environment.NewLine}definition: {definitionName}");
var result = artifacts.FirstOrDefault()?.Resource.DownloadUrl;

return new Uri(result ?? string.Empty);
}

public async Task<Stream> GetArtifactStream(Guid project, string branch, string definitionName)
{
var client = await _connection.GetClientAsync<BuildHttpClient>();
var build = await client.GetLatestBuildAsync(project, definitionName, branch);
var result = await client.GetArtifactContentZipAsync(project, build.Id, "backend");
return result;
}
}
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using Nuke.Common;

namespace PlatformTools.Modules.Azure;

public class AzureDevClient
{
private readonly VssConnection _connection;

public AzureDevClient(string orgName, string token)
{
_connection = new VssConnection(new Uri(orgName), new VssBasicCredential(string.Empty, token));
}

public async Task<Uri> GetArtifactUrl(Guid project, string branch, string definitionName)
{
var client = await _connection.GetClientAsync<BuildHttpClient>();
var build = await client.GetLatestBuildAsync(project, definitionName, branch);
var artifacts = await client.GetArtifactsAsync(project, build.Id);
Assert.NotEmpty(artifacts,
$"No builds found for the project id: {project.ToString()}{Environment.NewLine}branch: {branch}{Environment.NewLine}definition: {definitionName}");
var result = artifacts.FirstOrDefault()?.Resource.DownloadUrl;

return new Uri(result ?? string.Empty);
}

public async Task<Stream> GetArtifactStream(Guid project, string branch, string definitionName)
{
var client = await _connection.GetClientAsync<BuildHttpClient>();
var build = await client.GetLatestBuildAsync(project, definitionName, branch);
var result = await client.GetArtifactContentZipAsync(project, build.Id, "backend");
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
namespace PlatformTools.Azure
{
internal class AzureModuleItem : ModuleItem
{
public AzureModuleItem(string id, string version) : base(id, version)
{
}

public string BuildId { get; set; }
public string Branch { get; set; }
public string Definition { get; set; }
}
}

using PlatformTools.Modules;

namespace PlatformTools.Modules.Azure
{
internal class AzureModuleItem : ModuleItem
{
public AzureModuleItem(string id, string version) : base(id, version)
{
}

public string BuildId { get; set; }
public string Branch { get; set; }
public string Definition { get; set; }
}
}

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Collections.Generic;
using VirtoCommerce.Build.PlatformTools;

namespace PlatformTools.Azure
{
internal class AzurePipelineArtifacts : ModuleSource
{
public string Organization { get; set; }
public string Project { get; set; }
public List<AzureModuleItem> Modules { get; set; }
public override string Name { get; set; } = nameof(AzurePipelineArtifacts);
}
}
using System.Collections.Generic;
using PlatformTools.Modules;

namespace PlatformTools.Modules.Azure
{
internal class AzurePipelineArtifacts : ModuleSource
{
public string Organization { get; set; }
public string Project { get; set; }
public List<AzureModuleItem> Modules { get; set; }
public override string Name { get; set; } = nameof(AzurePipelineArtifacts);
}
}

Loading

0 comments on commit f2983af

Please sign in to comment.