Skip to content

Commit 4adaf9c

Browse files
authored
Use Global.Variables instead of JobContext and include action path/ref in the message. (#2214)
* Use Global.Variables instead of JobContext and include action path/ref in the message. * encoding * .
1 parent d301c06 commit 4adaf9c

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# https://editorconfig.org/
22

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

src/Runner.Worker/Handlers/NodeScriptActionHandler.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using System.Text;
@@ -7,8 +8,8 @@
78
using GitHub.DistributedTask.Pipelines.ContextData;
89
using GitHub.DistributedTask.WebApi;
910
using GitHub.Runner.Common;
10-
using GitHub.Runner.Sdk;
1111
using GitHub.Runner.Common.Util;
12+
using GitHub.Runner.Sdk;
1213
using GitHub.Runner.Worker.Container;
1314
using GitHub.Runner.Worker.Container.ContainerHooks;
1415

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

138139
if (Data.NodeVersion == "node12" && (ExecutionContext.Global.Variables.GetBoolean(Constants.Runner.Features.Node12Warning) ?? false))
139140
{
140-
if (!ExecutionContext.JobContext.ContainsKey("Node12ActionsWarnings"))
141+
var repoAction = Action as RepositoryPathReference;
142+
var warningActions = new HashSet<string>();
143+
if (ExecutionContext.Global.Variables.TryGetValue("Node12ActionsWarnings", out var node12Warnings))
141144
{
142-
ExecutionContext.JobContext["Node12ActionsWarnings"] = new ArrayContextData();
145+
warningActions = StringUtil.ConvertFromJson<HashSet<string>>(node12Warnings);
143146
}
144-
var repoAction = Action as RepositoryPathReference;
145-
var actionDisplayName = new StringContextData(repoAction.Name ?? repoAction.Path); // local actions don't have a 'Name'
146-
ExecutionContext.JobContext["Node12ActionsWarnings"].AssertArray("Node12ActionsWarnings").Add(actionDisplayName);
147+
148+
var repoActionFullName = "";
149+
if (string.IsNullOrEmpty(repoAction.Name))
150+
{
151+
repoActionFullName = repoAction.Path; // local actions don't have a 'Name'
152+
}
153+
else
154+
{
155+
repoActionFullName = $"{repoAction.Name}/{repoAction.Path ?? string.Empty}".TrimEnd('/') + $"@{repoAction.Ref}";
156+
}
157+
158+
warningActions.Add(repoActionFullName);
159+
ExecutionContext.Global.Variables.Set("Node12ActionsWarnings", StringUtil.ConvertToJson(warningActions));
147160
}
148161

149162
using (var stdoutManager = new OutputManager(ExecutionContext, ActionCommandManager))

src/Runner.Worker/JobRunner.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
@@ -258,9 +258,9 @@ private async Task<TaskResult> CompleteJobAsync(IJobServer jobServer, IExecution
258258
}
259259
}
260260

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

src/Runner.Worker/Variables.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using GitHub.DistributedTask.WebApi;
65
using GitHub.DistributedTask.Logging;
76
using GitHub.DistributedTask.Pipelines.ContextData;
7+
using GitHub.DistributedTask.WebApi;
88
using GitHub.Runner.Common;
99
using GitHub.Runner.Common.Util;
1010
using GitHub.Runner.Sdk;
@@ -136,6 +136,12 @@ public string Get(string name)
136136
return null;
137137
}
138138

139+
public void Set(string name, string val)
140+
{
141+
ArgUtil.NotNullOrEmpty(name, nameof(name));
142+
_variables[name] = new Variable(name, val, false);
143+
}
144+
139145
public bool TryGetValue(string name, out string val)
140146
{
141147
Variable variable;

0 commit comments

Comments
 (0)