From 32215aece66a31ac9be13a09aa6a9ac04f7acce3 Mon Sep 17 00:00:00 2001 From: Salman Chishti Date: Fri, 25 Jul 2025 15:53:51 +0000 Subject: [PATCH] undo change --- src/Runner.Common/Util/NodeUtil.cs | 111 +++++++---------------------- 1 file changed, 24 insertions(+), 87 deletions(-) diff --git a/src/Runner.Common/Util/NodeUtil.cs b/src/Runner.Common/Util/NodeUtil.cs index 903a42c43..2d66f895b 100644 --- a/src/Runner.Common/Util/NodeUtil.cs +++ b/src/Runner.Common/Util/NodeUtil.cs @@ -1,102 +1,39 @@ using System; -using System.Collections.Generic; -using GitHub.DistributedTask.WebApi; -using GitHub.Runner.Common.Util; -using Pipelines = GitHub.DistributedTask.Pipelines; -using GitHub.Runner.Common; -using GitHub.Runner.Sdk; +using System.Collections.ObjectModel; -namespace GitHub.Runner.Worker.Handlers +namespace GitHub.Runner.Common.Util { - [ServiceLocator(Default = typeof(HandlerFactory))] - public interface IHandlerFactory : IRunnerService + public static class NodeUtil { - IHandler Create( - IExecutionContext executionContext, - Pipelines.ActionStepDefinitionReference action, - IStepHost stepHost, - ActionExecutionData data, - Dictionary inputs, - Dictionary environment, - Variables runtimeVariables, - string actionDirectory, - List localActionContainerSetupSteps); - } - - public sealed class HandlerFactory : RunnerService, IHandlerFactory - { - public IHandler Create( - IExecutionContext executionContext, - Pipelines.ActionStepDefinitionReference action, - IStepHost stepHost, - ActionExecutionData data, - Dictionary inputs, - Dictionary environment, - Variables runtimeVariables, - string actionDirectory, - List localActionContainerSetupSteps) + private const string _defaultNodeVersion = "node20"; + public static readonly ReadOnlyCollection BuiltInNodeVersions = new(new[] { "node20" }); + public static string GetInternalNodeVersion() { - // Validate args. - Trace.Entering(); - ArgUtil.NotNull(executionContext, nameof(executionContext)); - ArgUtil.NotNull(stepHost, nameof(stepHost)); - ArgUtil.NotNull(data, nameof(data)); - ArgUtil.NotNull(inputs, nameof(inputs)); - ArgUtil.NotNull(environment, nameof(environment)); - ArgUtil.NotNull(runtimeVariables, nameof(runtimeVariables)); + var forcedInternalNodeVersion = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedInternalNodeVersion); + var isForcedInternalNodeVersion = !string.IsNullOrEmpty(forcedInternalNodeVersion) && BuiltInNodeVersions.Contains(forcedInternalNodeVersion); - // Create the handler. - IHandler handler; - if (data.ExecutionType == ActionExecutionType.Container) + if (isForcedInternalNodeVersion) { - handler = HostContext.CreateService(); - (handler as IContainerActionHandler).Data = data as ContainerActionExecutionData; + return forcedInternalNodeVersion; } - else if (data.ExecutionType == ActionExecutionType.NodeJS) - { - handler = HostContext.CreateService(); - var nodeData = data as NodeJSActionExecutionData; + return _defaultNodeVersion; + } - // With node12 EoL in 04/2022 and node16 EoL in 09/23, we want to execute all JS actions using node20 - if (string.Equals(nodeData.NodeVersion, "node12", StringComparison.InvariantCultureIgnoreCase) || - string.Equals(nodeData.NodeVersion, "node16", StringComparison.InvariantCultureIgnoreCase)) - { - nodeData.NodeVersion = "node20"; - } - - (handler as INodeScriptActionHandler).Data = nodeData; - } - else if (data.ExecutionType == ActionExecutionType.Script) + /// + /// Checks if Node24 is requested but running on ARM32 Linux, and determines if fallback is needed. + /// + /// The preferred Node version + /// A tuple containing the adjusted node version and an optional warning message + public static (string nodeVersion, string warningMessage) CheckNodeVersionForLinuxArm32(string preferredVersion) + { + if (string.Equals(preferredVersion, "node24", StringComparison.OrdinalIgnoreCase) && + Constants.Runner.PlatformArchitecture.Equals(Constants.Architecture.Arm) && + Constants.Runner.Platform.Equals(Constants.OSPlatform.Linux)) { - handler = HostContext.CreateService(); - (handler as IScriptHandler).Data = data as ScriptActionExecutionData; - } - else if (data.ExecutionType == ActionExecutionType.Plugin) - { - // Runner plugin - handler = HostContext.CreateService(); - (handler as IRunnerPluginHandler).Data = data as PluginActionExecutionData; - } - else if (data.ExecutionType == ActionExecutionType.Composite) - { - handler = HostContext.CreateService(); - (handler as ICompositeActionHandler).Data = data as CompositeActionExecutionData; - } - else - { - // This should never happen. - throw new NotSupportedException(data.ExecutionType.ToString()); + return ("node20", "Node 24 is not supported on Linux ARM32 platforms. Falling back to Node 20."); } - handler.Action = action; - handler.Environment = environment; - handler.RuntimeVariables = runtimeVariables; - handler.ExecutionContext = executionContext; - handler.StepHost = stepHost; - handler.Inputs = inputs; - handler.ActionDirectory = actionDirectory; - handler.LocalActionContainerSetupSteps = localActionContainerSetupSteps; - return handler; + return (preferredVersion, null); } } } \ No newline at end of file