From f30a83a4b7f298cb7beff55e45719e7269fd5539 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Mon, 13 Mar 2023 10:00:46 -0400 Subject: [PATCH 01/26] adding extra catch for download failure in composite actions --- src/Runner.Worker/ActionManager.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 49e14e68ae3..80b3372852f 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -682,12 +682,14 @@ private async Task BuildActionContainerAsync(IExecutionContext executionContext, // * Repo or tag doesn't exist, or isn't public // * Policy validation failed if (ex is WebApi.UnresolvableActionDownloadInfoException) - { + { // Log the error and fail the JobExtension Initialization. throw; } else { // This exception will be traced as an infrastructure failure + Trace.Error($"Caught exception from JobExtenion Initialization: {ex}"); + executionContext.InfrastructureError(ex.Message); throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info.", ex); } } From f1bfabc06770e2b7b44e6d2d6176bde569fde2a9 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Fri, 17 Mar 2023 11:03:01 -0400 Subject: [PATCH 02/26] Adding infra error --- src/Runner.Worker/ActionManager.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 80b3372852f..de89d8e5189 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -272,7 +272,7 @@ public sealed class ActionManager : RunnerService, IActionManager } else if (depth > 0) { - // if we're in a composite action and haven't loaded the local action yet + // if we're in a © action and haven't loaded the local action yet // we assume it has a post step if (!_cachedEmbeddedPostSteps.ContainsKey(parentStepId)) { @@ -683,6 +683,8 @@ private async Task BuildActionContainerAsync(IExecutionContext executionContext, // * Policy validation failed if (ex is WebApi.UnresolvableActionDownloadInfoException) { // Log the error and fail the JobExtension Initialization. + Trace.Error($"Caught exception from JobExtenion Initialization: {ex}"); + executionContext.InfrastructureError(ex.Message); throw; } else From b7773454d337cac9a044e3485a2f4315de92528a Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Mon, 20 Mar 2023 11:50:22 -0400 Subject: [PATCH 03/26] Adding error handling centralizing --- src/Runner.Worker/ActionManager.cs | 9 ++++----- src/Runner.Worker/ActionRunner.cs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index de89d8e5189..7ef1b19720b 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -682,15 +682,14 @@ private async Task BuildActionContainerAsync(IExecutionContext executionContext, // * Repo or tag doesn't exist, or isn't public // * Policy validation failed if (ex is WebApi.UnresolvableActionDownloadInfoException) - { // Log the error and fail the JobExtension Initialization. - Trace.Error($"Caught exception from JobExtenion Initialization: {ex}"); - executionContext.InfrastructureError(ex.Message); - throw; + { // Log the error as user error + Trace.Error($"Caught exception from ActionDownloadInfoCollection: {ex}"); + throw new WebApi.UnresolvableActionDownloadInfoException("Failed to resolve action download info.", ex); } else { // This exception will be traced as an infrastructure failure - Trace.Error($"Caught exception from JobExtenion Initialization: {ex}"); + Trace.Error($"Caught exception from ActionDownloadInfoCollection Initialization: {ex}"); executionContext.InfrastructureError(ex.Message); throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info.", ex); } diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 62fbbb812d6..e2567538798 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -10,6 +10,7 @@ using GitHub.Runner.Common.Util; using GitHub.Runner.Sdk; using GitHub.Runner.Worker.Handlers; +using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; namespace GitHub.Runner.Worker @@ -89,7 +90,18 @@ Action.Reference is Pipelines.RepositoryPathReference localAction && string.Equals(localAction.RepositoryType, Pipelines.PipelineConstants.SelfAlias, StringComparison.OrdinalIgnoreCase)) { var actionManager = HostContext.GetService(); - var prepareResult = await actionManager.PrepareActionsAsync(ExecutionContext, compositeHandlerData.Steps, ExecutionContext.Id); + var prepareResult = default(PrepareResult); + try + { + prepareResult = await actionManager.PrepareActionsAsync(ExecutionContext, compositeHandlerData.Steps, ExecutionContext.Id); + } + catch (Exception ex){ + if(ex is WebApi.UnresolvableActionDownloadInfoException){ + Trace.Error($"Caught exception from ActionDownloadInfoCollection Initialization: {ex}"); + ExecutionContext.InfrastructureError(ex.Message); + throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info.", ex); + } + } // Reload definition since post may exist now (from embedded steps that were JIT downloaded) definition = taskManager.LoadAction(ExecutionContext, Action); From 88cf005ece0f28d51e5ec57662c0691c4ac49faa Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Tue, 28 Mar 2023 12:53:40 -0400 Subject: [PATCH 04/26] updating try catch bubbling --- src/Runner.Listener/JobDispatcher.cs | 2 +- src/Runner.Worker/ActionManager.cs | 98 ++++++++++++------- src/Runner.Worker/ActionRunner.cs | 21 ++-- .../Handlers/CompositeActionHandler.cs | 1 - src/Runner.Worker/JobExtension.cs | 12 ++- src/Runner.Worker/StepsRunner.cs | 2 +- src/Runner.Worker/Worker.cs | 2 +- src/Test/L0/Worker/ActionManagerL0.cs | 2 +- 8 files changed, 90 insertions(+), 50 deletions(-) diff --git a/src/Runner.Listener/JobDispatcher.cs b/src/Runner.Listener/JobDispatcher.cs index 53380b9b220..40216e5343a 100644 --- a/src/Runner.Listener/JobDispatcher.cs +++ b/src/Runner.Listener/JobDispatcher.cs @@ -1303,4 +1303,4 @@ private void Dispose(bool disposing) } } } -} +} \ No newline at end of file diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 7ef1b19720b..16a646cdfeb 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -100,43 +100,57 @@ public sealed class ActionManager : RunnerService, IActionManager } IEnumerable actions = steps.OfType(); executionContext.Output("Prepare all required actions"); - var result = await PrepareActionsRecursiveAsync(executionContext, state, actions, depth, rootStepId); - if (!FeatureManager.IsContainerHooksEnabled(executionContext.Global.Variables)) + PrepareActionsState result = default(PrepareActionsState); + try { - if (state.ImagesToPull.Count > 0) + result = await PrepareActionsRecursiveAsync(executionContext, state, actions, depth, rootStepId); + + if (!FeatureManager.IsContainerHooksEnabled(executionContext.Global.Variables)) { - foreach (var imageToPull in result.ImagesToPull) + if (state.ImagesToPull.Count > 0) { - Trace.Info($"{imageToPull.Value.Count} steps need to pull image '{imageToPull.Key}'"); - containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.PullActionContainerAsync, - condition: $"{PipelineTemplateConstants.Success}()", - displayName: $"Pull {imageToPull.Key}", - data: new ContainerSetupInfo(imageToPull.Value, imageToPull.Key))); + foreach (var imageToPull in result.ImagesToPull) + { + Trace.Info($"{imageToPull.Value.Count} steps need to pull image '{imageToPull.Key}'"); + containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.PullActionContainerAsync, + condition: $"{PipelineTemplateConstants.Success}()", + displayName: $"Pull {imageToPull.Key}", + data: new ContainerSetupInfo(imageToPull.Value, imageToPull.Key))); + } } - } - if (result.ImagesToBuild.Count > 0) - { - foreach (var imageToBuild in result.ImagesToBuild) + if (result?.ImagesToBuild.Count > 0) { - var setupInfo = result.ImagesToBuildInfo[imageToBuild.Key]; - Trace.Info($"{imageToBuild.Value.Count} steps need to build image from '{setupInfo.Dockerfile}'"); - containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.BuildActionContainerAsync, - condition: $"{PipelineTemplateConstants.Success}()", - displayName: $"Build {setupInfo.ActionRepository}", - data: new ContainerSetupInfo(imageToBuild.Value, setupInfo.Dockerfile, setupInfo.WorkingDirectory))); + foreach (var imageToBuild in result.ImagesToBuild) + { + var setupInfo = result.ImagesToBuildInfo[imageToBuild.Key]; + Trace.Info($"{imageToBuild.Value.Count} steps need to build image from '{setupInfo.Dockerfile}'"); + containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.BuildActionContainerAsync, + condition: $"{PipelineTemplateConstants.Success}()", + displayName: $"Build {setupInfo.ActionRepository}", + data: new ContainerSetupInfo(imageToBuild.Value, setupInfo.Dockerfile, setupInfo.WorkingDirectory))); + } } - } #if !OS_LINUX - if (containerSetupSteps.Count > 0) + if (containerSetupSteps.Count > 0) + { + executionContext.Output("Container action is only supported on Linux, skip pull and build docker images."); + containerSetupSteps.Clear(); + } +#endif + } + return new PrepareResult(containerSetupSteps, result?.PreStepTracker); + + } + catch (Exception ex) + { + if (ex is WebApi.FailedToResolveActionDownloadInfoException) { - executionContext.Output("Container action is only supported on Linux, skip pull and build docker images."); - containerSetupSteps.Clear(); + throw; } -#endif } - return new PrepareResult(containerSetupSteps, result.PreStepTracker); + return null; } private async Task PrepareActionsRecursiveAsync(IExecutionContext executionContext, PrepareActionsState state, IEnumerable actions, Int32 depth = 0, Guid parentStepId = default(Guid)) @@ -174,7 +188,26 @@ public sealed class ActionManager : RunnerService, IActionManager if (repositoryActions.Count > 0) { // Get the download info - var downloadInfos = await GetDownloadInfoAsync(executionContext, repositoryActions); + var downloadInfos = new Dictionary + { + ["patterns"] = new WebApi.ActionDownloadInfo() + }; + + try + { + downloadInfos.Clear(); + if (downloadInfos.Count == 0) + { + downloadInfos = (Dictionary)await GetDownloadInfoAsync(executionContext, repositoryActions); + + } + + } + catch + { + throw; + // throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info.", ex); + } // Download each action foreach (var action in repositoryActions) @@ -272,7 +305,7 @@ public sealed class ActionManager : RunnerService, IActionManager } else if (depth > 0) { - // if we're in a © action and haven't loaded the local action yet + // if we're in a composite action and haven't loaded the local action yet // we assume it has a post step if (!_cachedEmbeddedPostSteps.ContainsKey(parentStepId)) { @@ -655,6 +688,7 @@ private async Task BuildActionContainerAsync(IExecutionContext executionContext, try { actionDownloadInfos = await jobServer.ResolveActionDownloadInfoAsync(executionContext.Global.Plan.ScopeIdentifier, executionContext.Global.Plan.PlanType, executionContext.Global.Plan.PlanId, executionContext.Root.Id, new WebApi.ActionReferenceList { Actions = actionReferences }, executionContext.CancellationToken); + // throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info"); break; } catch (Exception ex) when (!executionContext.CancellationToken.IsCancellationRequested) // Do not retry if the run is cancelled. @@ -682,15 +716,13 @@ private async Task BuildActionContainerAsync(IExecutionContext executionContext, // * Repo or tag doesn't exist, or isn't public // * Policy validation failed if (ex is WebApi.UnresolvableActionDownloadInfoException) - { // Log the error as user error - Trace.Error($"Caught exception from ActionDownloadInfoCollection: {ex}"); - throw new WebApi.UnresolvableActionDownloadInfoException("Failed to resolve action download info.", ex); + { + throw new WebApi.UnresolvableActionDownloadInfoException("Unable to resolve action download info", ex); + // throw; } else { // This exception will be traced as an infrastructure failure - Trace.Error($"Caught exception from ActionDownloadInfoCollection Initialization: {ex}"); - executionContext.InfrastructureError(ex.Message); throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info.", ex); } } @@ -1310,4 +1342,4 @@ public class PrepareActionsState public Dictionary ImagesToBuildInfo; public Dictionary PreStepTracker; } -} +} \ No newline at end of file diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index e2567538798..37b36f51a86 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -12,6 +12,7 @@ using GitHub.Runner.Worker.Handlers; using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; +using System.Threading; namespace GitHub.Runner.Worker { @@ -90,16 +91,16 @@ Action.Reference is Pipelines.RepositoryPathReference localAction && string.Equals(localAction.RepositoryType, Pipelines.PipelineConstants.SelfAlias, StringComparison.OrdinalIgnoreCase)) { var actionManager = HostContext.GetService(); - var prepareResult = default(PrepareResult); - try + PrepareResult prepareResult = default(PrepareResult); + try { - prepareResult = await actionManager.PrepareActionsAsync(ExecutionContext, compositeHandlerData.Steps, ExecutionContext.Id); - } - catch (Exception ex){ - if(ex is WebApi.UnresolvableActionDownloadInfoException){ - Trace.Error($"Caught exception from ActionDownloadInfoCollection Initialization: {ex}"); - ExecutionContext.InfrastructureError(ex.Message); - throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info.", ex); + prepareResult = await actionManager.PrepareActionsAsync(ExecutionContext, compositeHandlerData.Steps, ExecutionContext.Id); + } + catch (Exception ex) + { + if (ex is WebApi.FailedToResolveActionDownloadInfoException) + { + throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info", ex); } } @@ -469,4 +470,4 @@ private static string FormatStepName(string prefix, string stepName) return $"{prefix}{result}"; } } -} +} \ No newline at end of file diff --git a/src/Runner.Worker/Handlers/CompositeActionHandler.cs b/src/Runner.Worker/Handlers/CompositeActionHandler.cs index 4cc54af41c6..8169f015dec 100644 --- a/src/Runner.Worker/Handlers/CompositeActionHandler.cs +++ b/src/Runner.Worker/Handlers/CompositeActionHandler.cs @@ -161,7 +161,6 @@ public async Task RunAsync(ActionRunStage stage) embeddedSteps.Add(step); } - // Run embedded steps await RunStepsAsync(embeddedSteps, stage); diff --git a/src/Runner.Worker/JobExtension.cs b/src/Runner.Worker/JobExtension.cs index 580c9999dd7..0ee86616417 100644 --- a/src/Runner.Worker/JobExtension.cs +++ b/src/Runner.Worker/JobExtension.cs @@ -253,8 +253,16 @@ public async Task> InitializeJob(IExecutionContext jobContext, Pipel // Download actions not already in the cache Trace.Info("Downloading actions"); var actionManager = HostContext.GetService(); - var prepareResult = await actionManager.PrepareActionsAsync(context, message.Steps); + var prepareResult = default(PrepareResult); + try + { + prepareResult = await actionManager.PrepareActionsAsync(context, message.Steps); + } + catch + { + throw; + } // add hook to preJobSteps var startedHookPath = Environment.GetEnvironmentVariable("ACTIONS_RUNNER_HOOK_JOB_STARTED"); if (!string.IsNullOrEmpty(startedHookPath)) @@ -730,4 +738,4 @@ private static void ValidateJobContainer(JobContainer container) } } } -} +} \ No newline at end of file diff --git a/src/Runner.Worker/StepsRunner.cs b/src/Runner.Worker/StepsRunner.cs index 05d21d4bb06..4096a0f6b3b 100644 --- a/src/Runner.Worker/StepsRunner.cs +++ b/src/Runner.Worker/StepsRunner.cs @@ -335,4 +335,4 @@ private void CompleteStep(IStep step, TaskResult? result = null, string resultCo executionContext.Complete(result, resultCode: resultCode); } } -} +} \ No newline at end of file diff --git a/src/Runner.Worker/Worker.cs b/src/Runner.Worker/Worker.cs index 4784c169314..4616baf849a 100644 --- a/src/Runner.Worker/Worker.cs +++ b/src/Runner.Worker/Worker.cs @@ -219,4 +219,4 @@ private void Worker_Unloading(object sender, EventArgs e) } } } -} +} \ No newline at end of file diff --git a/src/Test/L0/Worker/ActionManagerL0.cs b/src/Test/L0/Worker/ActionManagerL0.cs index 07cf9b48700..acb51d5c83b 100644 --- a/src/Test/L0/Worker/ActionManagerL0.cs +++ b/src/Test/L0/Worker/ActionManagerL0.cs @@ -923,7 +923,7 @@ public async void PrepareActions_CompositeActionWithActionfile_MaxLimit() //Act Func result = async () => await _actionManager.PrepareActionsAsync(_ec.Object, actions); - + Assert.NotNull(result); //Assert var exception = await Assert.ThrowsAsync(result); Assert.Equal($"Composite action depth exceeded max depth {Constants.CompositeActionsMaxDepth}", exception.Message); From 4c6982bc9533afa059557a8084dd9d9e6a411f68 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Tue, 28 Mar 2023 13:07:48 -0400 Subject: [PATCH 05/26] cleaning up commits --- src/Runner.Listener/JobDispatcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Runner.Listener/JobDispatcher.cs b/src/Runner.Listener/JobDispatcher.cs index 40216e5343a..53380b9b220 100644 --- a/src/Runner.Listener/JobDispatcher.cs +++ b/src/Runner.Listener/JobDispatcher.cs @@ -1303,4 +1303,4 @@ private void Dispose(bool disposing) } } } -} \ No newline at end of file +} From 3068f6546906ee03d3eff0c3a54b42e96aeaf8fe Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Tue, 28 Mar 2023 13:16:22 -0400 Subject: [PATCH 06/26] cleaning up commits --- src/Runner.Worker/StepsRunner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Runner.Worker/StepsRunner.cs b/src/Runner.Worker/StepsRunner.cs index 4096a0f6b3b..05d21d4bb06 100644 --- a/src/Runner.Worker/StepsRunner.cs +++ b/src/Runner.Worker/StepsRunner.cs @@ -335,4 +335,4 @@ private void CompleteStep(IStep step, TaskResult? result = null, string resultCo executionContext.Complete(result, resultCode: resultCode); } } -} \ No newline at end of file +} From e70526a05cbb9af3d0165a11e3eb37d149421d3d Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Tue, 28 Mar 2023 13:17:44 -0400 Subject: [PATCH 07/26] cleaning up commits --- src/Runner.Worker/Worker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Runner.Worker/Worker.cs b/src/Runner.Worker/Worker.cs index 4616baf849a..4784c169314 100644 --- a/src/Runner.Worker/Worker.cs +++ b/src/Runner.Worker/Worker.cs @@ -219,4 +219,4 @@ private void Worker_Unloading(object sender, EventArgs e) } } } -} \ No newline at end of file +} From c81633337e8902ea18c361b2f4e5675c5e0d39d0 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Tue, 28 Mar 2023 14:21:12 -0400 Subject: [PATCH 08/26] updating bubbler --- src/Runner.Worker/ActionManager.cs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 16a646cdfeb..fc7d2c9aabc 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -100,7 +100,7 @@ public sealed class ActionManager : RunnerService, IActionManager } IEnumerable actions = steps.OfType(); executionContext.Output("Prepare all required actions"); - PrepareActionsState result = default(PrepareActionsState); + PrepareActionsState result = new PrepareActionsState(); try { result = await PrepareActionsRecursiveAsync(executionContext, state, actions, depth, rootStepId); @@ -119,7 +119,7 @@ public sealed class ActionManager : RunnerService, IActionManager } } - if (result?.ImagesToBuild.Count > 0) + if (result.ImagesToBuild.Count > 0) { foreach (var imageToBuild in result.ImagesToBuild) { @@ -140,17 +140,16 @@ public sealed class ActionManager : RunnerService, IActionManager } #endif } - return new PrepareResult(containerSetupSteps, result?.PreStepTracker); + return new PrepareResult(containerSetupSteps, result.PreStepTracker); } - catch (Exception ex) + catch (Exception) { - if (ex is WebApi.FailedToResolveActionDownloadInfoException) - { - throw; - } + + throw; + + // return null; } - return null; } private async Task PrepareActionsRecursiveAsync(IExecutionContext executionContext, PrepareActionsState state, IEnumerable actions, Int32 depth = 0, Guid parentStepId = default(Guid)) @@ -205,8 +204,8 @@ public sealed class ActionManager : RunnerService, IActionManager } catch { + // bubble up for handling in main caller throw; - // throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info.", ex); } // Download each action @@ -688,7 +687,6 @@ private async Task BuildActionContainerAsync(IExecutionContext executionContext, try { actionDownloadInfos = await jobServer.ResolveActionDownloadInfoAsync(executionContext.Global.Plan.ScopeIdentifier, executionContext.Global.Plan.PlanType, executionContext.Global.Plan.PlanId, executionContext.Root.Id, new WebApi.ActionReferenceList { Actions = actionReferences }, executionContext.CancellationToken); - // throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info"); break; } catch (Exception ex) when (!executionContext.CancellationToken.IsCancellationRequested) // Do not retry if the run is cancelled. From da6ceb140a9af254f7325f540ff315c49b8fa855 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Tue, 28 Mar 2023 14:22:38 -0400 Subject: [PATCH 09/26] cleaning up test files --- src/Test/L0/Worker/ActionManagerL0.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Test/L0/Worker/ActionManagerL0.cs b/src/Test/L0/Worker/ActionManagerL0.cs index acb51d5c83b..07cf9b48700 100644 --- a/src/Test/L0/Worker/ActionManagerL0.cs +++ b/src/Test/L0/Worker/ActionManagerL0.cs @@ -923,7 +923,7 @@ public async void PrepareActions_CompositeActionWithActionfile_MaxLimit() //Act Func result = async () => await _actionManager.PrepareActionsAsync(_ec.Object, actions); - Assert.NotNull(result); + //Assert var exception = await Assert.ThrowsAsync(result); Assert.Equal($"Composite action depth exceeded max depth {Constants.CompositeActionsMaxDepth}", exception.Message); From 4681f1d8915c4f66b6fa9dde068049ec208aaf4b Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Tue, 28 Mar 2023 14:46:52 -0400 Subject: [PATCH 10/26] Fixing linting errors --- src/Runner.Worker/ActionManager.cs | 2 +- src/Runner.Worker/ActionRunner.cs | 2 +- src/Runner.Worker/JobExtension.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index fc7d2c9aabc..596a7fc71f2 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -1340,4 +1340,4 @@ public class PrepareActionsState public Dictionary ImagesToBuildInfo; public Dictionary PreStepTracker; } -} \ No newline at end of file +} diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 37b36f51a86..3c45e6bdc3b 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -470,4 +470,4 @@ private static string FormatStepName(string prefix, string stepName) return $"{prefix}{result}"; } } -} \ No newline at end of file +} diff --git a/src/Runner.Worker/JobExtension.cs b/src/Runner.Worker/JobExtension.cs index 0ee86616417..a7518d40cf0 100644 --- a/src/Runner.Worker/JobExtension.cs +++ b/src/Runner.Worker/JobExtension.cs @@ -738,4 +738,4 @@ private static void ValidateJobContainer(JobContainer container) } } } -} \ No newline at end of file +} From d8b1a84eb89664af8c1fc2b2ab734432f19c0cce Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Wed, 29 Mar 2023 11:38:01 -0400 Subject: [PATCH 11/26] updating exception bubble --- src/Runner.Worker/ActionManager.cs | 91 +++++++++++++----------------- src/Runner.Worker/JobExtension.cs | 18 +----- 2 files changed, 40 insertions(+), 69 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 596a7fc71f2..7f7d594e375 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -17,6 +17,7 @@ using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; using PipelineTemplateConstants = GitHub.DistributedTask.Pipelines.ObjectTemplating.PipelineTemplateConstants; +using GitHub.DistributedTask.WebApi; namespace GitHub.Runner.Worker { @@ -105,51 +106,54 @@ public sealed class ActionManager : RunnerService, IActionManager { result = await PrepareActionsRecursiveAsync(executionContext, state, actions, depth, rootStepId); - if (!FeatureManager.IsContainerHooksEnabled(executionContext.Global.Variables)) + } + catch (FailedToResolveActionDownloadInfoException ex) + { + // Log the error and fail the PrepareActionsAsync Initialization. + Trace.Error($"Caught exception from PrepareActionsAsync Initialization: {ex}"); + executionContext.InfrastructureError(ex.Message); + executionContext.Result = TaskResult.Failed; + throw; + } + + if (!FeatureManager.IsContainerHooksEnabled(executionContext.Global.Variables)) + { + if (state.ImagesToPull.Count > 0) { - if (state.ImagesToPull.Count > 0) + foreach (var imageToPull in result.ImagesToPull) { - foreach (var imageToPull in result.ImagesToPull) - { - Trace.Info($"{imageToPull.Value.Count} steps need to pull image '{imageToPull.Key}'"); - containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.PullActionContainerAsync, - condition: $"{PipelineTemplateConstants.Success}()", - displayName: $"Pull {imageToPull.Key}", - data: new ContainerSetupInfo(imageToPull.Value, imageToPull.Key))); - } + Trace.Info($"{imageToPull.Value.Count} steps need to pull image '{imageToPull.Key}'"); + containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.PullActionContainerAsync, + condition: $"{PipelineTemplateConstants.Success}()", + displayName: $"Pull {imageToPull.Key}", + data: new ContainerSetupInfo(imageToPull.Value, imageToPull.Key))); } + } - if (result.ImagesToBuild.Count > 0) + if (result.ImagesToBuild.Count > 0) + { + foreach (var imageToBuild in result.ImagesToBuild) { - foreach (var imageToBuild in result.ImagesToBuild) - { - var setupInfo = result.ImagesToBuildInfo[imageToBuild.Key]; - Trace.Info($"{imageToBuild.Value.Count} steps need to build image from '{setupInfo.Dockerfile}'"); - containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.BuildActionContainerAsync, - condition: $"{PipelineTemplateConstants.Success}()", - displayName: $"Build {setupInfo.ActionRepository}", - data: new ContainerSetupInfo(imageToBuild.Value, setupInfo.Dockerfile, setupInfo.WorkingDirectory))); - } + var setupInfo = result.ImagesToBuildInfo[imageToBuild.Key]; + Trace.Info($"{imageToBuild.Value.Count} steps need to build image from '{setupInfo.Dockerfile}'"); + containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.BuildActionContainerAsync, + condition: $"{PipelineTemplateConstants.Success}()", + displayName: $"Build {setupInfo.ActionRepository}", + data: new ContainerSetupInfo(imageToBuild.Value, setupInfo.Dockerfile, setupInfo.WorkingDirectory))); } + } #if !OS_LINUX - if (containerSetupSteps.Count > 0) - { - executionContext.Output("Container action is only supported on Linux, skip pull and build docker images."); - containerSetupSteps.Clear(); - } -#endif + if (containerSetupSteps.Count > 0) + { + executionContext.Output("Container action is only supported on Linux, skip pull and build docker images."); + containerSetupSteps.Clear(); } - return new PrepareResult(containerSetupSteps, result.PreStepTracker); - +#endif } - catch (Exception) - { + return new PrepareResult(containerSetupSteps, result.PreStepTracker); - throw; - // return null; - } } private async Task PrepareActionsRecursiveAsync(IExecutionContext executionContext, PrepareActionsState state, IEnumerable actions, Int32 depth = 0, Guid parentStepId = default(Guid)) @@ -186,27 +190,8 @@ public sealed class ActionManager : RunnerService, IActionManager if (repositoryActions.Count > 0) { - // Get the download info - var downloadInfos = new Dictionary - { - ["patterns"] = new WebApi.ActionDownloadInfo() - }; - try - { - downloadInfos.Clear(); - if (downloadInfos.Count == 0) - { - downloadInfos = (Dictionary)await GetDownloadInfoAsync(executionContext, repositoryActions); - - } - } - catch - { - // bubble up for handling in main caller - throw; - } // Download each action foreach (var action in repositoryActions) @@ -216,6 +201,8 @@ public sealed class ActionManager : RunnerService, IActionManager { continue; } + // Get the download info + var downloadInfos = await GetDownloadInfoAsync(executionContext, repositoryActions); if (!downloadInfos.TryGetValue(lookupKey, out var downloadInfo)) { diff --git a/src/Runner.Worker/JobExtension.cs b/src/Runner.Worker/JobExtension.cs index a7518d40cf0..51517c6b4f7 100644 --- a/src/Runner.Worker/JobExtension.cs +++ b/src/Runner.Worker/JobExtension.cs @@ -253,16 +253,8 @@ public async Task> InitializeJob(IExecutionContext jobContext, Pipel // Download actions not already in the cache Trace.Info("Downloading actions"); var actionManager = HostContext.GetService(); - var prepareResult = default(PrepareResult); - try - { - prepareResult = await actionManager.PrepareActionsAsync(context, message.Steps); + var prepareResult = await actionManager.PrepareActionsAsync(context, message.Steps); - } - catch - { - throw; - } // add hook to preJobSteps var startedHookPath = Environment.GetEnvironmentVariable("ACTIONS_RUNNER_HOOK_JOB_STARTED"); if (!string.IsNullOrEmpty(startedHookPath)) @@ -439,14 +431,6 @@ public async Task> InitializeJob(IExecutionContext jobContext, Pipel context.Result = TaskResult.Canceled; throw; } - catch (FailedToResolveActionDownloadInfoException ex) - { - // Log the error and fail the JobExtension Initialization. - Trace.Error($"Caught exception from JobExtenion Initialization: {ex}"); - context.InfrastructureError(ex.Message); - context.Result = TaskResult.Failed; - throw; - } catch (Exception ex) { // Log the error and fail the JobExtension Initialization. From 290688fcaa4bd4299646d1baf32beab354e5c3b2 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Wed, 29 Mar 2023 11:46:04 -0400 Subject: [PATCH 12/26] reverting composite --- src/Runner.Worker/Handlers/CompositeActionHandler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Runner.Worker/Handlers/CompositeActionHandler.cs b/src/Runner.Worker/Handlers/CompositeActionHandler.cs index 8169f015dec..4cc54af41c6 100644 --- a/src/Runner.Worker/Handlers/CompositeActionHandler.cs +++ b/src/Runner.Worker/Handlers/CompositeActionHandler.cs @@ -161,6 +161,7 @@ public async Task RunAsync(ActionRunStage stage) embeddedSteps.Add(step); } + // Run embedded steps await RunStepsAsync(embeddedSteps, stage); From 1abe6db1eef02c342ffda80c764880d2de747efa Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Wed, 29 Mar 2023 14:23:07 -0400 Subject: [PATCH 13/26] updating catch to not exclude other exceptions --- src/Runner.Worker/ActionRunner.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 3c45e6bdc3b..cf21250aab7 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -96,12 +96,10 @@ Action.Reference is Pipelines.RepositoryPathReference localAction && { prepareResult = await actionManager.PrepareActionsAsync(ExecutionContext, compositeHandlerData.Steps, ExecutionContext.Id); } - catch (Exception ex) + catch (WebApi.FailedToResolveActionDownloadInfoException ex) { - if (ex is WebApi.FailedToResolveActionDownloadInfoException) - { - throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info", ex); - } + throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info", ex); + } // Reload definition since post may exist now (from embedded steps that were JIT downloaded) From 02835c2efeed40b19af9f3704dae3d4a384724c2 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Wed, 29 Mar 2023 14:26:16 -0400 Subject: [PATCH 14/26] removing uneeded import --- src/Runner.Worker/ActionRunner.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index cf21250aab7..e4a29e0aaf0 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -12,7 +12,6 @@ using GitHub.Runner.Worker.Handlers; using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; -using System.Threading; namespace GitHub.Runner.Worker { From 6ceaa65631e8079ccea871306f7e341ef9a83002 Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Thu, 30 Mar 2023 09:45:38 -0400 Subject: [PATCH 15/26] Update src/Runner.Worker/ActionRunner.cs Co-authored-by: Tingluo Huang --- src/Runner.Worker/ActionRunner.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index e4a29e0aaf0..53e8bca9b97 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -98,7 +98,6 @@ Action.Reference is Pipelines.RepositoryPathReference localAction && catch (WebApi.FailedToResolveActionDownloadInfoException ex) { throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info", ex); - } // Reload definition since post may exist now (from embedded steps that were JIT downloaded) From 6fc0990665642bcaf74bc597e5ab1facd9f07ffc Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Thu, 30 Mar 2023 09:46:01 -0400 Subject: [PATCH 16/26] Update src/Runner.Worker/ActionManager.cs Co-authored-by: Tingluo Huang --- src/Runner.Worker/ActionManager.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 7f7d594e375..86778a4efd1 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -152,8 +152,6 @@ public sealed class ActionManager : RunnerService, IActionManager #endif } return new PrepareResult(containerSetupSteps, result.PreStepTracker); - - } private async Task PrepareActionsRecursiveAsync(IExecutionContext executionContext, PrepareActionsState state, IEnumerable actions, Int32 depth = 0, Guid parentStepId = default(Guid)) From 083a491e4fc5161d55a3bbfba606e7db509f52ef Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Thu, 30 Mar 2023 09:46:16 -0400 Subject: [PATCH 17/26] Update src/Runner.Worker/ActionManager.cs Co-authored-by: Tingluo Huang --- src/Runner.Worker/ActionManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 86778a4efd1..7a0e2234ce5 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -105,7 +105,6 @@ public sealed class ActionManager : RunnerService, IActionManager try { result = await PrepareActionsRecursiveAsync(executionContext, state, actions, depth, rootStepId); - } catch (FailedToResolveActionDownloadInfoException ex) { From 052bf12dea74545501a61d3f86cc281f0be2eb47 Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Thu, 30 Mar 2023 09:48:51 -0400 Subject: [PATCH 18/26] Update src/Runner.Worker/ActionManager.cs Co-authored-by: Tingluo Huang --- src/Runner.Worker/ActionManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 7a0e2234ce5..fc40dd38798 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -700,7 +700,6 @@ private async Task BuildActionContainerAsync(IExecutionContext executionContext, if (ex is WebApi.UnresolvableActionDownloadInfoException) { throw new WebApi.UnresolvableActionDownloadInfoException("Unable to resolve action download info", ex); - // throw; } else { From c03ba7783ad634b470269a0b1b3ba1ec27d20848 Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Thu, 30 Mar 2023 09:50:05 -0400 Subject: [PATCH 19/26] Update src/Runner.Worker/ActionManager.cs Co-authored-by: Tingluo Huang --- src/Runner.Worker/ActionManager.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index fc40dd38798..a15edc135ff 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -188,8 +188,6 @@ public sealed class ActionManager : RunnerService, IActionManager if (repositoryActions.Count > 0) { - - // Download each action foreach (var action in repositoryActions) { From 051cdd096c65d1c4e3f3089e62a6310f5eb65f49 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Thu, 30 Mar 2023 11:03:27 -0400 Subject: [PATCH 20/26] moving download out of for loop; reverting exception wrap --- src/Runner.Worker/ActionManager.cs | 8 ++++---- src/Runner.Worker/ActionRunner.cs | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index a15edc135ff..177ee6e009e 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -188,6 +188,9 @@ public sealed class ActionManager : RunnerService, IActionManager if (repositoryActions.Count > 0) { + // Get the download info + var downloadInfos = await GetDownloadInfoAsync(executionContext, repositoryActions); + // Download each action foreach (var action in repositoryActions) { @@ -196,9 +199,6 @@ public sealed class ActionManager : RunnerService, IActionManager { continue; } - // Get the download info - var downloadInfos = await GetDownloadInfoAsync(executionContext, repositoryActions); - if (!downloadInfos.TryGetValue(lookupKey, out var downloadInfo)) { throw new Exception($"Missing download info for {lookupKey}"); @@ -697,7 +697,7 @@ private async Task BuildActionContainerAsync(IExecutionContext executionContext, // * Policy validation failed if (ex is WebApi.UnresolvableActionDownloadInfoException) { - throw new WebApi.UnresolvableActionDownloadInfoException("Unable to resolve action download info", ex); + throw; } else { diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 53e8bca9b97..58092dcc695 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -12,7 +12,6 @@ using GitHub.Runner.Worker.Handlers; using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; - namespace GitHub.Runner.Worker { public enum ActionRunStage From 0193f2ef6fee3b6ce8bbdf836bba58cd72429df6 Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Thu, 6 Apr 2023 09:47:08 -0400 Subject: [PATCH 21/26] Update src/Runner.Worker/ActionManager.cs Co-authored-by: Tingluo Huang --- src/Runner.Worker/ActionManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 177ee6e009e..2dbbf16b3c4 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -187,7 +187,6 @@ public sealed class ActionManager : RunnerService, IActionManager if (repositoryActions.Count > 0) { - // Get the download info var downloadInfos = await GetDownloadInfoAsync(executionContext, repositoryActions); From 31544f384bedc760fc222b9a20f54222a940ae89 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Wed, 10 May 2023 23:43:18 -0400 Subject: [PATCH 22/26] Adding blank lines back --- src/Runner.Worker/ActionManager.cs | 1 + src/Runner.Worker/ActionRunner.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 28cc162e6bd..3d27633f373 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -199,6 +199,7 @@ public sealed class ActionManager : RunnerService, IActionManager { continue; } + if (!downloadInfos.TryGetValue(lookupKey, out var downloadInfo)) { throw new Exception($"Missing download info for {lookupKey}"); diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 58092dcc695..53e8bca9b97 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -12,6 +12,7 @@ using GitHub.Runner.Worker.Handlers; using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; + namespace GitHub.Runner.Worker { public enum ActionRunStage From dc08dd8b9ff4afdc52aa22ec4b8386cb95b201fe Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Wed, 10 May 2023 23:44:55 -0400 Subject: [PATCH 23/26] Adding blank lines back --- src/Runner.Worker/ActionRunner.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 53e8bca9b97..7d96684df28 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -13,6 +13,7 @@ using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; + namespace GitHub.Runner.Worker { public enum ActionRunStage From d4ce9391196eb6e9c083b91f568507ce8ac74b4f Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Thu, 11 May 2023 00:32:42 -0400 Subject: [PATCH 24/26] removing uneeded catch for download fail --- src/Runner.Worker/ActionManager.cs | 16 +--------------- src/Runner.Worker/ActionRunner.cs | 10 +--------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 3d27633f373..ad39efb917e 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -18,7 +18,6 @@ using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; using PipelineTemplateConstants = GitHub.DistributedTask.Pipelines.ObjectTemplating.PipelineTemplateConstants; -using GitHub.DistributedTask.WebApi; namespace GitHub.Runner.Worker { @@ -102,20 +101,7 @@ public sealed class ActionManager : RunnerService, IActionManager } IEnumerable actions = steps.OfType(); executionContext.Output("Prepare all required actions"); - PrepareActionsState result = new PrepareActionsState(); - try - { - result = await PrepareActionsRecursiveAsync(executionContext, state, actions, depth, rootStepId); - } - catch (FailedToResolveActionDownloadInfoException ex) - { - // Log the error and fail the PrepareActionsAsync Initialization. - Trace.Error($"Caught exception from PrepareActionsAsync Initialization: {ex}"); - executionContext.InfrastructureError(ex.Message); - executionContext.Result = TaskResult.Failed; - throw; - } - + var result = await PrepareActionsRecursiveAsync(executionContext, state, actions, depth, rootStepId); if (!FeatureManager.IsContainerHooksEnabled(executionContext.Global.Variables)) { if (state.ImagesToPull.Count > 0) diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 7d96684df28..3ac41436641 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -91,15 +91,7 @@ Action.Reference is Pipelines.RepositoryPathReference localAction && string.Equals(localAction.RepositoryType, Pipelines.PipelineConstants.SelfAlias, StringComparison.OrdinalIgnoreCase)) { var actionManager = HostContext.GetService(); - PrepareResult prepareResult = default(PrepareResult); - try - { - prepareResult = await actionManager.PrepareActionsAsync(ExecutionContext, compositeHandlerData.Steps, ExecutionContext.Id); - } - catch (WebApi.FailedToResolveActionDownloadInfoException ex) - { - throw new WebApi.FailedToResolveActionDownloadInfoException("Failed to resolve action download info", ex); - } + PrepareResult prepareResult = await actionManager.PrepareActionsAsync(ExecutionContext, compositeHandlerData.Steps, ExecutionContext.Id); // Reload definition since post may exist now (from embedded steps that were JIT downloaded) definition = taskManager.LoadAction(ExecutionContext, Action); From 371f3e0d66948f7a19bf0e00c794d839e26a5261 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Thu, 11 May 2023 00:33:40 -0400 Subject: [PATCH 25/26] adding var back for consistency --- src/Runner.Worker/ActionRunner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 3ac41436641..8d3b866eeaf 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -91,7 +91,7 @@ Action.Reference is Pipelines.RepositoryPathReference localAction && string.Equals(localAction.RepositoryType, Pipelines.PipelineConstants.SelfAlias, StringComparison.OrdinalIgnoreCase)) { var actionManager = HostContext.GetService(); - PrepareResult prepareResult = await actionManager.PrepareActionsAsync(ExecutionContext, compositeHandlerData.Steps, ExecutionContext.Id); + var prepareResult = await actionManager.PrepareActionsAsync(ExecutionContext, compositeHandlerData.Steps, ExecutionContext.Id); // Reload definition since post may exist now (from embedded steps that were JIT downloaded) definition = taskManager.LoadAction(ExecutionContext, Action); From 16943a9781f6e6e69a328d220590ebb3bab24733 Mon Sep 17 00:00:00 2001 From: vmjoseph Date: Thu, 11 May 2023 09:29:19 -0400 Subject: [PATCH 26/26] formatting clean --- src/Runner.Worker/ActionManager.cs | 15 ++++++++++++++- src/Runner.Worker/ActionRunner.cs | 2 -- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index ad39efb917e..6f7a0cb8657 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -18,6 +18,7 @@ using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; using PipelineTemplateConstants = GitHub.DistributedTask.Pipelines.ObjectTemplating.PipelineTemplateConstants; +using GitHub.DistributedTask.WebApi; namespace GitHub.Runner.Worker { @@ -101,7 +102,19 @@ public sealed class ActionManager : RunnerService, IActionManager } IEnumerable actions = steps.OfType(); executionContext.Output("Prepare all required actions"); - var result = await PrepareActionsRecursiveAsync(executionContext, state, actions, depth, rootStepId); + PrepareActionsState result = new PrepareActionsState(); + try + { + result = await PrepareActionsRecursiveAsync(executionContext, state, actions, depth, rootStepId); + } + catch (FailedToResolveActionDownloadInfoException ex) + { + // Log the error and fail the PrepareActionsAsync Initialization. + Trace.Error($"Caught exception from PrepareActionsAsync Initialization: {ex}"); + executionContext.InfrastructureError(ex.Message); + executionContext.Result = TaskResult.Failed; + throw; + } if (!FeatureManager.IsContainerHooksEnabled(executionContext.Global.Variables)) { if (state.ImagesToPull.Count > 0) diff --git a/src/Runner.Worker/ActionRunner.cs b/src/Runner.Worker/ActionRunner.cs index 8d3b866eeaf..62fbbb812d6 100644 --- a/src/Runner.Worker/ActionRunner.cs +++ b/src/Runner.Worker/ActionRunner.cs @@ -10,10 +10,8 @@ using GitHub.Runner.Common.Util; using GitHub.Runner.Sdk; using GitHub.Runner.Worker.Handlers; -using WebApi = GitHub.DistributedTask.WebApi; using Pipelines = GitHub.DistributedTask.Pipelines; - namespace GitHub.Runner.Worker { public enum ActionRunStage