[Templates] Capture binlogs on failed build and publish template tests (#14108)
This commit is contained in:
parent
3c324d17bf
commit
baaaf68250
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
@ -27,6 +26,9 @@ namespace Templates.Test.Helpers
|
||||||
public static bool IsCIEnvironment => typeof(Project).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
|
public static bool IsCIEnvironment => typeof(Project).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||||
.Any(a => a.Key == "ContinuousIntegrationBuild");
|
.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 DotNetNewLock { get; set; }
|
||||||
public SemaphoreSlim NodeLock { get; set; }
|
public SemaphoreSlim NodeLock { get; set; }
|
||||||
public string ProjectName { get; set; }
|
public string ProjectName { get; set; }
|
||||||
|
|
@ -112,11 +114,6 @@ namespace Templates.Test.Helpers
|
||||||
{
|
{
|
||||||
Output.WriteLine("Publishing ASP.NET application...");
|
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.
|
// 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
|
// 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.
|
// it's run without interruptions.
|
||||||
|
|
@ -124,8 +121,9 @@ namespace Templates.Test.Helpers
|
||||||
await effectiveLock.WaitAsync();
|
await effectiveLock.WaitAsync();
|
||||||
try
|
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;
|
await result.Exited;
|
||||||
|
CaptureBinLogOnFailure(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
@ -145,8 +143,9 @@ namespace Templates.Test.Helpers
|
||||||
await effectiveLock.WaitAsync();
|
await effectiveLock.WaitAsync();
|
||||||
try
|
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;
|
await result.Exited;
|
||||||
|
CaptureBinLogOnFailure(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
finally
|
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}";
|
public override string ToString() => $"{ProjectName}: {TemplateOutputDir}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,11 @@
|
||||||
<_Parameter2>$(ArtifactsShippingPackagesDir)</_Parameter2>
|
<_Parameter2>$(ArtifactsShippingPackagesDir)</_Parameter2>
|
||||||
</AssemblyAttribute>
|
</AssemblyAttribute>
|
||||||
|
|
||||||
|
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
|
||||||
|
<_Parameter1>ArtifactsLogDir</_Parameter1>
|
||||||
|
<_Parameter2>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'log'))</_Parameter2>
|
||||||
|
</AssemblyAttribute>
|
||||||
|
|
||||||
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
|
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
|
||||||
<_Parameter1>ArtifactsNonShippingPackagesDir</_Parameter1>
|
<_Parameter1>ArtifactsNonShippingPackagesDir</_Parameter1>
|
||||||
<_Parameter2>$(ArtifactsNonShippingPackagesDir)</_Parameter2>
|
<_Parameter2>$(ArtifactsNonShippingPackagesDir)</_Parameter2>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue