From d11bd3d8be89c04a0eb3793a5f4d7ed39a013f55 Mon Sep 17 00:00:00 2001 From: Stefan Ruvceski <96768603+ruvceskistefan@users.noreply.github.com> Date: Wed, 22 Jun 2022 17:13:28 +0200 Subject: [PATCH] Created env var for forcing node12 actions to run on node16 (#1913) * Created env var for forcing node12 actions to run on node16 * get value of hostContext environment variable * changing location of forced node version check * small code refactoring Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> * more of small code refactoring Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> * refactoring of conditions for getting internal node version * changing expected value for node version env var * Adding empty line between two methods * Created method GetNodeVersion * GetNodeVersion from function to inline call and PR fixes Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com> --- src/Runner.Common/Constants.cs | 1 + src/Runner.Common/Util/NodeUtil.cs | 10 ++++++++-- src/Runner.Worker/Handlers/NodeScriptActionHandler.cs | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index 1ee60714e..0e756ae55 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -242,6 +242,7 @@ namespace GitHub.Runner.Common // Set this env var to "node12" to downgrade the node version for internal functions (e.g hashfiles). This does NOT affect the version of node actions. public static readonly string ForcedInternalNodeVersion = "ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION"; + public static readonly string ForcedActionsNodeVersion = "ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION"; } public static class System diff --git a/src/Runner.Common/Util/NodeUtil.cs b/src/Runner.Common/Util/NodeUtil.cs index bae94f4b0..8fbf53bdf 100644 --- a/src/Runner.Common/Util/NodeUtil.cs +++ b/src/Runner.Common/Util/NodeUtil.cs @@ -15,8 +15,14 @@ namespace GitHub.Runner.Common.Util public static string GetInternalNodeVersion() { - var forcedNodeVersion = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedInternalNodeVersion); - return !string.IsNullOrEmpty(forcedNodeVersion) && BuiltInNodeVersions.Contains(forcedNodeVersion) ? forcedNodeVersion : _defaultNodeVersion; + var forcedInternalNodeVersion = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedInternalNodeVersion); + var isForcedInternalNodeVersion = !string.IsNullOrEmpty(forcedInternalNodeVersion) && BuiltInNodeVersions.Contains(forcedInternalNodeVersion); + + if (isForcedInternalNodeVersion) + { + return forcedInternalNodeVersion; + } + return _defaultNodeVersion; } } } diff --git a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs index 6f513c863..0311c4ab8 100644 --- a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs +++ b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs @@ -8,6 +8,7 @@ using GitHub.DistributedTask.Pipelines.ContextData; using GitHub.DistributedTask.WebApi; using GitHub.Runner.Common; using GitHub.Runner.Sdk; +using GitHub.Runner.Common.Util; using GitHub.Runner.Worker.Container; using GitHub.Runner.Worker.Container.ContainerHooks; @@ -104,6 +105,12 @@ namespace GitHub.Runner.Worker.Handlers Data.NodeVersion = "node16"; } #endif + string forcedNodeVersion = System.Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedActionsNodeVersion); + + if (forcedNodeVersion == "node16" && Data.NodeVersion != "node16") + { + Data.NodeVersion = "node16"; + } var nodeRuntimeVersion = await StepHost.DetermineNodeRuntimeVersion(ExecutionContext, Data.NodeVersion); string file = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), nodeRuntimeVersion, "bin", $"node{IOUtil.ExeExtension}");