Skip to content

Commit 54ef4d4

Browse files
provide gitea prefixes via FeatureFlag (#562)
* system.runner.server.github_prefixes comma separated list of context names
1 parent a0a52da commit 54ef4d4

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

src/Runner.Worker/ExecutionContext.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ public void InitializeJob(Pipelines.AgentJobRequestMessage message, Cancellation
865865
var base64EncodedToken = Convert.ToBase64String(Encoding.UTF8.GetBytes($"x-access-token:{githubAccessToken}"));
866866
HostContext.SecretMasker.AddValue(base64EncodedToken);
867867
var githubJob = Global.Variables.Get("system.github.job");
868-
var githubContext = new GitHubContext();
868+
var githubContext = new GitHubContext(Global.Variables.Get("system.runner.server.github_prefixes")?.Split(","));
869869
githubContext["token"] = githubAccessToken;
870870
if (!string.IsNullOrEmpty(githubJob))
871871
{
@@ -876,8 +876,10 @@ public void InitializeJob(Pipelines.AgentJobRequestMessage message, Cancellation
876876
{
877877
githubContext[pair.Key] = pair.Value;
878878
}
879-
ExpressionValues["github"] = githubContext;
880-
879+
foreach (var prefix in githubContext.Prefixes)
880+
{
881+
ExpressionValues[prefix] = githubContext;
882+
}
881883
// Prepend Path
882884
Global.PrependPath = new List<string>();
883885

src/Runner.Worker/GitHubContext.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ namespace GitHub.Runner.Worker
66
{
77
public sealed class GitHubContext : DictionaryContextData, IEnvironmentContextData
88
{
9+
public GitHubContext(string[] prefixes = null) {
10+
Prefixes = prefixes ?? ["github"];
11+
}
12+
913
private readonly HashSet<string> _contextEnvAllowlist = new(StringComparer.OrdinalIgnoreCase)
1014
{
1115
"action_path",
@@ -47,27 +51,32 @@ public sealed class GitHubContext : DictionaryContextData, IEnvironmentContextDa
4751
"workspace"
4852
};
4953

54+
public string[] Prefixes { get; }
55+
5056
public IEnumerable<KeyValuePair<string, string>> GetRuntimeEnvironmentVariables()
5157
{
5258
foreach (var data in this)
5359
{
5460
if (_contextEnvAllowlist.Contains(data.Key))
5561
{
56-
if (data.Value is StringContextData value)
57-
{
58-
yield return new KeyValuePair<string, string>($"GITHUB_{data.Key.ToUpperInvariant()}", value);
59-
}
60-
else if (data.Value is BooleanContextData booleanValue)
62+
foreach (var prefix in Prefixes)
6163
{
62-
yield return new KeyValuePair<string, string>($"GITHUB_{data.Key.ToUpperInvariant()}", booleanValue.ToString());
64+
if (data.Value is StringContextData value)
65+
{
66+
yield return new KeyValuePair<string, string>($"{prefix.ToUpperInvariant()}_{data.Key.ToUpperInvariant()}", value);
67+
}
68+
else if (data.Value is BooleanContextData booleanValue)
69+
{
70+
yield return new KeyValuePair<string, string>($"{prefix.ToUpperInvariant()}_{data.Key.ToUpperInvariant()}", booleanValue.ToString());
71+
}
6372
}
6473
}
6574
}
6675
}
6776

6877
public GitHubContext ShallowCopy()
6978
{
70-
var copy = new GitHubContext();
79+
var copy = new GitHubContext(Prefixes);
7180

7281
foreach (var pair in this)
7382
{

src/Runner.Worker/Handlers/CompositeActionHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ public async Task RunAsync(ActionRunStage stage)
154154
var gitHubContext = step.ExecutionContext.ExpressionValues["github"] as GitHubContext;
155155
ArgUtil.NotNull(gitHubContext, nameof(gitHubContext));
156156
gitHubContext = gitHubContext.ShallowCopy();
157-
step.ExecutionContext.ExpressionValues["github"] = gitHubContext;
157+
foreach (var prefix in gitHubContext.Prefixes)
158+
{
159+
step.ExecutionContext.ExpressionValues[prefix] = gitHubContext;
160+
}
158161

159162
// Set GITHUB_ACTION_PATH
160163
step.ExecutionContext.SetGitHubContext("action_path", ActionDirectory);

0 commit comments

Comments
 (0)