[Templates] Capture binlogs on failed build and publish template tests (#14108)

This commit is contained in:
Javier Calvarro Nelson 2019-09-18 20:23:56 +02:00 committed by GitHub
parent 3c324d17bf
commit baaaf68250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@ -27,6 +26,9 @@ namespace Templates.Test.Helpers
public static bool IsCIEnvironment => typeof(Project).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
.Any(a => a.Key == "ContinuousIntegrationBuild");
public static string ArtifactsLogDir => typeof(Project).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
.Single(a => a.Key == "ArtifactsLogDir")?.Value;
public SemaphoreSlim DotNetNewLock { get; set; }
public SemaphoreSlim NodeLock { get; set; }
public string ProjectName { get; set; }
@ -112,11 +114,6 @@ namespace Templates.Test.Helpers
{
Output.WriteLine("Publishing ASP.NET application...");
// Workaround for issue with runtime store not yet being published
// https://github.com/aspnet/Home/issues/2254#issuecomment-339709628
var extraArgs = "-p:PublishWithAspNetCoreTargetManifest=false";
// This is going to trigger a build, so we need to acquire the lock like in the other cases.
// We want to take the node lock as some builds run NPM as part of the build and we want to make sure
// it's run without interruptions.
@ -124,8 +121,9 @@ namespace Templates.Test.Helpers
await effectiveLock.WaitAsync();
try
{
var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish -c Release {extraArgs}", packageOptions);
var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish -c Release /bl", packageOptions);
await result.Exited;
CaptureBinLogOnFailure(result);
return result;
}
finally
@ -145,8 +143,9 @@ namespace Templates.Test.Helpers
await effectiveLock.WaitAsync();
try
{
var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), "build -c Debug", packageOptions);
var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), "build -c Debug /bl", packageOptions);
await result.Exited;
CaptureBinLogOnFailure(result);
return result;
}
finally
@ -507,6 +506,17 @@ namespace Templates.Test.Helpers
}
}
private void CaptureBinLogOnFailure(ProcessEx result)
{
if (result.ExitCode != 0 && !string.IsNullOrEmpty(ArtifactsLogDir))
{
var sourceFile = Path.Combine(TemplateOutputDir, "msbuild.binlog");
Assert.True(File.Exists(sourceFile), $"Log for '{ProjectName}' not found in '{sourceFile}'.");
var destination = Path.Combine(ArtifactsLogDir, ProjectName + ".binlog");
File.Move(sourceFile, destination);
}
}
public override string ToString() => $"{ProjectName}: {TemplateOutputDir}";
}
}

View File

@ -75,6 +75,11 @@
<_Parameter2>$(ArtifactsShippingPackagesDir)</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>ArtifactsLogDir</_Parameter1>
<_Parameter2>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'log'))</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>ArtifactsNonShippingPackagesDir</_Parameter1>
<_Parameter2>$(ArtifactsNonShippingPackagesDir)</_Parameter2>