From 408d6c579c36f0eb318acfdafdcbafc872696501 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Date: Tue, 22 Mar 2022 10:43:25 +0100 Subject: [PATCH] Add annotations if Node 12 action is found and FF is on (#1735) * Add annotations if node 12 action is found * Better placeholder * Only warn if FF is on * Move annotation logic * Pass in the LTS Url * Raise annotation right before executing the action * Match server side FF name * Change name back to features * Better warning text * Update src/Runner.Common/Constants.cs Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com> Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com> --- src/Runner.Common/Constants.cs | 2 ++ .../Handlers/NodeScriptActionHandler.cs | 13 +++++++++++++ src/Runner.Worker/JobRunner.cs | 7 +++++++ src/Runner.Worker/StepsRunner.cs | 1 + 4 files changed, 23 insertions(+) diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index b9eeb6e81..42fb9dcbe 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -149,6 +149,7 @@ namespace GitHub.Runner.Common public static class Features { public static readonly string DiskSpaceWarning = "runner.diskspace.warning"; + public static readonly string Node12Warning = "DistributedTask.AddWarningToNode12Action"; } public static readonly string InternalTelemetryIssueDataKey = "_internal_telemetry"; @@ -158,6 +159,7 @@ namespace GitHub.Runner.Common public static readonly string UnsupportedCommandMessageDisabled = "The `{0}` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/"; public static readonly string UnsupportedStopCommandTokenDisabled = "You cannot use a endToken that is an empty string, the string 'pause-logging', or another workflow command. For more information see: https://docs.github.com/actions/learn-github-actions/workflow-commands-for-github-actions#example-stopping-and-starting-workflow-commands or opt into insecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_STOPCOMMAND_TOKENS` environment variable to `true`."; public static readonly string UnsupportedSummarySize = "$GITHUB_STEP_SUMMARY upload aborted, supports content up to a size of {0}k, got {1}k. For more information see: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary"; + public static readonly string Node12DetectedAfterEndOfLife = "Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: {0}"; } public static class RunnerEvent diff --git a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs index bd4cfc672..cc8cedfd0 100644 --- a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs +++ b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs @@ -3,6 +3,8 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using GitHub.DistributedTask.Pipelines; +using GitHub.DistributedTask.Pipelines.ContextData; using GitHub.DistributedTask.WebApi; using GitHub.Runner.Common; using GitHub.Runner.Sdk; @@ -112,6 +114,17 @@ namespace GitHub.Runner.Worker.Handlers // Remove environment variable that may cause conflicts with the node within the runner. Environment.Remove("NODE_ICU_DATA"); // https://github.com/actions/runner/issues/795 + if (Data.NodeVersion == "node12" && (ExecutionContext.Global.Variables.GetBoolean(Constants.Runner.Features.Node12Warning) ?? false)) + { + if (!ExecutionContext.JobContext.ContainsKey("Node12ActionsWarnings")) + { + ExecutionContext.JobContext["Node12ActionsWarnings"] = new ArrayContextData(); + } + var repoAction = Action as RepositoryPathReference; + var actionDisplayName = new StringContextData(repoAction.Name ?? repoAction.Path); // local actions don't have a 'Name' + ExecutionContext.JobContext["Node12ActionsWarnings"].AssertArray("Node12ActionsWarnings").Add(actionDisplayName); + } + using (var stdoutManager = new OutputManager(ExecutionContext, ActionCommandManager)) using (var stderrManager = new OutputManager(ExecutionContext, ActionCommandManager)) { diff --git a/src/Runner.Worker/JobRunner.cs b/src/Runner.Worker/JobRunner.cs index 74b142885..ac2ebd42a 100644 --- a/src/Runner.Worker/JobRunner.cs +++ b/src/Runner.Worker/JobRunner.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; +using GitHub.DistributedTask.Pipelines.ContextData; using GitHub.DistributedTask.WebApi; using GitHub.Runner.Common; using GitHub.Runner.Common.Util; @@ -257,6 +258,12 @@ namespace GitHub.Runner.Worker } } + if (jobContext.JobContext.ContainsKey("Node12ActionsWarnings")) + { + var actions = string.Join(", ", jobContext.JobContext["Node12ActionsWarnings"].AssertArray("Node12ActionsWarnings").Select(action => action.ToString())); + jobContext.Warning(string.Format(Constants.Runner.Node12DetectedAfterEndOfLife, actions)); + } + try { await ShutdownQueue(throwOnFailure: true); diff --git a/src/Runner.Worker/StepsRunner.cs b/src/Runner.Worker/StepsRunner.cs index 82c9218ba..47f9d4c59 100644 --- a/src/Runner.Worker/StepsRunner.cs +++ b/src/Runner.Worker/StepsRunner.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks;