From faf826d15a6b602566ec009a1e94a94f921cffbe Mon Sep 17 00:00:00 2001 From: Ethan Chiu Date: Fri, 24 Jul 2020 15:46:19 -0400 Subject: [PATCH] ah --- src/Runner.Worker/ActionRunner.cs | 3 +++ src/Runner.Worker/ExecutionContext.cs | 9 +++------ src/Runner.Worker/GitHubContext.cs | 1 + src/Runner.Worker/Handlers/CompositeActionHandler.cs | 12 ++++++++++-- src/Runner.Worker/Handlers/ScriptHandler.cs | 5 +++++ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 8a12b9561..952b6267e 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -135,6 +135,9 @@ namespace GitHub.Runner.Worker ExecutionContext.SetGitHubContext("event_path", workflowFile); } + var gitHubActionPath = ExecutionContext.GetGitHubContext("action_path"); + Trace.Info($"githubactionpath: {gitHubActionPath}"); + // Setup container stephost for running inside the container. if (ExecutionContext.Global.Container != null) { diff --git a/src/Runner.Worker/ExecutionContext.cs b/src/Runner.Worker/ExecutionContext.cs index 370960b07..b7740f3c9 100644 --- a/src/Runner.Worker/ExecutionContext.cs +++ b/src/Runner.Worker/ExecutionContext.cs @@ -98,7 +98,7 @@ namespace GitHub.Runner.Worker // others void ForceTaskComplete(); void RegisterPostJobStep(IStep step); - IStep CreateCompositeStep(string scopeName, IActionRunner step, DictionaryContextData inputsData, Dictionary envData, string actionDirectory); + IStep CreateCompositeStep(string scopeName, IActionRunner step, DictionaryContextData inputsData, Dictionary envData); } public sealed class ExecutionContext : RunnerService, IExecutionContext @@ -258,8 +258,7 @@ namespace GitHub.Runner.Worker string scopeName, IActionRunner step, DictionaryContextData inputsData, - Dictionary envData, - string actionDirectory) + Dictionary envData) { step.ExecutionContext = Root.CreateChild(_record.Id, step.DisplayName, _record.Id.ToString("N"), scopeName, step.Action.ContextName, logger: _logger, insideComposite: true, cancellationTokenSource: CancellationTokenSource.CreateLinkedTokenSource(_cancellationTokenSource.Token)); step.ExecutionContext.ExpressionValues["inputs"] = inputsData; @@ -276,9 +275,6 @@ namespace GitHub.Runner.Worker envContext[pair.Key] = new StringContextData(pair.Value ?? string.Empty); } - // Add path to action directory as an environment variable. - envContext["GITHUB_ACTION_PATH"] = new StringContextData(actionDirectory); - step.ExecutionContext.ExpressionValues["env"] = envContext; return step; @@ -425,6 +421,7 @@ namespace GitHub.Runner.Worker ArgUtil.NotNullOrEmpty(name, nameof(name)); var githubContext = ExpressionValues["github"] as GitHubContext; githubContext[name] = new StringContextData(value); + Trace.Info($"GitHub Context: {StringUtil.ConvertToJson(githubContext)}"); } public string GetGitHubContext(string name) diff --git a/src/Runner.Worker/GitHubContext.cs b/src/Runner.Worker/GitHubContext.cs index ac6566ad9..1ecca19f0 100644 --- a/src/Runner.Worker/GitHubContext.cs +++ b/src/Runner.Worker/GitHubContext.cs @@ -9,6 +9,7 @@ namespace GitHub.Runner.Worker private readonly HashSet _contextEnvWhitelist = new HashSet(StringComparer.OrdinalIgnoreCase) { "action", + "action_path", "actor", "api_url", "base_ref", diff --git a/src/Runner.Worker/Handlers/CompositeActionHandler.cs b/src/Runner.Worker/Handlers/CompositeActionHandler.cs index 8dc8b9213..354820f55 100644 --- a/src/Runner.Worker/Handlers/CompositeActionHandler.cs +++ b/src/Runner.Worker/Handlers/CompositeActionHandler.cs @@ -56,6 +56,10 @@ namespace GitHub.Runner.Worker.Handlers childScopeName = $"__{Guid.NewGuid()}"; } + // Set GITHUB_ACTION_PATH + Trace.Info($"ActionDirectory: {ActionDirectory}"); + ExecutionContext.SetGitHubContext("action_path", ActionDirectory); + foreach (Pipelines.ActionStep actionStep in actionSteps) { var actionRunner = HostContext.CreateService(); @@ -63,7 +67,10 @@ namespace GitHub.Runner.Worker.Handlers actionRunner.Stage = stage; actionRunner.Condition = actionStep.Condition; - var step = ExecutionContext.CreateCompositeStep(childScopeName, actionRunner, inputsData, Environment, ActionDirectory); + var step = ExecutionContext.CreateCompositeStep(childScopeName, actionRunner, inputsData, Environment); + + // step.ExecutionContext.ExpressionValues["github"] = ExecutionContext.ExpressionValues["github"] as GitHubContext; + compositeSteps.Add(step); } @@ -177,7 +184,8 @@ namespace GitHub.Runner.Worker.Handlers var actionStep = step as IActionRunner; // Set GITHUB_ACTION - step.ExecutionContext.SetGitHubContext("action", step.ExecutionContext.GetFullyQualifiedContextName()); + // For composite + their nested steps, we want the all of them to have the same GITHUB_ACTION + step.ExecutionContext.SetGitHubContext("action", ExecutionContext.GetGitHubContext("action")); try { diff --git a/src/Runner.Worker/Handlers/ScriptHandler.cs b/src/Runner.Worker/Handlers/ScriptHandler.cs index 397d9a176..c30bffca5 100644 --- a/src/Runner.Worker/Handlers/ScriptHandler.cs +++ b/src/Runner.Worker/Handlers/ScriptHandler.cs @@ -265,6 +265,11 @@ namespace GitHub.Runner.Worker.Handlers { foreach (var env in runtimeContext.GetRuntimeEnvironmentVariables()) { + if (runtimeContext is GitHubContext) + { + Trace.Info($"gh context key: {env.Key}"); + Trace.Info($"gh context Value: {env.Value}"); + } Environment[env.Key] = env.Value; } }