diff --git a/src/Runner.Worker/ActionCommandManager.cs b/src/Runner.Worker/ActionCommandManager.cs index 132e5cce5..be96a4514 100644 --- a/src/Runner.Worker/ActionCommandManager.cs +++ b/src/Runner.Worker/ActionCommandManager.cs @@ -188,7 +188,7 @@ namespace GitHub.Runner.Worker throw new Exception("Required field 'name' is missing in ##[set-env] command."); } - context.EnvironmentVariables[envName] = command.Data; + context.Global.EnvironmentVariables[envName] = command.Data; context.SetEnvContext(envName, command.Data); context.Debug($"{envName}='{command.Data}'"); } @@ -283,8 +283,8 @@ namespace GitHub.Runner.Worker public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { ArgUtil.NotNullOrEmpty(command.Data, "path"); - context.PrependPath.RemoveAll(x => string.Equals(x, command.Data, StringComparison.CurrentCulture)); - context.PrependPath.Add(command.Data); + context.Global.PrependPath.RemoveAll(x => string.Equals(x, command.Data, StringComparison.CurrentCulture)); + context.Global.PrependPath.Add(command.Data); } } diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 65c3d3593..0a942bf79 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -66,7 +66,7 @@ namespace GitHub.Runner.Worker // TODO: Deprecate the PREVIEW_ACTION_TOKEN // Log even if we aren't using it to ensure users know. - if (!string.IsNullOrEmpty(executionContext.Variables.Get("PREVIEW_ACTION_TOKEN"))) + if (!string.IsNullOrEmpty(executionContext.Global.Variables.Get("PREVIEW_ACTION_TOKEN"))) { executionContext.Warning("The 'PREVIEW_ACTION_TOKEN' secret is deprecated. Please remove it from the repository's secrets"); } @@ -75,7 +75,7 @@ namespace GitHub.Runner.Worker IOUtil.DeleteDirectory(HostContext.GetDirectory(WellKnownDirectory.Actions), executionContext.CancellationToken); // todo: Remove when feature flag DistributedTask.NewActionMetadata is removed - var newActionMetadata = executionContext.Variables.GetBoolean("DistributedTask.NewActionMetadata") ?? false; + var newActionMetadata = executionContext.Global.Variables.GetBoolean("DistributedTask.NewActionMetadata") ?? false; var repositoryActions = new List(); @@ -589,7 +589,7 @@ namespace GitHub.Runner.Worker { try { - actionDownloadInfos = await jobServer.ResolveActionDownloadInfoAsync(executionContext.Plan.ScopeIdentifier, executionContext.Plan.PlanType, executionContext.Plan.PlanId, new WebApi.ActionReferenceList { Actions = actionReferences }, executionContext.CancellationToken); + actionDownloadInfos = await jobServer.ResolveActionDownloadInfoAsync(executionContext.Global.Plan.ScopeIdentifier, executionContext.Global.Plan.PlanType, executionContext.Global.Plan.PlanId, new WebApi.ActionReferenceList { Actions = actionReferences }, executionContext.CancellationToken); break; } catch (Exception ex) when (attempt < 3) @@ -947,7 +947,7 @@ namespace GitHub.Runner.Worker if (string.IsNullOrEmpty(authToken)) { // TODO: Deprecate the PREVIEW_ACTION_TOKEN - authToken = executionContext.Variables.Get("PREVIEW_ACTION_TOKEN"); + authToken = executionContext.Global.Variables.Get("PREVIEW_ACTION_TOKEN"); } if (!string.IsNullOrEmpty(authToken)) diff --git a/src/Runner.Worker/ActionManifestManager.cs b/src/Runner.Worker/ActionManifestManager.cs index 15734cb86..5be77c174 100644 --- a/src/Runner.Worker/ActionManifestManager.cs +++ b/src/Runner.Worker/ActionManifestManager.cs @@ -77,9 +77,9 @@ namespace GitHub.Runner.Worker // Add this file to the FileTable in executionContext if it hasn't been added already // we use > since fileID is 1 indexed - if (fileId > executionContext.FileTable.Count) + if (fileId > executionContext.Global.FileTable.Count) { - executionContext.FileTable.Add(fileRelativePath); + executionContext.Global.FileTable.Add(fileRelativePath); } // Read the file @@ -347,9 +347,9 @@ namespace GitHub.Runner.Worker } // Add the file table from the Execution Context - for (var i = 0; i < executionContext.FileTable.Count; i++) + for (var i = 0; i < executionContext.Global.FileTable.Count; i++) { - result.GetFileId(executionContext.FileTable[i]); + result.GetFileId(executionContext.Global.FileTable[i]); } return result; diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 81ecf1a14..8a12b9561 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -136,12 +136,12 @@ namespace GitHub.Runner.Worker } // Setup container stephost for running inside the container. - if (ExecutionContext.Container != null) + if (ExecutionContext.Global.Container != null) { // Make sure required container is already created. - ArgUtil.NotNullOrEmpty(ExecutionContext.Container.ContainerId, nameof(ExecutionContext.Container.ContainerId)); + ArgUtil.NotNullOrEmpty(ExecutionContext.Global.Container.ContainerId, nameof(ExecutionContext.Global.Container.ContainerId)); var containerStepHost = HostContext.CreateService(); - containerStepHost.Container = ExecutionContext.Container; + containerStepHost.Container = ExecutionContext.Global.Container; stepHost = containerStepHost; } @@ -231,7 +231,7 @@ namespace GitHub.Runner.Worker handlerData, inputs, environment, - ExecutionContext.Variables, + ExecutionContext.Global.Variables, actionDirectory: definition.Directory); // Print out action details diff --git a/src/Runner.Worker/DiagnosticLogManager.cs b/src/Runner.Worker/DiagnosticLogManager.cs index 45443f856..698f2112c 100644 --- a/src/Runner.Worker/DiagnosticLogManager.cs +++ b/src/Runner.Worker/DiagnosticLogManager.cs @@ -86,9 +86,9 @@ namespace GitHub.Runner.Worker executionContext.Debug("Zipping diagnostic files."); - string buildNumber = executionContext.Variables.Build_Number ?? "UnknownBuildNumber"; + string buildNumber = executionContext.Global.Variables.Build_Number ?? "UnknownBuildNumber"; string buildName = $"Build {buildNumber}"; - string phaseName = executionContext.Variables.System_PhaseDisplayName ?? "UnknownPhaseName"; + string phaseName = executionContext.Global.Variables.System_PhaseDisplayName ?? "UnknownPhaseName"; // zip the files string diagnosticsZipFileName = $"{buildName}-{phaseName}.zip"; diff --git a/src/Runner.Worker/ExecutionContext.cs b/src/Runner.Worker/ExecutionContext.cs index 18e7dd9d1..6f6279c6b 100644 --- a/src/Runner.Worker/ExecutionContext.cs +++ b/src/Runner.Worker/ExecutionContext.cs @@ -44,22 +44,12 @@ namespace GitHub.Runner.Worker string ResultCode { get; set; } TaskResult? CommandResult { get; set; } CancellationToken CancellationToken { get; } - List Endpoints { get; } - TaskOrchestrationPlanReference Plan { get; } + GlobalContext Global { get; } - PlanFeatures Features { get; } - Variables Variables { get; } Dictionary IntraActionState { get; } - IDictionary> JobDefaults { get; } Dictionary JobOutputs { get; } - IDictionary EnvironmentVariables { get; } - IList FileTable { get; } - StepsContext StepsContext { get; } DictionaryContextData ExpressionValues { get; } IList ExpressionFunctions { get; } - List PrependPath { get; } - ContainerInfo Container { get; set; } - List ServiceContainers { get; } JobContext JobContext { get; } // Only job level ExecutionContext has JobSteps @@ -76,7 +66,6 @@ namespace GitHub.Runner.Worker IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, Dictionary intraActionState = null, int? recordOrder = null, IPagingLogger logger = null); // logging - bool WriteDebug { get; } long Write(string tag, string message); void QueueAttachFile(string type, string name, string filePath); @@ -142,21 +131,13 @@ namespace GitHub.Runner.Worker public string ContextName { get; private set; } public Task ForceCompleted => _forceCompleted.Task; public CancellationToken CancellationToken => _cancellationTokenSource.Token; - public List Endpoints { get; private set; } - public TaskOrchestrationPlanReference Plan { get; private set; } - public Variables Variables { get; private set; } public Dictionary IntraActionState { get; private set; } - public IDictionary> JobDefaults { get; private set; } public Dictionary JobOutputs { get; private set; } - public IDictionary EnvironmentVariables { get; private set; } - public IList FileTable { get; private set; } - public StepsContext StepsContext { get; private set; } public DictionaryContextData ExpressionValues { get; } = new DictionaryContextData(); public IList ExpressionFunctions { get; } = new List(); - public bool WriteDebug { get; private set; } - public List PrependPath { get; private set; } - public ContainerInfo Container { get; set; } - public List ServiceContainers { get; private set; } + + // Shared pointer across job-level execution context and step-level execution contexts + public GlobalContext Global { get; private set; } // Only job level ExecutionContext has JobSteps public List JobSteps { get; private set; } @@ -199,8 +180,6 @@ namespace GitHub.Runner.Worker } } - public PlanFeatures Features { get; private set; } - private ExecutionContext Root { get @@ -277,7 +256,7 @@ namespace GitHub.Runner.Worker { step.ExecutionContext = Root.CreateChild(_record.Id, step.DisplayName, _record.Id.ToString("N"), scopeName, step.Action.ContextName, logger: _logger); step.ExecutionContext.ExpressionValues["inputs"] = inputsData; - step.ExecutionContext.ExpressionValues["steps"] = StepsContext.GetScope(step.ExecutionContext.GetFullyQualifiedContextName()); + step.ExecutionContext.ExpressionValues["steps"] = Global.StepsContext.GetScope(step.ExecutionContext.GetFullyQualifiedContextName()); // Add the composite action environment variables to each step. #if OS_WINDOWS @@ -300,12 +279,9 @@ namespace GitHub.Runner.Worker var child = new ExecutionContext(); child.Initialize(HostContext); + child.Global = Global; child.ScopeName = scopeName; child.ContextName = contextName; - child.Features = Features; - child.Variables = Variables; - child.Endpoints = Endpoints; - child.Plan = Plan; if (intraActionState == null) { child.IntraActionState = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -314,10 +290,6 @@ namespace GitHub.Runner.Worker { child.IntraActionState = intraActionState; } - child.EnvironmentVariables = EnvironmentVariables; - child.JobDefaults = JobDefaults; - child.FileTable = FileTable; - child.StepsContext = StepsContext; foreach (var pair in ExpressionValues) { child.ExpressionValues[pair.Key] = pair.Value; @@ -327,11 +299,7 @@ namespace GitHub.Runner.Worker child.ExpressionFunctions.Add(item); } child._cancellationTokenSource = new CancellationTokenSource(); - child.WriteDebug = WriteDebug; child._parentExecutionContext = this; - child.PrependPath = PrependPath; - child.Container = Container; - child.ServiceContainers = ServiceContainers; child.EchoOnActionCommand = EchoOnActionCommand; if (recordOrder != null) @@ -411,8 +379,8 @@ namespace GitHub.Runner.Worker // todo: Skip if generated context name. After M271-ish the server will never send an empty context name. Generated context names will start with "__" if (!string.IsNullOrEmpty(ContextName)) { - StepsContext.SetOutcome(ScopeName, ContextName, (Outcome ?? Result ?? TaskResult.Succeeded).ToActionResult()); - StepsContext.SetConclusion(ScopeName, ContextName, (Result ?? TaskResult.Succeeded).ToActionResult()); + Global.StepsContext.SetOutcome(ScopeName, ContextName, (Outcome ?? Result ?? TaskResult.Succeeded).ToActionResult()); + Global.StepsContext.SetConclusion(ScopeName, ContextName, (Result ?? TaskResult.Succeeded).ToActionResult()); } return Result.Value; @@ -480,7 +448,7 @@ namespace GitHub.Runner.Worker // todo: restrict multiline? - StepsContext.SetOutput(ScopeName, ContextName, name, value, out reference); + Global.StepsContext.SetOutput(ScopeName, ContextName, name, value, out reference); } public void SetTimeout(TimeSpan? timeout) @@ -614,33 +582,35 @@ namespace GitHub.Runner.Worker _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token); + Global = new GlobalContext(); + // Plan - Plan = message.Plan; - Features = PlanUtil.GetFeatures(message.Plan); + Global.Plan = message.Plan; + Global.Features = PlanUtil.GetFeatures(message.Plan); // Endpoints - Endpoints = message.Resources.Endpoints; + Global.Endpoints = message.Resources.Endpoints; // Variables - Variables = new Variables(HostContext, message.Variables); + Global.Variables = new Variables(HostContext, message.Variables); // Environment variables shared across all actions - EnvironmentVariables = new Dictionary(VarUtil.EnvironmentVariableKeyComparer); + Global.EnvironmentVariables = new Dictionary(VarUtil.EnvironmentVariableKeyComparer); // Job defaults shared across all actions - JobDefaults = new Dictionary>(StringComparer.OrdinalIgnoreCase); + Global.JobDefaults = new Dictionary>(StringComparer.OrdinalIgnoreCase); // Job Outputs JobOutputs = new Dictionary(StringComparer.OrdinalIgnoreCase); // Service container info - ServiceContainers = new List(); + Global.ServiceContainers = new List(); // Steps context (StepsRunner manages adding the scoped steps context) - StepsContext = new StepsContext(); + Global.StepsContext = new StepsContext(); // File table - FileTable = new List(message.FileTable ?? new string[0]); + Global.FileTable = new List(message.FileTable ?? new string[0]); // Expression values if (message.ContextData?.Count > 0) @@ -651,15 +621,15 @@ namespace GitHub.Runner.Worker } } - ExpressionValues["secrets"] = Variables.ToSecretsContext(); + ExpressionValues["secrets"] = Global.Variables.ToSecretsContext(); ExpressionValues["runner"] = new RunnerContext(); ExpressionValues["job"] = new JobContext(); Trace.Info("Initialize GitHub context"); - var githubAccessToken = new StringContextData(Variables.Get("system.github.token")); + var githubAccessToken = new StringContextData(Global.Variables.Get("system.github.token")); var base64EncodedToken = Convert.ToBase64String(Encoding.UTF8.GetBytes($"x-access-token:{githubAccessToken}")); HostContext.SecretMasker.AddValue(base64EncodedToken); - var githubJob = Variables.Get("system.github.job"); + var githubJob = Global.Variables.Get("system.github.job"); var githubContext = new GitHubContext(); githubContext["token"] = githubAccessToken; if (!string.IsNullOrEmpty(githubJob)) @@ -682,7 +652,7 @@ namespace GitHub.Runner.Worker #endif // Prepend Path - PrependPath = new List(); + Global.PrependPath = new List(); // JobSteps for job ExecutionContext JobSteps = new List(); @@ -708,10 +678,10 @@ namespace GitHub.Runner.Worker _logger.Setup(_mainTimelineId, _record.Id); // Initialize 'echo on action command success' property, default to false, unless Step_Debug is set - EchoOnActionCommand = Variables.Step_Debug ?? false; + EchoOnActionCommand = Global.Variables.Step_Debug ?? false; // Verbosity (from GitHub.Step_Debug). - WriteDebug = Variables.Step_Debug ?? false; + Global.WriteDebug = Global.Variables.Step_Debug ?? false; // Hook up JobServerQueueThrottling event, we will log warning on server tarpit. _jobServerQueue.JobServerQueueThrottling += JobServerQueueThrottling_EventReceived; @@ -960,7 +930,7 @@ namespace GitHub.Runner.Worker // Do not add a format string overload. See comment on ExecutionContext.Write(). public static void Debug(this IExecutionContext context, string message) { - if (context.WriteDebug) + if (context.Global.WriteDebug) { var multilines = message?.Replace("\r\n", "\n")?.Split("\n"); if (multilines != null) @@ -985,7 +955,7 @@ namespace GitHub.Runner.Worker traceWriter = context.ToTemplateTraceWriter(); } var schema = PipelineTemplateSchemaFactory.GetSchema(); - return new PipelineTemplateEvaluator(traceWriter, schema, context.FileTable); + return new PipelineTemplateEvaluator(traceWriter, schema, context.Global.FileTable); } public static ObjectTemplating.ITraceWriter ToTemplateTraceWriter(this IExecutionContext context) diff --git a/src/Runner.Worker/GlobalContext.cs b/src/Runner.Worker/GlobalContext.cs new file mode 100644 index 000000000..b740e10bd --- /dev/null +++ b/src/Runner.Worker/GlobalContext.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using GitHub.DistributedTask.WebApi; +using GitHub.Runner.Common.Util; +using GitHub.Runner.Worker.Container; + +namespace GitHub.Runner.Worker +{ + public sealed class GlobalContext + { + public ContainerInfo Container { get; set; } + public List Endpoints { get; set; } + public IDictionary EnvironmentVariables { get; set; } + public PlanFeatures Features { get; set; } + public IList FileTable { get; set; } + public IDictionary> JobDefaults { get; set; } + public TaskOrchestrationPlanReference Plan { get; set; } + public List PrependPath { get; set; } + public List ServiceContainers { get; set; } + public StepsContext StepsContext { get; set; } + public Variables Variables { get; set; } + public bool WriteDebug { get; set; } + } +} diff --git a/src/Runner.Worker/Handlers/CompositeActionHandler.cs b/src/Runner.Worker/Handlers/CompositeActionHandler.cs index 2ebad979f..80e4d13a5 100644 --- a/src/Runner.Worker/Handlers/CompositeActionHandler.cs +++ b/src/Runner.Worker/Handlers/CompositeActionHandler.cs @@ -73,7 +73,7 @@ namespace GitHub.Runner.Worker.Handlers // Get the pointer of the correct "steps" object and pass it to the ExecutionContext so that we can process the outputs correctly ExecutionContext.ExpressionValues["inputs"] = inputsData; - ExecutionContext.ExpressionValues["steps"] = ExecutionContext.StepsContext.GetScope(ExecutionContext.GetFullyQualifiedContextName()); + ExecutionContext.ExpressionValues["steps"] = ExecutionContext.Global.StepsContext.GetScope(ExecutionContext.GetFullyQualifiedContextName()); ProcessCompositeActionOutputs(); } @@ -141,7 +141,7 @@ namespace GitHub.Runner.Worker.Handlers { Trace.Info($"Processing composite step: DisplayName='{step.DisplayName}'"); - step.ExecutionContext.ExpressionValues["steps"] = step.ExecutionContext.StepsContext.GetScope(step.ExecutionContext.ScopeName); + step.ExecutionContext.ExpressionValues["steps"] = ExecutionContext.Global.StepsContext.GetScope(step.ExecutionContext.ScopeName); // Populate env context for each step Trace.Info("Initialize Env context for step"); @@ -152,7 +152,7 @@ namespace GitHub.Runner.Worker.Handlers #endif // Global env - foreach (var pair in step.ExecutionContext.EnvironmentVariables) + foreach (var pair in ExecutionContext.Global.EnvironmentVariables) { envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty); } diff --git a/src/Runner.Worker/Handlers/ContainerActionHandler.cs b/src/Runner.Worker/Handlers/ContainerActionHandler.cs index 6e93d1919..573010030 100644 --- a/src/Runner.Worker/Handlers/ContainerActionHandler.cs +++ b/src/Runner.Worker/Handlers/ContainerActionHandler.cs @@ -185,7 +185,7 @@ namespace GitHub.Runner.Worker.Handlers } // Add Actions Runtime server info - var systemConnection = ExecutionContext.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); + var systemConnection = ExecutionContext.Global.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri; Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken]; if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl)) diff --git a/src/Runner.Worker/Handlers/Handler.cs b/src/Runner.Worker/Handlers/Handler.cs index 11e30e62a..f3e91bc03 100644 --- a/src/Runner.Worker/Handlers/Handler.cs +++ b/src/Runner.Worker/Handlers/Handler.cs @@ -148,14 +148,14 @@ namespace GitHub.Runner.Worker.Handlers { // Validate args. Trace.Entering(); - ArgUtil.NotNull(ExecutionContext.PrependPath, nameof(ExecutionContext.PrependPath)); - if (ExecutionContext.PrependPath.Count == 0) + ArgUtil.NotNull(ExecutionContext.Global.PrependPath, nameof(ExecutionContext.Global.PrependPath)); + if (ExecutionContext.Global.PrependPath.Count == 0) { return; } // Prepend path. - string prepend = string.Join(Path.PathSeparator.ToString(), ExecutionContext.PrependPath.Reverse()); + string prepend = string.Join(Path.PathSeparator.ToString(), ExecutionContext.Global.PrependPath.Reverse()); var containerStepHost = StepHost as ContainerStepHost; if (containerStepHost != null) { diff --git a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs index c28f3de93..da0d66f67 100644 --- a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs +++ b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs @@ -46,7 +46,7 @@ namespace GitHub.Runner.Worker.Handlers } // Add Actions Runtime server info - var systemConnection = ExecutionContext.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); + var systemConnection = ExecutionContext.Global.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri; Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken]; if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl)) @@ -113,7 +113,7 @@ namespace GitHub.Runner.Worker.Handlers requireExitCodeZero: false, outputEncoding: outputEncoding, killProcessOnCancel: false, - inheritConsoleHandler: !ExecutionContext.Variables.Retain_Default_Encoding, + inheritConsoleHandler: !ExecutionContext.Global.Variables.Retain_Default_Encoding, cancellationToken: ExecutionContext.CancellationToken); // Wait for either the node exit or force finish through ##vso command diff --git a/src/Runner.Worker/Handlers/OutputManager.cs b/src/Runner.Worker/Handlers/OutputManager.cs index a0c136c3f..855e6bd02 100644 --- a/src/Runner.Worker/Handlers/OutputManager.cs +++ b/src/Runner.Worker/Handlers/OutputManager.cs @@ -31,7 +31,7 @@ namespace GitHub.Runner.Worker.Handlers { _executionContext = executionContext; _commandManager = commandManager; - _container = container ?? executionContext.Container; + _container = container ?? executionContext.Global.Container; // Recursion failsafe (test override) var failsafeString = Environment.GetEnvironmentVariable("RUNNER_TEST_GET_REPOSITORY_PATH_FAILSAFE"); @@ -41,7 +41,7 @@ namespace GitHub.Runner.Worker.Handlers } // Determine the timeout - var timeoutStr = _executionContext.Variables.Get(_timeoutKey); + var timeoutStr = _executionContext.Global.Variables.Get(_timeoutKey); if (string.IsNullOrEmpty(timeoutStr) || !TimeSpan.TryParse(timeoutStr, CultureInfo.InvariantCulture, out _timeout) || _timeout <= TimeSpan.Zero) diff --git a/src/Runner.Worker/Handlers/ScriptHandler.cs b/src/Runner.Worker/Handlers/ScriptHandler.cs index 051cd5fc7..f7d90dc45 100644 --- a/src/Runner.Worker/Handlers/ScriptHandler.cs +++ b/src/Runner.Worker/Handlers/ScriptHandler.cs @@ -57,13 +57,13 @@ namespace GitHub.Runner.Worker.Handlers string shellCommand; string shellCommandPath = null; bool validateShellOnHost = !(StepHost is ContainerStepHost); - string prependPath = string.Join(Path.PathSeparator.ToString(), ExecutionContext.PrependPath.Reverse()); + string prependPath = string.Join(Path.PathSeparator.ToString(), ExecutionContext.Global.PrependPath.Reverse()); string shell = null; if (!Inputs.TryGetValue("shell", out shell) || string.IsNullOrEmpty(shell)) { // TODO: figure out how defaults interact with template later // for now, we won't check job.defaults if we are inside a template. - if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.JobDefaults.TryGetValue("run", out var runDefaults)) + if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.Global.JobDefaults.TryGetValue("run", out var runDefaults)) { runDefaults.TryGetValue("shell", out shell); } @@ -153,7 +153,7 @@ namespace GitHub.Runner.Worker.Handlers { // TODO: figure out how defaults interact with template later // for now, we won't check job.defaults if we are inside a template. - if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.JobDefaults.TryGetValue("run", out var runDefaults)) + if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.Global.JobDefaults.TryGetValue("run", out var runDefaults)) { if (runDefaults.TryGetValue("working-directory", out workingDirectory)) { @@ -169,7 +169,7 @@ namespace GitHub.Runner.Worker.Handlers { // TODO: figure out how defaults interact with template later // for now, we won't check job.defaults if we are inside a template. - if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.JobDefaults.TryGetValue("run", out var runDefaults)) + if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.Global.JobDefaults.TryGetValue("run", out var runDefaults)) { if (runDefaults.TryGetValue("shell", out shell)) { @@ -180,7 +180,7 @@ namespace GitHub.Runner.Worker.Handlers var isContainerStepHost = StepHost is ContainerStepHost; - string prependPath = string.Join(Path.PathSeparator.ToString(), ExecutionContext.PrependPath.Reverse()); + string prependPath = string.Join(Path.PathSeparator.ToString(), ExecutionContext.Global.PrependPath.Reverse()); string commandPath, argFormat, shellCommand; // Set up default command and arguments if (string.IsNullOrEmpty(shell)) @@ -232,7 +232,7 @@ namespace GitHub.Runner.Worker.Handlers #if OS_WINDOWS // Normalize Windows line endings contents = contents.Replace("\r\n", "\n").Replace("\n", "\r\n"); - var encoding = ExecutionContext.Variables.Retain_Default_Encoding && Console.InputEncoding.CodePage != 65001 + var encoding = ExecutionContext.Global.Variables.Retain_Default_Encoding && Console.InputEncoding.CodePage != 65001 ? Console.InputEncoding : new UTF8Encoding(false); #else @@ -285,7 +285,7 @@ namespace GitHub.Runner.Worker.Handlers requireExitCodeZero: false, outputEncoding: null, killProcessOnCancel: false, - inheritConsoleHandler: !ExecutionContext.Variables.Retain_Default_Encoding, + inheritConsoleHandler: !ExecutionContext.Global.Variables.Retain_Default_Encoding, cancellationToken: ExecutionContext.CancellationToken); // Error diff --git a/src/Runner.Worker/JobExtension.cs b/src/Runner.Worker/JobExtension.cs index eb3f4fcd4..6b3c07830 100644 --- a/src/Runner.Worker/JobExtension.cs +++ b/src/Runner.Worker/JobExtension.cs @@ -162,7 +162,7 @@ namespace GitHub.Runner.Worker var environmentVariables = templateEvaluator.EvaluateStepEnvironment(token, jobContext.ExpressionValues, jobContext.ExpressionFunctions, VarUtil.EnvironmentVariableKeyComparer); foreach (var pair in environmentVariables) { - context.EnvironmentVariables[pair.Key] = pair.Value ?? string.Empty; + context.Global.EnvironmentVariables[pair.Key] = pair.Value ?? string.Empty; context.SetEnvContext(pair.Key, pair.Value ?? string.Empty); } } @@ -172,7 +172,7 @@ namespace GitHub.Runner.Worker var container = templateEvaluator.EvaluateJobContainer(message.JobContainer, jobContext.ExpressionValues, jobContext.ExpressionFunctions); if (container != null) { - jobContext.Container = new Container.ContainerInfo(HostContext, container); + jobContext.Global.Container = new Container.ContainerInfo(HostContext, container); } // Evaluate the job service containers @@ -184,7 +184,7 @@ namespace GitHub.Runner.Worker { var networkAlias = pair.Key; var serviceContainer = pair.Value; - jobContext.ServiceContainers.Add(new Container.ContainerInfo(HostContext, serviceContainer, false, networkAlias)); + jobContext.Global.ServiceContainers.Add(new Container.ContainerInfo(HostContext, serviceContainer, false, networkAlias)); } } @@ -195,14 +195,14 @@ namespace GitHub.Runner.Worker var defaults = token.AssertMapping("defaults"); if (defaults.Any(x => string.Equals(x.Key.AssertString("defaults key").Value, "run", StringComparison.OrdinalIgnoreCase))) { - context.JobDefaults["run"] = new Dictionary(StringComparer.OrdinalIgnoreCase); + context.Global.JobDefaults["run"] = new Dictionary(StringComparer.OrdinalIgnoreCase); var defaultsRun = defaults.First(x => string.Equals(x.Key.AssertString("defaults key").Value, "run", StringComparison.OrdinalIgnoreCase)); var jobDefaults = templateEvaluator.EvaluateJobDefaultsRun(defaultsRun.Value, jobContext.ExpressionValues, jobContext.ExpressionFunctions); foreach (var pair in jobDefaults) { if (!string.IsNullOrEmpty(pair.Value)) { - context.JobDefaults["run"][pair.Key] = pair.Value; + context.Global.JobDefaults["run"][pair.Key] = pair.Value; } } } @@ -216,15 +216,15 @@ namespace GitHub.Runner.Worker preJobSteps.AddRange(prepareResult.ContainerSetupSteps); // Add start-container steps, record and stop-container steps - if (jobContext.Container != null || jobContext.ServiceContainers.Count > 0) + if (jobContext.Global.Container != null || jobContext.Global.ServiceContainers.Count > 0) { var containerProvider = HostContext.GetService(); var containers = new List(); - if (jobContext.Container != null) + if (jobContext.Global.Container != null) { - containers.Add(jobContext.Container); + containers.Add(jobContext.Global.Container); } - containers.AddRange(jobContext.ServiceContainers); + containers.AddRange(jobContext.Global.ServiceContainers); preJobSteps.Add(new JobExtensionRunner(runAsync: containerProvider.StartContainersAsync, condition: $"{PipelineTemplateConstants.Success}()", @@ -305,7 +305,7 @@ namespace GitHub.Runner.Worker steps.AddRange(jobSteps); // Prepare for orphan process cleanup - _processCleanup = jobContext.Variables.GetBoolean("process.clean") ?? true; + _processCleanup = jobContext.Global.Variables.GetBoolean("process.clean") ?? true; if (_processCleanup) { // Set the RUNNER_TRACKING_ID env variable. @@ -376,13 +376,13 @@ namespace GitHub.Runner.Worker var envContext = new CaseSensitiveDictionaryContextData(); #endif context.ExpressionValues["env"] = envContext; - foreach (var pair in context.EnvironmentVariables) + foreach (var pair in context.Global.EnvironmentVariables) { envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty); } Trace.Info("Initialize steps context for evaluating job outputs"); - context.ExpressionValues["steps"] = context.StepsContext.GetScope(context.ScopeName); + context.ExpressionValues["steps"] = context.Global.StepsContext.GetScope(context.ScopeName); var templateEvaluator = context.ToPipelineTemplateEvaluator(); var outputs = templateEvaluator.EvaluateJobOutput(message.JobOutputs, context.ExpressionValues, context.ExpressionFunctions); @@ -413,7 +413,7 @@ namespace GitHub.Runner.Worker } } - if (context.Variables.GetBoolean(Constants.Variables.Actions.RunnerDebug) ?? false) + if (context.Global.Variables.GetBoolean(Constants.Variables.Actions.RunnerDebug) ?? false) { Trace.Info("Support log upload starting."); context.Output("Uploading runner diagnostic logs"); diff --git a/src/Runner.Worker/JobRunner.cs b/src/Runner.Worker/JobRunner.cs index 33b291adb..3ea9e0e04 100644 --- a/src/Runner.Worker/JobRunner.cs +++ b/src/Runner.Worker/JobRunner.cs @@ -99,7 +99,7 @@ namespace GitHub.Runner.Worker return await CompleteJobAsync(jobServer, jobContext, message, TaskResult.Failed); } - if (jobContext.WriteDebug) + if (jobContext.Global.WriteDebug) { jobContext.SetRunnerContext("debug", "1"); } @@ -209,7 +209,7 @@ namespace GitHub.Runner.Worker // Clean TEMP after finish process jobserverqueue, since there might be a pending fileupload still use the TEMP dir. _tempDirectoryManager?.CleanupTempDirectory(); - if (!jobContext.Features.HasFlag(PlanFeatures.JobCompletedPlanEvent)) + if (!jobContext.Global.Features.HasFlag(PlanFeatures.JobCompletedPlanEvent)) { Trace.Info($"Skip raise job completed event call from worker because Plan version is {message.Plan.Version}"); return result; diff --git a/src/Runner.Worker/RunnerPluginManager.cs b/src/Runner.Worker/RunnerPluginManager.cs index 1157a1762..78f7ff38f 100644 --- a/src/Runner.Worker/RunnerPluginManager.cs +++ b/src/Runner.Worker/RunnerPluginManager.cs @@ -100,12 +100,12 @@ namespace GitHub.Runner.Worker RunnerActionPluginExecutionContext pluginContext = new RunnerActionPluginExecutionContext { Inputs = inputs, - Endpoints = context.Endpoints, + Endpoints = context.Global.Endpoints, Context = context.ExpressionValues }; // variables - foreach (var variable in context.Variables.AllVariables) + foreach (var variable in context.Global.Variables.AllVariables) { pluginContext.Variables[variable.Name] = new VariableValue(variable.Value, variable.Secret); } diff --git a/src/Runner.Worker/StepsRunner.cs b/src/Runner.Worker/StepsRunner.cs index dfe7e8778..7877ae6a7 100644 --- a/src/Runner.Worker/StepsRunner.cs +++ b/src/Runner.Worker/StepsRunner.cs @@ -70,7 +70,8 @@ namespace GitHub.Runner.Worker Trace.Info($"Processing step: DisplayName='{step.DisplayName}'"); ArgUtil.NotNull(step.ExecutionContext, nameof(step.ExecutionContext)); - ArgUtil.NotNull(step.ExecutionContext.Variables, nameof(step.ExecutionContext.Variables)); + ArgUtil.NotNull(step.ExecutionContext.Global, nameof(step.ExecutionContext.Global)); + ArgUtil.NotNull(step.ExecutionContext.Global.Variables, nameof(step.ExecutionContext.Global.Variables)); // Start step.ExecutionContext.Start(); @@ -82,7 +83,7 @@ namespace GitHub.Runner.Worker step.ExecutionContext.ExpressionFunctions.Add(new FunctionInfo(PipelineTemplateConstants.Success, 0, 0)); step.ExecutionContext.ExpressionFunctions.Add(new FunctionInfo(PipelineTemplateConstants.HashFiles, 1, byte.MaxValue)); - step.ExecutionContext.ExpressionValues["steps"] = step.ExecutionContext.StepsContext.GetScope(step.ExecutionContext.ScopeName); + step.ExecutionContext.ExpressionValues["steps"] = step.ExecutionContext.Global.StepsContext.GetScope(step.ExecutionContext.ScopeName); // Populate env context for each step Trace.Info("Initialize Env context for step"); @@ -92,7 +93,8 @@ namespace GitHub.Runner.Worker var envContext = new CaseSensitiveDictionaryContextData(); #endif - foreach (var pair in step.ExecutionContext.EnvironmentVariables) + // Global env + foreach (var pair in step.ExecutionContext.Global.EnvironmentVariables) { envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty); } @@ -105,7 +107,7 @@ namespace GitHub.Runner.Worker // Set GITHUB_ACTION // Warning: Do not turn on FF DistributedTask.UseContextNameForGITHUBACTION until after M271-ish. After M271-ish // the server will never send an empty context name. Generated context names start with "__" - if (step.ExecutionContext.Variables.GetBoolean("DistributedTask.UseContextNameForGITHUBACTION") ?? false) + if (step.ExecutionContext.Global.Variables.GetBoolean("DistributedTask.UseContextNameForGITHUBACTION") ?? false) { step.ExecutionContext.SetGitHubContext("action", actionStep.Action.Name); } diff --git a/src/Test/L0/Worker/ActionCommandManagerL0.cs b/src/Test/L0/Worker/ActionCommandManagerL0.cs index 2ef9f5c5c..3cc1c5ceb 100644 --- a/src/Test/L0/Worker/ActionCommandManagerL0.cs +++ b/src/Test/L0/Worker/ActionCommandManagerL0.cs @@ -96,7 +96,7 @@ namespace GitHub.Runner.Common.Tests.Worker hc.GetTrace().Info($"{issue.Type} {issue.Message} {message ?? string.Empty}"); }); - _ec.Setup(x => x.EnvironmentVariables).Returns(new Dictionary()); + _ec.Object.Global.EnvironmentVariables = new Dictionary(); Assert.True(_commandManager.TryProcessCommand(_ec.Object, "##[stop-commands]stopToken", null)); Assert.False(_commandManager.TryProcessCommand(_ec.Object, "##[set-env name=foo]bar", null)); @@ -119,8 +119,6 @@ namespace GitHub.Runner.Common.Tests.Worker return 1; }); - _ec.SetupAllProperties(); - Assert.False(_ec.Object.EchoOnActionCommand); Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::echo::on", null)); @@ -204,8 +202,6 @@ namespace GitHub.Runner.Common.Tests.Worker return 1; }); - _ec.SetupAllProperties(); - // Echo commands below are considered "processed", but are invalid // 1. Invalid echo value Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::echo::invalid", null)); @@ -287,6 +283,8 @@ namespace GitHub.Runner.Common.Tests.Worker // Execution context _ec = new Mock(); + _ec.SetupAllProperties(); + _ec.Setup(x => x.Global).Returns(new GlobalContext()); // Command manager _commandManager = new ActionCommandManager(); diff --git a/src/Test/L0/Worker/ActionManagerL0.cs b/src/Test/L0/Worker/ActionManagerL0.cs index cfdd306e1..0481d9894 100644 --- a/src/Test/L0/Worker/ActionManagerL0.cs +++ b/src/Test/L0/Worker/ActionManagerL0.cs @@ -3575,17 +3575,18 @@ runs: _workFolder = _hc.GetDirectory(WellKnownDirectory.Work); _ec = new Mock(); + _ec.Setup(x => x.Global).Returns(new GlobalContext()); _ec.Setup(x => x.CancellationToken).Returns(_ecTokenSource.Token); var variables = new Dictionary(); if (newActionMetadata) { variables["DistributedTask.NewActionMetadata"] = "true"; } - _ec.Setup(x => x.Variables).Returns(new Variables(_hc, variables)); + _ec.Object.Global.Variables = new Variables(_hc, variables); _ec.Setup(x => x.ExpressionValues).Returns(new DictionaryContextData()); _ec.Setup(x => x.ExpressionFunctions).Returns(new List()); - _ec.Setup(x => x.FileTable).Returns(new List()); - _ec.Setup(x => x.Plan).Returns(new TaskOrchestrationPlanReference()); + _ec.Object.Global.FileTable = new List(); + _ec.Object.Global.Plan = new TaskOrchestrationPlanReference(); _ec.Setup(x => x.Write(It.IsAny(), It.IsAny())).Callback((string tag, string message) => { _hc.GetTrace().Info($"[{tag}]{message}"); }); _ec.Setup(x => x.AddIssue(It.IsAny(), It.IsAny())).Callback((Issue issue, string message) => { _hc.GetTrace().Info($"[{issue.Type}]{issue.Message ?? message}"); }); _ec.Setup(x => x.GetGitHubContext("workspace")).Returns(Path.Combine(_workFolder, "actions", "actions")); diff --git a/src/Test/L0/Worker/ActionManifestManagerL0.cs b/src/Test/L0/Worker/ActionManifestManagerL0.cs index 0f89f743c..264c41995 100644 --- a/src/Test/L0/Worker/ActionManifestManagerL0.cs +++ b/src/Test/L0/Worker/ActionManifestManagerL0.cs @@ -754,12 +754,16 @@ namespace GitHub.Runner.Common.Tests.Worker _hc = new TestHostContext(this, name); _ec = new Mock(); - _ec.Setup(x => x.WriteDebug).Returns(true); + _ec.Setup(x => x.Global) + .Returns(new GlobalContext + { + FileTable = new List(), + Variables = new Variables(_hc, new Dictionary()), + WriteDebug = true, + }); _ec.Setup(x => x.CancellationToken).Returns(_ecTokenSource.Token); - _ec.Setup(x => x.Variables).Returns(new Variables(_hc, new Dictionary())); _ec.Setup(x => x.ExpressionValues).Returns(new DictionaryContextData()); _ec.Setup(x => x.ExpressionFunctions).Returns(new List()); - _ec.Setup(x => x.FileTable).Returns(new List()); _ec.Setup(x => x.Write(It.IsAny(), It.IsAny())).Callback((string tag, string message) => { _hc.GetTrace().Info($"{tag}{message}"); }); _ec.Setup(x => x.AddIssue(It.IsAny(), It.IsAny())).Callback((Issue issue, string message) => { _hc.GetTrace().Info($"[{issue.Type}]{issue.Message ?? message}"); }); } diff --git a/src/Test/L0/Worker/ActionRunnerL0.cs b/src/Test/L0/Worker/ActionRunnerL0.cs index 1851f47d7..c5c6426e4 100644 --- a/src/Test/L0/Worker/ActionRunnerL0.cs +++ b/src/Test/L0/Worker/ActionRunnerL0.cs @@ -375,15 +375,16 @@ namespace GitHub.Runner.Common.Tests.Worker #endif _ec = new Mock(); + _ec.Setup(x => x.Global).Returns(new GlobalContext()); _ec.Setup(x => x.ExpressionValues).Returns(_context); _ec.Setup(x => x.ExpressionFunctions).Returns(new List()); _ec.Setup(x => x.IntraActionState).Returns(new Dictionary()); - _ec.Setup(x => x.EnvironmentVariables).Returns(new Dictionary()); - _ec.Setup(x => x.FileTable).Returns(new List()); + _ec.Object.Global.EnvironmentVariables = new Dictionary(); + _ec.Object.Global.FileTable = new List(); _ec.Setup(x => x.SetGitHubContext(It.IsAny(), It.IsAny())); _ec.Setup(x => x.GetGitHubContext(It.IsAny())).Returns("{\"foo\":\"bar\"}"); _ec.Setup(x => x.CancellationToken).Returns(_ecTokenSource.Token); - _ec.Setup(x => x.Variables).Returns(new Variables(_hc, new Dictionary())); + _ec.Object.Global.Variables = new Variables(_hc, new Dictionary()); _ec.Setup(x => x.Write(It.IsAny(), It.IsAny())).Callback((string tag, string message) => { _hc.GetTrace().Info($"[{tag}]{message}"); }); _ec.Setup(x => x.AddIssue(It.IsAny(), It.IsAny())).Callback((Issue issue, string message) => { _hc.GetTrace().Info($"[{issue.Type}]{issue.Message ?? message}"); }); diff --git a/src/Test/L0/Worker/ExecutionContextL0.cs b/src/Test/L0/Worker/ExecutionContextL0.cs index 356b7f4e5..0efd4bfe5 100644 --- a/src/Test/L0/Worker/ExecutionContextL0.cs +++ b/src/Test/L0/Worker/ExecutionContextL0.cs @@ -357,20 +357,20 @@ namespace GitHub.Runner.Common.Tests.Worker // Act. jobContext.InitializeJob(jobRequest, CancellationToken.None); - jobContext.StepsContext.SetConclusion(null, "step1", ActionResult.Success); - var conclusion1 = (jobContext.StepsContext.GetScope(null)["step1"] as DictionaryContextData)["conclusion"].ToString(); + jobContext.Global.StepsContext.SetConclusion(null, "step1", ActionResult.Success); + var conclusion1 = (jobContext.Global.StepsContext.GetScope(null)["step1"] as DictionaryContextData)["conclusion"].ToString(); Assert.Equal(conclusion1, conclusion1.ToLowerInvariant()); - jobContext.StepsContext.SetOutcome(null, "step2", ActionResult.Cancelled); - var outcome1 = (jobContext.StepsContext.GetScope(null)["step2"] as DictionaryContextData)["outcome"].ToString(); + jobContext.Global.StepsContext.SetOutcome(null, "step2", ActionResult.Cancelled); + var outcome1 = (jobContext.Global.StepsContext.GetScope(null)["step2"] as DictionaryContextData)["outcome"].ToString(); Assert.Equal(outcome1, outcome1.ToLowerInvariant()); - jobContext.StepsContext.SetConclusion(null, "step3", ActionResult.Failure); - var conclusion2 = (jobContext.StepsContext.GetScope(null)["step3"] as DictionaryContextData)["conclusion"].ToString(); + jobContext.Global.StepsContext.SetConclusion(null, "step3", ActionResult.Failure); + var conclusion2 = (jobContext.Global.StepsContext.GetScope(null)["step3"] as DictionaryContextData)["conclusion"].ToString(); Assert.Equal(conclusion2, conclusion2.ToLowerInvariant()); - jobContext.StepsContext.SetOutcome(null, "step4", ActionResult.Skipped); - var outcome2 = (jobContext.StepsContext.GetScope(null)["step4"] as DictionaryContextData)["outcome"].ToString(); + jobContext.Global.StepsContext.SetOutcome(null, "step4", ActionResult.Skipped); + var outcome2 = (jobContext.Global.StepsContext.GetScope(null)["step4"] as DictionaryContextData)["outcome"].ToString(); Assert.Equal(outcome2, outcome2.ToLowerInvariant()); jobContext.JobContext.Status = ActionResult.Success; diff --git a/src/Test/L0/Worker/OutputManagerL0.cs b/src/Test/L0/Worker/OutputManagerL0.cs index bcd2936f7..f02e2bf1e 100644 --- a/src/Test/L0/Worker/OutputManagerL0.cs +++ b/src/Test/L0/Worker/OutputManagerL0.cs @@ -955,12 +955,13 @@ namespace GitHub.Runner.Common.Tests.Worker _variables = new Variables(hostContext, new Dictionary()); _executionContext = new Mock(); - _executionContext.Setup(x => x.WriteDebug) - .Returns(true); - _executionContext.Setup(x => x.Variables) - .Returns(_variables); - _executionContext.Setup(x => x.Container) - .Returns(jobContainer); + _executionContext.Setup(x => x.Global) + .Returns(new GlobalContext + { + Container = jobContainer, + Variables = _variables, + WriteDebug = true, + }); _executionContext.Setup(x => x.GetMatchers()) .Returns(matchers?.Matchers ?? new List()); _executionContext.Setup(x => x.Add(It.IsAny())) diff --git a/src/Test/L0/Worker/PipelineDirectoryManagerL0.cs b/src/Test/L0/Worker/PipelineDirectoryManagerL0.cs index de0ac5be6..4cc6d4bca 100644 --- a/src/Test/L0/Worker/PipelineDirectoryManagerL0.cs +++ b/src/Test/L0/Worker/PipelineDirectoryManagerL0.cs @@ -203,6 +203,7 @@ namespace GitHub.Runner.Common.Tests.Worker // Setup the execution context. _ec = new Mock(); + _ec.Setup(x => x.Global).Returns(new GlobalContext()); GitHubContext githubContext = new GitHubContext(); _ec.Setup(x => x.GetGitHubContext("repository")).Returns("actions/runner"); diff --git a/src/Test/L0/Worker/StepsRunnerL0.cs b/src/Test/L0/Worker/StepsRunnerL0.cs index 2fde1bcb6..87ef812c3 100644 --- a/src/Test/L0/Worker/StepsRunnerL0.cs +++ b/src/Test/L0/Worker/StepsRunnerL0.cs @@ -38,7 +38,9 @@ namespace GitHub.Runner.Common.Tests.Worker }; _ec = new Mock(); _ec.SetupAllProperties(); - _ec.Setup(x => x.Variables).Returns(_variables); + _ec.Setup(x => x.Global).Returns(new GlobalContext { WriteDebug = true }); + _ec.Object.Global.Variables = _variables; + _ec.Object.Global.EnvironmentVariables = _env; _contexts = new DictionaryContextData(); _jobContext = new JobContext(); @@ -50,7 +52,7 @@ namespace GitHub.Runner.Common.Tests.Worker _ec.Setup(x => x.JobContext).Returns(_jobContext); _stepContext = new StepsContext(); - _ec.Setup(x => x.StepsContext).Returns(_stepContext); + _ec.Object.Global.StepsContext = _stepContext; _ec.Setup(x => x.PostJobSteps).Returns(new Stack()); @@ -599,13 +601,10 @@ namespace GitHub.Runner.Common.Tests.Worker // Setup the step execution context. var stepContext = new Mock(); stepContext.SetupAllProperties(); - stepContext.Setup(x => x.WriteDebug).Returns(true); - stepContext.Setup(x => x.Variables).Returns(_variables); - stepContext.Setup(x => x.EnvironmentVariables).Returns(_env); + stepContext.Setup(x => x.Global).Returns(() => _ec.Object.Global); stepContext.Setup(x => x.ExpressionValues).Returns(new DictionaryContextData()); stepContext.Setup(x => x.ExpressionFunctions).Returns(new List()); stepContext.Setup(x => x.JobContext).Returns(_jobContext); - stepContext.Setup(x => x.StepsContext).Returns(_stepContext); stepContext.Setup(x => x.ContextName).Returns(step.Object.Action.ContextName); stepContext.Setup(x => x.Complete(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((TaskResult? r, string currentOperation, string resultCode) =>