Skip to content

Commit e8ccafe

Browse files
authored
Add internal to node version function and use better env var name (#1715)
1 parent 02d2cb8 commit e8ccafe

File tree

9 files changed

+10
-11
lines changed

9 files changed

+10
-11
lines changed

src/Runner.Common/Constants.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ public static class Agent
226226
{
227227
public static readonly string ToolsDirectory = "agent.ToolsDirectory";
228228

229-
// Set this env var to force a node version for internal functions (e.g hashfiles). This does NOT affect the version of node actions.
230-
public static readonly string ForcedNodeVersion = "GITHUB_ACTIONS_RUNNER_FORCED_NODE_VERSION";
229+
// 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.
230+
public static readonly string ForcedInternalNodeVersion = "ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION";
231231
}
232232

233233
public static class System

src/Runner.Common/Util/NodeUtil.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ public static class NodeUtil
77
{
88
private const string _defaultNodeVersion = "node16";
99
public static readonly ReadOnlyCollection<string> BuiltInNodeVersions = new(new[] {"node12", "node16"});
10-
public static string GetNodeVersion()
10+
public static string GetInternalNodeVersion()
1111
{
12-
var forcedNodeVersion = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedNodeVersion);
12+
var forcedNodeVersion = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedInternalNodeVersion);
1313
return !string.IsNullOrEmpty(forcedNodeVersion) && BuiltInNodeVersions.Contains(forcedNodeVersion) ? forcedNodeVersion : _defaultNodeVersion;
1414
}
1515
}

src/Runner.Listener/Checks/CheckUtil.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public static async Task<CheckResult> DownloadExtraCA(this IHostContext hostCont
315315
});
316316

317317
var downloadCertScript = Path.Combine(hostContext.GetDirectory(WellKnownDirectory.Bin), "checkScripts", "downloadCert");
318-
var node = Path.Combine(hostContext.GetDirectory(WellKnownDirectory.Externals), NodeUtil.GetNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
318+
var node = Path.Combine(hostContext.GetDirectory(WellKnownDirectory.Externals), NodeUtil.GetInternalNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
319319
result.Logs.Add($"{DateTime.UtcNow.ToString("O")} Run '{node} \"{downloadCertScript}\"' ");
320320
result.Logs.Add($"{DateTime.UtcNow.ToString("O")} {StringUtil.ConvertToJson(env)}");
321321
await processInvoker.ExecuteAsync(

src/Runner.Listener/Checks/NodeJsCheck.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private async Task<CheckResult> CheckNodeJs(string url, string pat, bool extraCA
145145
});
146146

147147
var makeWebRequestScript = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Bin), "checkScripts", "makeWebRequest.js");
148-
var node = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), NodeUtil.GetNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
148+
var node = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), NodeUtil.GetInternalNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
149149
result.Logs.Add($"{DateTime.UtcNow.ToString("O")} Run '{node} \"{makeWebRequestScript}\"' ");
150150
result.Logs.Add($"{DateTime.UtcNow.ToString("O")} {StringUtil.ConvertToJson(env)}");
151151
await processInvoker.ExecuteAsync(

src/Runner.Listener/SelfUpdater.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ private async Task<string> HashFiles(string fileFolder, CancellationToken token)
10701070

10711071
var stopWatch = Stopwatch.StartNew();
10721072
string binDir = HostContext.GetDirectory(WellKnownDirectory.Bin);
1073-
string node = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), NodeUtil.GetNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
1073+
string node = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), NodeUtil.GetInternalNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
10741074
string hashFilesScript = Path.Combine(binDir, "hashFiles");
10751075
var hashResult = string.Empty;
10761076

src/Runner.Worker/ExecutionContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ public void InitializeJob(Pipelines.AgentJobRequestMessage message, Cancellation
680680

681681
if (Global.Variables.GetBoolean("DistributedTask.ForceInternalNodeVersionOnRunnerTo12") ?? false)
682682
{
683-
Environment.SetEnvironmentVariable(Constants.Variables.Agent.ForcedNodeVersion, "node12");
683+
Environment.SetEnvironmentVariable(Constants.Variables.Agent.ForcedInternalNodeVersion, "node12");
684684
}
685685

686686
// Environment variables shared across all actions

src/Runner.Worker/Expressions/HashFilesFunction.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected sealed override Object EvaluateCore(
6363
string binDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
6464
string runnerRoot = new DirectoryInfo(binDir).Parent.FullName;
6565

66-
string node = Path.Combine(runnerRoot, "externals", NodeUtil.GetNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
66+
string node = Path.Combine(runnerRoot, "externals", NodeUtil.GetInternalNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
6767
string hashFilesScript = Path.Combine(binDir, "hashFiles");
6868
var hashResult = string.Empty;
6969
var p = new ProcessInvoker(new HashFilesTrace(context.Trace));

src/Runner.Worker/Handlers/NodeScriptActionHandler.cs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using GitHub.DistributedTask.WebApi;
77
using GitHub.Runner.Common;
88
using GitHub.Runner.Sdk;
9-
using Pipelines = GitHub.DistributedTask.Pipelines;
109

1110
namespace GitHub.Runner.Worker.Handlers
1211
{

src/Runner.Worker/Handlers/ScriptHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public async Task RunAsync(ActionRunStage stage)
266266
if (Environment.ContainsKey("DYLD_INSERT_LIBRARIES")) // We don't check `isContainerStepHost` because we don't support container on macOS
267267
{
268268
// launch `node macOSRunInvoker.js shell args` instead of `shell args` to avoid macOS SIP remove `DYLD_INSERT_LIBRARIES` when launch process
269-
string node = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), NodeUtil.GetNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
269+
string node = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), NodeUtil.GetInternalNodeVersion(), "bin", $"node{IOUtil.ExeExtension}");
270270
string macOSRunInvoker = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Bin), "macos-run-invoker.js");
271271
arguments = $"\"{macOSRunInvoker.Replace("\"", "\\\"")}\" \"{fileName.Replace("\"", "\\\"")}\" {arguments}";
272272
fileName = node;

0 commit comments

Comments
 (0)