Skip to content

Commit c16d336

Browse files
authored
[Helix] Install aspnet runtime as part of test runner (#20693)
1 parent 51f69a6 commit c16d336

File tree

10 files changed

+68
-160
lines changed

10 files changed

+68
-160
lines changed

eng/helix/content/InstallAppRuntime.ps1

Lines changed: 0 additions & 53 deletions
This file was deleted.

eng/helix/content/InstallAspNetRef.ps1

Lines changed: 0 additions & 40 deletions
This file was deleted.

eng/helix/content/RunTests/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ static async Task Main(string[] args)
2323
{
2424
keepGoing = await runner.InstallAspNetAppIfNeededAsync();
2525
}
26+
if (keepGoing)
27+
{
28+
keepGoing = runner.InstallAspNetRefIfNeeded();
29+
}
2630

2731
runner.DisplayContents();
2832

eng/helix/content/RunTests/RunTestsOptions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public static RunTestsOptions Parse(string[] args)
5050
aliases: new string[] { "--ef" },
5151
description: "The version of the EF tool to use")
5252
{ Argument = new Argument<string>(), Required = true },
53+
54+
new Option(
55+
aliases: new string[] { "--aspnetruntime" },
56+
description: "The path to the aspnet runtime nupkg to install")
57+
{ Argument = new Argument<string>(), Required = true },
58+
59+
new Option(
60+
aliases: new string[] { "--aspnetref" },
61+
description: "The path to the aspnet ref nupkg to install")
62+
{ Argument = new Argument<string>(), Required = true },
5363
};
5464

5565
var parseResult = command.Parse(args);
@@ -61,6 +71,8 @@ public static RunTestsOptions Parse(string[] args)
6171
options.Architecture = parseResult.ValueForOption<string>("--arch");
6272
options.Quarantined = parseResult.ValueForOption<bool>("--quarantined");
6373
options.EfVersion = parseResult.ValueForOption<string>("--ef");
74+
options.AspNetRuntime = parseResult.ValueForOption<string>("--aspnetruntime");
75+
options.AspNetRef = parseResult.ValueForOption<string>("--aspnetref");
6476
options.HELIX_WORKITEM_ROOT = Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT");
6577
options.Path = Environment.GetEnvironmentVariable("PATH");
6678
options.DotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT");
@@ -70,6 +82,8 @@ public static RunTestsOptions Parse(string[] args)
7082
public string Target { get; set;}
7183
public string SdkVersion { get; set;}
7284
public string RuntimeVersion { get; set;}
85+
public string AspNetRuntime { get; set;}
86+
public string AspNetRef { get; set;}
7387
public string HelixQueue { get; set;}
7488
public string Architecture { get; set;}
7589
public bool Quarantined { get; set;}

eng/helix/content/RunTests/TestRunner.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.CommandLine;
77
using System.IO;
8+
using System.IO.Compression;
89
using System.Runtime.InteropServices;
910
using System.Threading.Tasks;
1011

