mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +00:00
GitHub Actions Runner
This commit is contained in:
35
src/Runner.Worker/GitHubContext.cs
Normal file
35
src/Runner.Worker/GitHubContext.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using GitHub.DistributedTask.Pipelines.ContextData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GitHub.Runner.Worker
|
||||
{
|
||||
public sealed class GitHubContext : DictionaryContextData, IEnvironmentContextData
|
||||
{
|
||||
private readonly HashSet<string> _contextEnvWhitelist = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"action",
|
||||
"actor",
|
||||
"base_ref",
|
||||
"event_name",
|
||||
"event_path",
|
||||
"head_ref",
|
||||
"ref",
|
||||
"repository",
|
||||
"sha",
|
||||
"workflow",
|
||||
"workspace",
|
||||
};
|
||||
|
||||
public IEnumerable<KeyValuePair<string, string>> GetRuntimeEnvironmentVariables()
|
||||
{
|
||||
foreach (var data in this)
|
||||
{
|
||||
if (_contextEnvWhitelist.Contains(data.Key) && data.Value is StringContextData value)
|
||||
{
|
||||
yield return new KeyValuePair<string, string>($"GITHUB_{data.Key.ToUpperInvariant()}", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user