Skip to content

[Helix] Install aspnet runtime as part of test runner #20693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions eng/helix/content/InstallAppRuntime.ps1

This file was deleted.

40 changes: 0 additions & 40 deletions eng/helix/content/InstallAspNetRef.ps1

This file was deleted.

4 changes: 4 additions & 0 deletions eng/helix/content/RunTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ static async Task Main(string[] args)
{
keepGoing = await runner.InstallAspNetAppIfNeededAsync();
}
if (keepGoing)
{
keepGoing = runner.InstallAspNetRefIfNeeded();
}

runner.DisplayContents();

Expand Down
14 changes: 14 additions & 0 deletions eng/helix/content/RunTests/RunTestsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public static RunTestsOptions Parse(string[] args)
aliases: new string[] { "--ef" },
description: "The version of the EF tool to use")
{ Argument = new Argument<string>(), Required = true },

new Option(
aliases: new string[] { "--aspnetruntime" },
description: "The path to the aspnet runtime nupkg to install")
{ Argument = new Argument<string>(), Required = true },

new Option(
aliases: new string[] { "--aspnetref" },
description: "The path to the aspnet ref nupkg to install")
{ Argument = new Argument<string>(), Required = true },
};

var parseResult = command.Parse(args);
Expand All @@ -61,6 +71,8 @@ public static RunTestsOptions Parse(string[] args)
options.Architecture = parseResult.ValueForOption<string>("--arch");
options.Quarantined = parseResult.ValueForOption<bool>("--quarantined");
options.EfVersion = parseResult.ValueForOption<string>("--ef");
options.AspNetRuntime = parseResult.ValueForOption<string>("--aspnetruntime");
options.AspNetRef = parseResult.ValueForOption<string>("--aspnetref");
options.HELIX_WORKITEM_ROOT = Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT");
options.Path = Environment.GetEnvironmentVariable("PATH");
options.DotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT");
Expand All @@ -70,6 +82,8 @@ public static RunTestsOptions Parse(string[] args)
public string Target { get; set;}
public string SdkVersion { get; set;}
public string RuntimeVersion { get; set;}
public string AspNetRuntime { get; set;}
public string AspNetRef { get; set;}
public string HelixQueue { get; set;}
public string Architecture { get; set;}
public bool Quarantined { get; set;}
Expand Down
46 changes: 40 additions & 6 deletions eng/helix/content/RunTests/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.CommandLine;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

