// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using System.Collections.Generic; using System.CommandLine; using System.Globalization; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; namespace HelixTestRunner; public class HelixTestRunnerOptions { public static HelixTestRunnerOptions Parse(string[] args) { var command = new RootCommand() { new Option( aliases: new string[] { "--target", "-t" }, description: "The test dll to run") { Argument = new Argument(), Required = true }, new Option( aliases: new string[] { "--runtime" }, description: "The version of the ASP.NET runtime being installed and used") { Argument = new Argument(), Required = true }, new Option( aliases: new string[] { "--queue" }, description: "The name of the Helix queue being run on") { Argument = new Argument(), Required = true }, new Option( aliases: new string[] { "--arch" }, description: "The architecture being run on") { Argument = new Argument(), Required = true }, new Option( aliases: new string[] { "--playwright" }, description: "Whether to install Microsoft.Playwright browsers or not") { Argument = new Argument(), Required = true }, new Option( aliases: new string[] { "--quarantined" }, description: "Whether quarantined tests should run or not") { Argument = new Argument(), Required = true }, new Option( aliases: new string[] { "--helixTimeout" }, description: "The timeout duration of the Helix job") { Argument = new Argument(), Required = true }, new Option( aliases: new string[] { "--source" }, description: "The restore sources to use during testing") { Argument = new Argument() { Arity = ArgumentArity.ZeroOrMore }, Required = true } }; var parseResult = command.Parse(args); var sharedFxVersion = parseResult.ValueForOption("--runtime"); var options = new HelixTestRunnerOptions { Architecture = parseResult.ValueForOption("--arch"), HelixQueue = parseResult.ValueForOption("--queue"), InstallPlaywright = parseResult.ValueForOption("--playwright"), Quarantined = parseResult.ValueForOption("--quarantined"), RuntimeVersion = sharedFxVersion, Target = parseResult.ValueForOption("--target"), Timeout = TimeSpan.Parse(parseResult.ValueForOption("--helixTimeout"), CultureInfo.InvariantCulture), // When targeting pack builds, it has exactly the same version as the shared framework. AspNetRef = $"Microsoft.AspNetCore.App.Ref.{sharedFxVersion}.nupkg", AspNetRuntime = $"Microsoft.AspNetCore.App.Runtime.win-x64.{sharedFxVersion}.nupkg", DotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT"), HELIX_WORKITEM_ROOT = Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT"), Path = Environment.GetEnvironmentVariable("PATH"), }; return options; } public string Architecture { get; private set; } public string HelixQueue { get; private set; } public bool InstallPlaywright { get; private set; } public bool Quarantined { get; private set; } public string RuntimeVersion { get; private set; } public string Target { get; private set; } public TimeSpan Timeout { get; private set; } public string AspNetRef { get; private set; } public string AspNetRuntime { get; private set; } public string HELIX_WORKITEM_ROOT { get; private set; } public string DotnetRoot { get; private set; } public string Path { get; set; } }