@@ -91,18 +92,26 @@ public async Task<bool> InstallAspNetAppIfNeededAsync()
9192
{
9293
try
9394
{
94-
Console.WriteLine("Checking for Microsoft.AspNetCore.App/");
95-
if (Directory.Exists("Microsoft.AspNetCore.App"))
95+
if (File.Exists(Options.AspNetRuntime))
9696
{
9797
var appRuntimePath = $"{Options.DotnetRoot}/shared/Microsoft.AspNetCore.App/{Options.RuntimeVersion}";
9898
Console.WriteLine($"Creating directory: {appRuntimePath}");
9999
Directory.CreateDirectory(appRuntimePath);
100-
Console.WriteLine($"Found Microsoft.AspNetCore.App/, copying to {appRuntimePath}");
101100
Console.WriteLine($"Set ASPNET_RUNTIME_PATH: {appRuntimePath}");
102101
EnvironmentVariables.Add("ASPNET_RUNTIME_PATH", appRuntimePath);
103-
foreach (var file in Directory.EnumerateFiles("Microsoft.AspNetCore.App", "*.*", SearchOption.AllDirectories))
102+
Console.WriteLine($"Found AspNetRuntime: {Options.AspNetRuntime}, extracting *.txt,json,dll to {appRuntimePath}");
103+
using (var archive = ZipFile.OpenRead(Options.AspNetRuntime))
104104
{
105-
File.Copy(file, Path.Combine(appRuntimePath, Path.GetFileName(file)), overwrite: true);
105+
foreach (var entry in archive.Entries)
106+
{
107+
// These are the only extensions that end up in the shared fx directory
108+
if (entry.Name.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) ||
109+
entry.Name.EndsWith(".json", StringComparison.OrdinalIgnoreCase) ||
110+
entry.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
111+
{
112+
entry.ExtractToFile(Path.Combine(appRuntimePath, entry.Name));
113+
}
114+
}
106115
}
107116

108117
DisplayContents(appRuntimePath);
@@ -135,7 +144,7 @@ await ProcessUtil.RunAsync($"{Options.DotnetRoot}/dotnet",
135144
}
136145
else
137146
{
138-
Console.WriteLine($"No app runtime found, skipping...");
147+
Console.WriteLine($"No AspNetRuntime found: {Options.AspNetRuntime}, skipping...");
139148
}
140149
return true;
141150
}
@@ -146,6 +155,31 @@ await ProcessUtil.RunAsync($"{Options.DotnetRoot}/dotnet",
146155
}
147156
}
148157

158+
public bool InstallAspNetRefIfNeeded()
159+
{
160+
try
161+
{
162+
if (File.Exists(Options.AspNetRef))
163+
{
164+
var refPath = $"Microsoft.AspNetCore.App.Ref";
165+
Console.WriteLine($"Found AspNetRef: {Options.AspNetRef}, extracting to {refPath}");
166+
ZipFile.ExtractToDirectory(Options.AspNetRef, "Microsoft.AspNetCore.App.Ref");
167+
168+
DisplayContents(refPath);
169+
}
170+
else
171+
{
172+
Console.WriteLine($"No AspNetRef found: {Options.AspNetRef}, skipping...");
173+
}
174+
return true;
175+
}
176+
catch (Exception e)
177+
{
178+
Console.WriteLine($"Exception in InstallAspNetRefIfNeeded: {e.ToString()}");
179+
return false;
180+
}
181+
}
182+
149183
public async Task<bool> CheckTestDiscoveryAsync()
150184
{
151185
try

eng/helix/content/installappruntime.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

eng/helix/content/installaspnetref.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

eng/helix/content/runtests.cmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ echo "Installing Runtime"
2121
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%"
2222

2323
set exit_code=0
24-
echo "Restore for RunTests..."
24+
echo "Restore: dotnet restore RunTests\RunTests.csproj --source https://api.nuget.org/v3/index.json --ignore-failed-sources..."
2525
dotnet restore RunTests\RunTests.csproj --source https://api.nuget.org/v3/index.json --ignore-failed-sources
26-
echo "Running tests..."
27-
dotnet run --project RunTests\RunTests.csproj -- --target %1 --sdk %2 --runtime %3 --queue %4 --arch %5 --quarantined %6 --ef %7
26+
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..."
27+
dotnet run --project RunTests\RunTests.csproj -- --target %1 --sdk %2 --runtime %3 --queue %4 --arch %5 --quarantined %6 --ef %7 --aspnetruntime %8 --aspnetref %9
2828
if errorlevel 1 (
2929
set exit_code=1
3030
)

eng/helix/content/runtests.sh

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ fi
8686
sync
8787

8888
exit_code=0
89-
echo "Restore for RunTests..."
89+
echo "Restore: $DOTNET_ROOT/dotnet restore RunTests/RunTests.csproj --source https://api.nuget.org/v3/index.json --ignore-failed-sources..."
9090
$DOTNET_ROOT/dotnet restore RunTests/RunTests.csproj --source https://api.nuget.org/v3/index.json --ignore-failed-sources
91-
echo "Running tests..."
92-
$DOTNET_ROOT/dotnet run --project RunTests/RunTests.csproj -- --target $1 --sdk $2 --runtime $3 --queue $4 --arch $5 --quarantined $6 --ef $7
91+
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..."
92+
$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
9393
exit_code=$?
9494
echo "Finished tests...exit_code=$exit_code"
9595
exit $exit_code

eng/targets/Helix.targets

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,8 @@
1616
<HelixPreCommand Include="call RunPowershell.cmd InstallNode.ps1 $(NodeVersion) %25HELIX_CORRELATION_PAYLOAD%25\node\bin || exit /b 1" />
1717
</ItemGroup>
1818

19-
<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(IsWindowsHelixQueue)' == 'true' AND '$(TestDependsOnAspNetRef)' == 'true' AND '$(IsTargetingPackBuilding)' == 'true'">
19+
<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(TestDependsOnAspNetRef)' == 'true' AND '$(IsTargetingPackBuilding)' == 'true'">
2020
<HelixContent Include="$(RepoRoot)artifacts\packages\Release\Shipping\Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg" />
21-
<HelixPreCommand Include="call RunPowershell.cmd InstallAspNetRef.ps1 Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg Microsoft.AspNetCore.App.Ref || exit /b 1" />
22-
</ItemGroup>
23-
24-
<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(IsWindowsHelixQueue)' == 'false' AND '$(TestDependsOnAspNetRef)' == 'true' AND '$(IsTargetingPackBuilding)' == 'true'">
25-
<HelixContent Include="$(RepoRoot)artifacts\packages\Release\Shipping\Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg" />
26-
<HelixPreCommand Include="./installaspnetref.sh Microsoft.AspNetCore.App.Ref.$(AppRuntimeVersion).nupkg Microsoft.AspNetCore.App.Ref || exit /b 1" />
27-
</ItemGroup>
28-
29-
<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(IsWindowsHelixQueue)' == 'true' AND '$(TestDependsOnAspNetRuntime)' == 'true'">
30-
<HelixContent Include="$(RepoRoot)artifacts\packages\Release\Shipping\Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg" />
31-
<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" />
32-
</ItemGroup>
33-
34-
<ItemGroup Condition="'$(IsHelixJob)' == 'true' AND '$(IsWindowsHelixQueue)' == 'false' AND '$(TestDependsOnAspNetRuntime)' == 'true'">
35-
<HelixContent Include="$(RepoRoot)artifacts\packages\Release\Shipping\Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg" />
36-
<HelixPreCommand Include="./installappruntime.sh Microsoft.AspNetCore.App.Runtime.win-x64.$(AppRuntimeVersion).nupkg Microsoft.AspNetCore.App netcoreapp5.0 win-x64" />
3721
</ItemGroup>
3822

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

11499
<PropertyGroup>
@@ -130,8 +115,8 @@ Usage: dotnet msbuild /t:Helix src/MyTestProject.csproj
130115
<TestAssembly>$(TargetFileName)</TestAssembly>
131116
<PreCommands>@(HelixPreCommand)</PreCommands>
132117
<PostCommands>@(HelixPostCommand)</PostCommands>
133-
<Command Condition="$(IsWindowsHelixQueue)">call runtests.cmd $(TargetFileName) $(NETCoreSdkVersion) $(MicrosoftNETCoreAppRuntimeVersion) $(_HelixFriendlyNameTargetQueue) $(TargetArchitecture) $(RunQuarantinedTests) $(DotnetEfPackageVersion)</Command>
134-
<Command Condition="!$(IsWindowsHelixQueue)">./runtests.sh $(TargetFileName) $(NETCoreSdkVersion) $(MicrosoftNETCoreAppRuntimeVersion) $(_HelixFriendlyNameTargetQueue) $(TargetArchitecture) $(RunQuarantinedTests) $(DotnetEfPackageVersion)</Command>
118+
<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>
119+
<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>
135120
<Command Condition="$(HelixCommand) != ''">$(HelixCommand)</Command>
136121
<Timeout>$(HelixTimeout)</Timeout>
137122
</HelixWorkItem>

0 commit comments

Comments
 (0)