Expand Down Expand Up @@ -91,18 +92,26 @@ public async Task<bool> InstallAspNetAppIfNeededAsync()
{
try
{
Console.WriteLine("Checking for Microsoft.AspNetCore.App/");
if (Directory.Exists("Microsoft.AspNetCore.App"))
if (File.Exists(Options.AspNetRuntime))
{
var appRuntimePath = $"{Options.DotnetRoot}/shared/Microsoft.AspNetCore.App/{Options.RuntimeVersion}";
Console.WriteLine($"Creating directory: {appRuntimePath}");
Directory.CreateDirectory(appRuntimePath);
Console.WriteLine($"Found Microsoft.AspNetCore.App/, copying to {appRuntimePath}");
Console.WriteLine($"Set ASPNET_RUNTIME_PATH: {appRuntimePath}");
EnvironmentVariables.Add("ASPNET_RUNTIME_PATH", appRuntimePath);
foreach (var file in Directory.EnumerateFiles("Microsoft.AspNetCore.App", "*.*", SearchOption.AllDirectories))
Console.WriteLine($"Found AspNetRuntime: {Options.AspNetRuntime}, extracting *.txt,json,dll to {appRuntimePath}");
using (var archive = ZipFile.OpenRead(Options.AspNetRuntime))
{
File.Copy(file, Path.Combine(appRuntimePath, Path.GetFileName(file)), overwrite: true);
foreach (var entry in archive.Entries)
{
// These are the only extensions that end up in the shared fx directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it important to filter based on extension?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just flatten and dump all the files I guess, I mostly was just trying to mimic what the final contents of the shared framework directory has. There's a bunch of other metadata in other folders that aren't really relevant. This was a little cleaner than filtering for relative paths since we'd have to build those based on target framework and other things

if (entry.Name.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) ||
entry.Name.EndsWith(".json", StringComparison.OrdinalIgnoreCase) ||
entry.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
{
entry.ExtractToFile(Path.Combine(appRuntimePath, entry.Name));
}
}
}

DisplayContents(appRuntimePath);
Expand Down Expand Up @@ -135,7 +144,7 @@ await ProcessUtil.RunAsync($"{Options.DotnetRoot}/dotnet",
}
else
{
Console.WriteLine($"No app runtime found, skipping...");
Console.WriteLine($"No AspNetRuntime found: {Options.AspNetRuntime}, skipping...");
}
return true;
}
Expand All @@ -146,6 +155,31 @@ await ProcessUtil.RunAsync($"{Options.DotnetRoot}/dotnet",
}
}

public bool InstallAspNetRefIfNeeded()
{
try
{
if (File.Exists(Options.AspNetRef))
{
var refPath = $"Microsoft.AspNetCore.App.Ref";
Console.WriteLine($"Found AspNetRef: {Options.AspNetRef}, extracting to {refPath}");
ZipFile.ExtractToDirectory(Options.AspNetRef, "Microsoft.AspNetCore.App.Ref");

DisplayContents(refPath);
}
else
{
Console.WriteLine($"No AspNetRef found: {Options.AspNetRef}, skipping...");
}
return true;
}
catch (Exception e)
{
Console.WriteLine($"Exception in InstallAspNetRefIfNeeded: {e.ToString()}");
return false;
}
}

public async Task<bool> CheckTestDiscoveryAsync()
{
try
Expand Down
21 changes: 0 additions & 21 deletions eng/helix/content/installappruntime.sh

This file was deleted.

15 changes: 0 additions & 15 deletions eng/helix/content/installaspnetref.sh

This file was deleted.

6 changes: 3 additions & 3 deletions eng/helix/content/runtests.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ echo "Installing Runtime"
powershell.exe -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'))) -Architecture %$arch% -Runtime dotnet -Version %$runtimeVersion% -InstallDir %DOTNET_ROOT%"

set exit_code=0
echo "Restore for RunTests..."
echo "Restore: dotnet restore RunTests\RunTests.csproj --source https://api.nuget.org/v3/index.json --ignore-failed-sources..."
dotnet restore RunTests\RunTests.csproj --source https://api.nuget.org/v3/index.json --ignore-failed-sources
echo "Running tests..."
dotnet run --project RunTests\RunTests.csproj -- --target %1 --sdk %2 --runtime %3 --queue %4 --arch %5 --quarantined %6 --ef %7
echo "Running tests: dotnet run --project RunTests\RunTests.csproj -- --target %1 --sdk %2 --runtime %3 --queue %4 --arch %5 --quarantined %6 --ef %7 --aspnetruntime %8 --aspnetref %9..."
dotnet run --project RunTests\RunTests.csproj -- --target %1 --sdk %2 --runtime %3 --queue %4 --arch %5 --quarantined %6 --ef %7 --aspnetruntime %8 --aspnetref %9
if errorlevel 1 (
set exit_code=1
)
Expand Down
6 changes: 3 additions & 3 deletions eng/helix/content/runtests.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ fi
sync

exit_code=0
echo "Restore for RunTests..."
echo "Restore: $DOTNET_ROOT/dotnet restore RunTests/RunTests.csproj --source https://api.nuget.org/v3/index.json --ignore-failed-sources..."
$DOTNET_ROOT/dotnet restore RunTests/RunTests.csproj --source https://api.nuget.org/v3/index.json --ignore-failed-sources
echo "Running tests..."
$DOTNET_ROOT/dotnet run --project RunTests/RunTests.csproj -- --target $1 --sdk $2 --runtime $3 --queue $4 --arch $5 --quarantined $6 --ef $7
echo "Running tests: $DOTNET_ROOT/dotnet run --project RunTests/RunTests.csproj -- --target $1 --sdk $2 --runtime $3 --queue $4 --arch $5 --quarantined $6 --ef $7 --aspnetruntime $8 --aspnetref $9..."
$DOTNET_ROOT/dotnet run --project RunTests/RunTests.csproj -- --target $1 --sdk $2 --runtime $3 --queue $4 --arch $5 --quarantined $6 --ef $7 --aspnetruntime $8 --aspnetref $9
exit_code=$?
echo "Finished tests...exit_code=$exit_code"
exit $exit_code
23 changes: 4 additions & 19 deletions eng/targets/Helix.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,8 @@
<HelixPreCommand Include="call RunPowershell.cmd InstallNode.ps1 $(NodeVersion) %25HELIX_CORRELATION_PAYLOAD%25\node\bin || exit /b 1" />
</ItemGroup>

<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(IsWindowsHelixQueue)' == 'true' AND '$(TestDependsOnAspNetRef)' == 'true' AND '$(IsTargetingPackBuilding)' == 'true'">
<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(TestDependsOnAspNetRef)' == 'true' AND '$(IsTargetingPackBuilding)' == 'true'">
<HelixContent Include="$(RepoRoot)artifacts\packages\Release\Shipping\Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg" />
<HelixPreCommand Include="call RunPowershell.cmd InstallAspNetRef.ps1 Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg Microsoft.AspNetCore.App.Ref || exit /b 1" />
</ItemGroup>

<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(IsWindowsHelixQueue)' == 'false' AND '$(TestDependsOnAspNetRef)' == 'true' AND '$(IsTargetingPackBuilding)' == 'true'">
<HelixContent Include="$(RepoRoot)artifacts\packages\Release\Shipping\Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg" />
<HelixPreCommand Include="./installaspnetref.sh Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg Microsoft.AspNetCore.App.Ref || exit /b 1" />
</ItemGroup>

<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(IsWindowsHelixQueue)' == 'true' AND '$(TestDependsOnAspNetRuntime)' == 'true'">
<HelixContent Include="$(RepoRoot)artifacts\packages\Release\Shipping\Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg" />
<HelixPreCommand Include="call RunPowershell.cmd InstallAppRuntime.ps1 Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg Microsoft.AspNetCore.App netcoreapp5.0 win-x64 || exit /b 1" />
</ItemGroup>

<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(IsWindowsHelixQueue)' == 'false' AND '$(TestDependsOnAspNetRuntime)' == 'true'">
<HelixContent Include="$(RepoRoot)artifacts\packages\Release\Shipping\Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg" />
<HelixPreCommand Include="./installappruntime.sh Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg Microsoft.AspNetCore.App netcoreapp5.0 win-x64" />
</ItemGroup>

<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(TestDependsOnAspNetRuntime)' == 'true'">
Expand Down Expand Up @@ -109,6 +93,7 @@ Usage: dotnet msbuild /t:Helix src/MyTestProject.csproj
<ItemGroup>
<HelixContent Include="$(OutputPath)/Microsoft.VisualStudio.TestPlatform.Extension.Xunit.Xml.TestAdapter.dll" />
<HelixContent Include="$(OutputPath)/Microsoft.VisualStudio.TestPlatform.Extension.Xunit.Xml.TestLogger.dll" />
<HelixContent Condition="'$(TestDependsOnAspNetRuntime)' == 'true'" Include="$(RepoRoot)artifacts\packages\Release\Shipping\Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg" />
</ItemGroup>

<PropertyGroup>
Expand All @@ -130,8 +115,8 @@ Usage: dotnet msbuild /t:Helix src/MyTestProject.csproj
<TestAssembly>$(TargetFileName)</TestAssembly>
<PreCommands>@(HelixPreCommand)</PreCommands>
<PostCommands>@(HelixPostCommand)</PostCommands>
<Command Condition="$(IsWindowsHelixQueue)">call runtests.cmd $(TargetFileName) $(NETCoreSdkVersion) $(MicrosoftNETCoreAppRuntimeVersion) $(_HelixFriendlyNameTargetQueue) $(TargetArchitecture) $(RunQuarantinedTests) $(DotnetEfPackageVersion)</Command>
<Command Condition="!$(IsWindowsHelixQueue)">./runtests.sh $(TargetFileName) $(NETCoreSdkVersion) $(MicrosoftNETCoreAppRuntimeVersion) $(_HelixFriendlyNameTargetQueue) $(TargetArchitecture) $(RunQuarantinedTests) $(DotnetEfPackageVersion)</Command>
<Command Condition="$(IsWindowsHelixQueue)">call runtests.cmd $(TargetFileName) $(NETCoreSdkVersion) $(MicrosoftNETCoreAppRuntimeVersion) $(_HelixFriendlyNameTargetQueue) $(TargetArchitecture) $(RunQuarantinedTests) $(DotnetEfPackageVersion) Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg</Command>
<Command Condition="!$(IsWindowsHelixQueue)">./runtests.sh $(TargetFileName) $(NETCoreSdkVersion) $(MicrosoftNETCoreAppRuntimeVersion) $(_HelixFriendlyNameTargetQueue) $(TargetArchitecture) $(RunQuarantinedTests) $(DotnetEfPackageVersion) Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg</Command>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we passing a windows nupkg to Unix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long term we still need to do the work to build all the appropriate shared frameworks and match them to the appropriate helix queues, but today the tests only use managed code so it doesn't seem to matter (yet?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue basically: #11128

<Command Condition="$(HelixCommand) != ''">$(HelixCommand)</Command>
<Timeout>$(HelixTimeout)</Timeout>
</HelixWorkItem>
Expand Down