Update analysis to account for non-shipping package references (samples, tests)

This commit is contained in:
Nate McMaster 2017-09-15 17:45:55 -07:00
parent 479e37d7cc
commit 7568441acc
2 changed files with 47 additions and 7 deletions

View File

@ -51,7 +51,7 @@
<Target Name="CloneRepositories" DependsOnTargets="_PrepareRepositories">
<ItemGroup>
<_CloneRepositories Include="@(Repository);@(VerifyRepository)" />
<_CloneRepositories Include="@(Repository);@(ShippedRepository)" />
<_CloneRepository Include="$(MSBuildProjectFullPath)">
<AdditionalProperties>
CloneRepository=%(_CloneRepositories.Identity);
@ -123,9 +123,19 @@
<Output TaskParameter="TargetOutputs" ItemName="Solution" />
</MSBuild>
<!--
Analyze what was shipped in these repos.
This is required so we can verify that cascading versions are consistent.
-->
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="GetArtifactInfo"
Properties="RepositoryRoot=$(_CloneRepositoryRoot)%(ShippedRepository.Identity)\;Configuration=$(Configuration);BuildNumber=$(BuildNumber);IsFinalBuild=true"
ContinueOnError="WarnAndContinue">
<Output TaskParameter="TargetOutputs" ItemName="ShippedArtifactInfo" />
</MSBuild>
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="ResolveSolutions"
Properties="RepositoryRoot=$(_CloneRepositoryRoot)%(VerifyRepository.Identity)\;Configuration=$(Configuration);BuildNumber=$(BuildNumber)"
Properties="RepositoryRoot=$(_CloneRepositoryRoot)%(ShippedRepository.Identity)\;Configuration=$(Configuration);BuildNumber=$(BuildNumber)"
ContinueOnError="WarnAndContinue">
<Output TaskParameter="TargetOutputs" ItemName="_NoBuildSolution" />
</MSBuild>
@ -143,6 +153,7 @@
<RepoTasks.AnalyzeBuildGraph
Solutions="@(Solution)"
Artifacts="@(ArtifactInfo)"
ShippedArtifacts="@(ShippedArtifactInfo)"
Properties="Configuration=$(Configuration);BuildNumber=$(BuildNumber)">
<Output TaskParameter="RepositoryBuildOrder" ItemName="RepositoryBuildOrder" />
</RepoTasks.AnalyzeBuildGraph>

View File

@ -31,6 +31,10 @@ namespace RepoTasks
[Required]
public ITaskItem[] Artifacts { get; set; }
// Artifacts that already shipped from repos
[Required]
public ITaskItem[] ShippedArtifacts { get; set; }
[Required]
public string Properties { get; set; }
@ -83,10 +87,17 @@ namespace RepoTasks
private void EnsureConsistentGraph(IEnumerable<ArtifactInfo.Package> packages, IEnumerable<SolutionInfo> solutions)
{
var shippedPackageMap = ShippedArtifacts
.Select(ArtifactInfo.Parse)
.OfType<ArtifactInfo.Package>()
.Where(p => !p.IsSymbolsArtifact)
.ToDictionary(p => p.PackageInfo.Id, p => p, StringComparer.OrdinalIgnoreCase);
// ensure versions cascade
var lookup = packages.ToDictionary(p => p.PackageInfo.Id, p => p, StringComparer.OrdinalIgnoreCase);
var buildPackageMap = packages.ToDictionary(p => p.PackageInfo.Id, p => p, StringComparer.OrdinalIgnoreCase);
var inconsistentVersions = new List<VersionMismatch>();
var reposThatShouldPatch = new HashSet<string>();
// holy crap, o^4
foreach (var sln in solutions)
@ -94,7 +105,7 @@ namespace RepoTasks
foreach (var tfm in proj.Frameworks)
foreach (var dependency in tfm.Dependencies)
{
if (!lookup.TryGetValue(dependency.Key, out var package)) continue;
if (!buildPackageMap.TryGetValue(dependency.Key, out var package)) continue;
var refVersion = VersionRange.Parse(dependency.Value.Version);
if (refVersion.IsFloating && refVersion.Float.Satisfies(package.PackageInfo.Version))
@ -102,6 +113,19 @@ namespace RepoTasks
else if (package.PackageInfo.Version.Equals(refVersion))
continue;
if (!sln.ShouldBuild)
{
if (!shippedPackageMap.TryGetValue(proj.PackageId, out _))
{
Log.LogMessage(MessageImportance.Normal, $"Detected inconsistent in a sample or test project {proj.FullPath}");
continue;
}
else
{
reposThatShouldPatch.Add(Path.GetFileName(Path.GetDirectoryName(sln.FullPath)));
}
}
inconsistentVersions.Add(new VersionMismatch
{
Solution = sln,
@ -119,13 +143,13 @@ namespace RepoTasks
sb.AppendLine($"Repos are inconsistent. The following projects have PackageReferences that should be updated");
foreach (var sln in inconsistentVersions.GroupBy(p => p.Solution.FullPath))
{
sb.AppendLine($" - {Path.GetFileName(sln.Key)}");
sb.Append(" - ").AppendLine(Path.GetFileName(sln.Key));
foreach (var proj in sln.GroupBy(p => p.Project.FullPath))
{
sb.AppendLine($" - {Path.GetFileName(proj.Key)}");
sb.Append(" - ").AppendLine(Path.GetFileName(proj.Key));
foreach (var m in proj)
{
sb.AppendLine($" - {m.PackageId}/{{{m.ActualVersion} => {m.ExpectedVersion}}}");
sb.AppendLine($" + {m.PackageId}/{{{m.ActualVersion} => {m.ExpectedVersion}}}");
}
}
}
@ -133,6 +157,11 @@ namespace RepoTasks
Log.LogMessage(MessageImportance.High, sb.ToString());
Log.LogError("Package versions are inconsistent. See build log for details.");
}
foreach (var repo in reposThatShouldPatch)
{
Log.LogError($"{repo} should not be a 'ShippedRepository'. Version changes in other repositories mean it should be patched to perserve cascading version upgrades.");
}
}
private ITaskItem[] GetRepositoryBuildOrder(IEnumerable<ArtifactInfo.Package> artifacts, IEnumerable<SolutionInfo> solutions)