Skip to content

Commit

Permalink
Use Global.Variables instead of JobContext and include action path/re…
Browse files Browse the repository at this point in the history
…f in the message. (#2214)

* Use Global.Variables instead of JobContext and include action path/ref in the message.

* encoding

* .
  • Loading branch information
TingluoHuang authored Nov 2, 2022
1 parent d301c06 commit 4adaf9c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# https://editorconfig.org/

[*]
charset = utf-8 # Set default charset to utf-8
insert_final_newline = true # ensure all files end with a single newline
trim_trailing_whitespace = true # attempt to remove trailing whitespace on save

Expand Down
27 changes: 20 additions & 7 deletions src/Runner.Worker/Handlers/NodeScriptActionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -7,8 +8,8 @@
using GitHub.DistributedTask.Pipelines.ContextData;
using GitHub.DistributedTask.WebApi;
using GitHub.Runner.Common;
using GitHub.Runner.Sdk;
using GitHub.Runner.Common.Util;
using GitHub.Runner.Sdk;
using GitHub.Runner.Worker.Container;
using GitHub.Runner.Worker.Container.ContainerHooks;

Expand Down Expand Up @@ -137,13 +138,25 @@ public async Task RunAsync(ActionRunStage stage)

if (Data.NodeVersion == "node12" && (ExecutionContext.Global.Variables.GetBoolean(Constants.Runner.Features.Node12Warning) ?? false))
{
if (!ExecutionContext.JobContext.ContainsKey("Node12ActionsWarnings"))
var repoAction = Action as RepositoryPathReference;
var warningActions = new HashSet<string>();
if (ExecutionContext.Global.Variables.TryGetValue("Node12ActionsWarnings", out var node12Warnings))
{
ExecutionContext.JobContext["Node12ActionsWarnings"] = new ArrayContextData();
warningActions = StringUtil.ConvertFromJson<HashSet<string>>(node12Warnings);
}
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);

var repoActionFullName = "";
if (string.IsNullOrEmpty(repoAction.Name))
{
repoActionFullName = repoAction.Path; // local actions don't have a 'Name'
}
else
{
repoActionFullName = $"{repoAction.Name}/{repoAction.Path ?? string.Empty}".TrimEnd('/') + $"@{repoAction.Ref}";
}

warningActions.Add(repoActionFullName);
ExecutionContext.Global.Variables.Set("Node12ActionsWarnings", StringUtil.ConvertToJson(warningActions));
}

using (var stdoutManager = new OutputManager(ExecutionContext, ActionCommandManager))
Expand Down
6 changes: 3 additions & 3 deletions src/Runner.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -258,9 +258,9 @@ private async Task<TaskResult> CompleteJobAsync(IJobServer jobServer, IExecution
}
}

if (jobContext.JobContext.ContainsKey("Node12ActionsWarnings"))
if (jobContext.Global.Variables.TryGetValue("Node12ActionsWarnings", out var node12Warnings))
{
var actions = string.Join(", ", jobContext.JobContext["Node12ActionsWarnings"].AssertArray("Node12ActionsWarnings").Select(action => action.ToString()));
var actions = string.Join(", ", StringUtil.ConvertFromJson<HashSet<string>>(node12Warnings));
jobContext.Warning(string.Format(Constants.Runner.Node12DetectedAfterEndOfLife, actions));
}

Expand Down
10 changes: 8 additions & 2 deletions src/Runner.Worker/Variables.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using GitHub.DistributedTask.WebApi;
using GitHub.DistributedTask.Logging;
using GitHub.DistributedTask.Pipelines.ContextData;
using GitHub.DistributedTask.WebApi;
using GitHub.Runner.Common;
using GitHub.Runner.Common.Util;
using GitHub.Runner.Sdk;
Expand Down Expand Up @@ -136,6 +136,12 @@ public string Get(string name)
return null;
}

public void Set(string name, string val)
{
ArgUtil.NotNullOrEmpty(name, nameof(name));
_variables[name] = new Variable(name, val, false);
}

public bool TryGetValue(string name, out string val)
{
Variable variable;
Expand Down

0 comments on commit 4adaf9c

Please sign in to comment.