-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add JOB_ env vars #4053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add JOB_ env vars #4053
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
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 | ||
public sealed class JobContext : DictionaryContextData, IEnvironmentContextData | ||
{ | ||
public ActionResult? Status | ||
{ | ||
|
@@ -82,5 +84,29 @@ public double? CheckRunId | |
} | ||
} | ||
} | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would go for a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not a bad idea, I'm curious to see what the maintainers think. I had originally considered that, but:
Personally my preference would have been to name the context field cc @ericsciple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jenseng I think you are right your name pattern makes sense then |
||
} | ||
else if (data.Value is NumberContextData numberValue) | ||
{ | ||
yield return new KeyValuePair<string, string>($"JOB_{data.Key.ToUpperInvariant()}", numberValue.ToString()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implicit conversion from
StringContextData
tostring
may not work as expected. Usevalue.ToString()
to explicitly convert the value to a string.Copilot uses AI. Check for mistakes.