-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* VCI-128: Fix build project search * VCI-128: Fix module manifest search * Added help for the specific target * PT-3772: Fix build of sample projects (#20) * VCI-156: Add ability to update only platform (#22) * VCI-162: Fix user input comparing (#21) * VCI-162: Fix user input comparing * VCI-162: Make WebProject static * VCI-162: Fix codesmells * VCI-157: Backup appsettings.json on update (#23) * PT-58: Add DefaultProject parameter Added DefaultProject parameter to abillity to specify startap project name to complile module sample. Default value ".Web". For sample module build run vc-build Compile -DefaultProject "SampleModule.Web" * PT-4042: Add MatchVersions target (#25) * feat: Add MatchVersions target * refactor: Decrease complexity * VCI-166: Update changelog Co-authored-by: Dimitri Kargapolov <[email protected]> Co-authored-by: Maksim <[email protected]> Co-authored-by: Maksim Kopnov <[email protected]> Co-authored-by: Konstantin Savosteev <[email protected]>
- Loading branch information
1 parent
66924a8
commit 48a0dc7
Showing
8 changed files
with
231 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using Nuke.Common; | ||
using Nuke.Common.ProjectModel; | ||
using Nuke.Common.Utilities; | ||
using PlatformTools; | ||
using VirtoCommerce.Platform.Core.Common; | ||
using VirtoCommerce.Platform.Core.Modularity; | ||
|
||
namespace VirtoCommerce.Build | ||
{ | ||
internal partial class Build | ||
{ | ||
private Regex _moduleNameRegEx = new Regex(@"(VirtoCommerce.+)Module", RegexOptions.Compiled); | ||
|
||
public Target MatchVersions => _ => _ | ||
.Executes(() => | ||
{ | ||
var allPackages = new List<PackageItem>(); | ||
var allProjects = Solution.GetProjects("*"); | ||
|
||
foreach (var project in allProjects) | ||
{ | ||
var packagesInfo = GetProjectPackages(project); | ||
allPackages.AddRange(packagesInfo); | ||
} | ||
|
||
var errors = new List<string>(); | ||
|
||
var platformErrors = ValdatePlatformVersion(allPackages); | ||
errors.AddRange(platformErrors); | ||
|
||
var dependencyVerionErrors = ValidateModuleDependenciesVersions(allPackages); | ||
errors.AddRange(dependencyVerionErrors); | ||
|
||
var missedDependenciesErrors = ValidateForMissedDependencies(allPackages); | ||
errors.AddRange(missedDependenciesErrors); | ||
|
||
if (errors.Any()) | ||
{ | ||
ControlFlow.Fail(errors.Join(Environment.NewLine)); | ||
} | ||
}); | ||
|
||
/// <summary> | ||
/// Get list of VirtoCommerce packages (platform and module) | ||
/// </summary> | ||
private IEnumerable<PackageItem> GetProjectPackages(Project project) | ||
{ | ||
var msBuildProject = project.GetMSBuildProject(); | ||
|
||
// find all VirtoCommerce references | ||
return msBuildProject.Items | ||
.Where(x => x.ItemType == "PackageReference" | ||
&& (x.EvaluatedInclude.StartsWith("VirtoCommerce.Platform.") || _moduleNameRegEx.IsMatch(x.EvaluatedInclude))) | ||
.Select(x => | ||
{ | ||
var versionMetadata = x.Metadata.FirstOrDefault(x => x.Name == "Version"); | ||
if (versionMetadata == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var name = x.EvaluatedInclude; | ||
|
||
return new PackageItem | ||
{ | ||
Name = name, | ||
Version = versionMetadata.EvaluatedValue, | ||
ProjectName = project.Name, | ||
IsPlatformPackage = name.StartsWith("VirtoCommerce.Platform.") | ||
}; | ||
}) | ||
.Where(x => x != null); | ||
} | ||
|
||
/// <summary> | ||
/// Check match between manifest platform version and platform packages | ||
/// </summary> | ||
private IEnumerable<string> ValdatePlatformVersion(IEnumerable<PackageItem> packages) | ||
{ | ||
return packages | ||
.Where(package => package.IsPlatformPackage && SemanticVersion.Parse(package.Version) != SemanticVersion.Parse(ModuleManifest.PlatformVersion)) | ||
.Select(x => | ||
$"Mismatched platform dependency version found. Platform version: {ModuleManifest.PlatformVersion}, Platform package name: {x.Name}, platform package version: {x.Version}, project name: {x.ProjectName}"); | ||
} | ||
|
||
/// <summary> | ||
/// Check dependencies for module packages versions mismatch | ||
/// </summary> | ||
private IEnumerable<string> ValidateModuleDependenciesVersions(IEnumerable<PackageItem> packages) | ||
{ | ||
var result = new List<string>(); | ||
|
||
if (ModuleManifest.Dependencies.IsNullOrEmpty()) | ||
{ | ||
return result; | ||
} | ||
|
||
foreach (var dependency in ModuleManifest.Dependencies) | ||
{ | ||
var errors = packages | ||
.Where(package => !package.IsPlatformPackage | ||
&& HasNameMatch(package.Name, dependency.Id) | ||
&& SemanticVersion.Parse(package.Version) != SemanticVersion.Parse(dependency.Version)) | ||
.Select(package => | ||
$"Mismatched dependency version found. Dependency: {dependency.Id}, version: {dependency.Version}, Project package version: {package.Version}, project name: {package.ProjectName}"); | ||
|
||
result.AddRange(errors); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Check project packages for missed dependency in manifest | ||
/// </summary> | ||
private IEnumerable<string> ValidateForMissedDependencies(IEnumerable<PackageItem> packages) | ||
{ | ||
var result = new List<string>(); | ||
|
||
if (ModuleManifest.Dependencies.IsNullOrEmpty()) | ||
{ | ||
return result; | ||
} | ||
|
||
foreach (var packageGroup in packages.Where(x => !x.IsPlatformPackage).GroupBy(x => x.Name)) | ||
{ | ||
if (!ModuleManifest.Dependencies.Any(dependency => HasNameMatch(packageGroup.Key, dependency.Id))) | ||
{ | ||
result.Add($"Dependency in module.manifest is missing. Package name: {packageGroup.Key}"); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private bool HasNameMatch(string packageName, string dependencyName) | ||
{ | ||
var match = _moduleNameRegEx.Match(packageName); | ||
return match.Groups.Values.Any(x => x.Value == dependencyName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace PlatformTools | ||
{ | ||
internal class PackageItem | ||
{ | ||
public string Name { get; set; } | ||
|
||
public string ProjectName { get; set; } | ||
|
||
public string Version { get; set; } | ||
|
||
/// <summary> | ||
/// Whether or not the package is a module package or a platfrom package | ||
/// </summary> | ||
public bool IsPlatformPackage { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters