-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathJobContext.cs
More file actions
112 lines (106 loc) · 3.39 KB
/
JobContext.cs
File metadata and controls
112 lines (106 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using GitHub.DistributedTask.Pipelines.ContextData;
using GitHub.Runner.Common.Util;
using GitHub.Runner.Common;
using System;
using System.Collections.Generic;
namespace GitHub.Runner.Worker
{
public sealed class JobContext : DictionaryContextData, IEnvironmentContextData
{
public ActionResult? Status
{
get
{
if (this.TryGetValue("status", out var status) && status is StringContextData statusString)
{
return EnumUtil.TryParse<ActionResult>(statusString);
}
else
{
return null;
}
}
set
{
this["status"] = new StringContextData(value.ToString().ToLowerInvariant());
}
}
public DictionaryContextData Services
{
get
{
if (this.TryGetValue("services", out var services) && services is DictionaryContextData servicesDictionary)
{
return servicesDictionary;
}
else
{
this["services"] = new DictionaryContextData();
return this["services"] as DictionaryContextData;
}
}
}
public DictionaryContextData Container
{
get
{
if (this.TryGetValue("container", out var container) && container is DictionaryContextData containerDictionary)
{
return containerDictionary;
}
else
{
this["container"] = new DictionaryContextData();
return this["container"] as DictionaryContextData;
}
}
}
public double? CheckRunId
{
get
{
if (this.TryGetValue("check_run_id", out var value) && value is NumberContextData number)
{
return number.Value;
}
else
{
return null;
}
}
set
{
if (value.HasValue)
{
this["check_run_id"] = new NumberContextData(value.Value);
}
else
{
this["check_run_id"] = null;
}
}
}
private readonly HashSet<string> _contextEnvAllowlist = new(StringComparer.OrdinalIgnoreCase)
{
"check_run_id",
"status",
};
public IEnumerable<KeyValuePair<string, string>> GetRuntimeEnvironmentVariables()
{
foreach (var data in this)
{
if (_contextEnvAllowlist.Contains(data.Key))
{
if (data.Value is StringContextData value)
{
yield return new KeyValuePair<string, string>($"JOB_{data.Key.ToUpperInvariant()}", value);
}
else if (data.Value is NumberContextData numberValue)
{
yield return new KeyValuePair<string, string>($"JOB_{data.Key.ToUpperInvariant()}", numberValue.ToString());
}
}
}
}
}
}