HelixTestRunnerOptions.cs 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. using System;
  4. using System.Collections.Generic;
  5. using System.CommandLine;
  6. using System.Globalization;
  7. using System.IO;
  8. using System.Runtime.InteropServices;
  9. using System.Threading.Tasks;
  10. namespace HelixTestRunner;
  11. public class HelixTestRunnerOptions
  12. {
  13. public static HelixTestRunnerOptions Parse(string[] args)
  14. {
  15. var command = new RootCommand()
  16. {
  17. new Option(
  18. aliases: new string[] { "--target", "-t" },
  19. description: "The test dll to run")
  20. { Argument = new Argument<string>(), Required = true },
  21. new Option(
  22. aliases: new string[] { "--runtime" },
  23. description: "The version of the ASP.NET runtime being installed and used")
  24. { Argument = new Argument<string>(), Required = true },
  25. new Option(
  26. aliases: new string[] { "--queue" },
  27. description: "The name of the Helix queue being run on")
  28. { Argument = new Argument<string>(), Required = true },
  29. new Option(
  30. aliases: new string[] { "--arch" },
  31. description: "The architecture being run on")
  32. { Argument = new Argument<string>(), Required = true },
  33. new Option(
  34. aliases: new string[] { "--playwright" },
  35. description: "Whether to install Microsoft.Playwright browsers or not")
  36. { Argument = new Argument<bool>(), Required = true },
  37. new Option(
  38. aliases: new string[] { "--quarantined" },
  39. description: "Whether quarantined tests should run or not")
  40. { Argument = new Argument<bool>(), Required = true },
  41. new Option(
  42. aliases: new string[] { "--helixTimeout" },
  43. description: "The timeout duration of the Helix job")
  44. { Argument = new Argument<string>(), Required = true },
  45. new Option(
  46. aliases: new string[] { "--source" },
  47. description: "The restore sources to use during testing")
  48. { Argument = new Argument<string>() { Arity = ArgumentArity.ZeroOrMore }, Required = true }
  49. };
  50. var parseResult = command.Parse(args);
  51. var sharedFxVersion = parseResult.ValueForOption<string>("--runtime");
  52. var options = new HelixTestRunnerOptions
  53. {
  54. Architecture = parseResult.ValueForOption<string>("--arch"),
  55. HelixQueue = parseResult.ValueForOption<string>("--queue"),
  56. InstallPlaywright = parseResult.ValueForOption<bool>("--playwright"),
  57. Quarantined = parseResult.ValueForOption<bool>("--quarantined"),
  58. RuntimeVersion = sharedFxVersion,
  59. Target = parseResult.ValueForOption<string>("--target"),
  60. Timeout = TimeSpan.Parse(parseResult.ValueForOption<string>("--helixTimeout"), CultureInfo.InvariantCulture),
  61. // When targeting pack builds, it has exactly the same version as the shared framework.
  62. AspNetRef = $"Microsoft.AspNetCore.App.Ref.{sharedFxVersion}.nupkg",
  63. AspNetRuntime = $"Microsoft.AspNetCore.App.Runtime.win-x64.{sharedFxVersion}.nupkg",
  64. DotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT"),
  65. HELIX_WORKITEM_ROOT = Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT"),
  66. Path = Environment.GetEnvironmentVariable("PATH"),
  67. };
  68. return options;
  69. }
  70. public string Architecture { get; private set; }
  71. public string HelixQueue { get; private set; }
  72. public bool InstallPlaywright { get; private set; }
  73. public bool Quarantined { get; private set; }
  74. public string RuntimeVersion { get; private set; }
  75. public string Target { get; private set; }
  76. public TimeSpan Timeout { get; private set; }
  77. public string AspNetRef { get; private set; }
  78. public string AspNetRuntime { get; private set; }
  79. public string HELIX_WORKITEM_ROOT { get; private set; }
  80. public string DotnetRoot { get; private set; }
  81. public string Path { get; set; }
  82. }