mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +00:00
Adding a new vars context for non-secret variables (#2096)
* Adding a new vars context for non-secret variables * Fix test case * Trigger checks * Remove variables from env context and environment varibale * remove extra references * Add prefix handling to configuration variables * Fix test cases * Consume variables using vars in context data * removed action_yaml changes
This commit is contained in:
@@ -73,6 +73,7 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating
|
||||
public const String TimeoutMinutes = "timeout-minutes";
|
||||
public const String Username = "username";
|
||||
public const String Uses = "uses";
|
||||
public const String Vars = "vars";
|
||||
public const String VmImage = "vmImage";
|
||||
public const String Volumes = "volumes";
|
||||
public const String With = "with";
|
||||
|
||||
@@ -631,6 +631,7 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating
|
||||
{
|
||||
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.GitHub),
|
||||
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Needs),
|
||||
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Vars),
|
||||
};
|
||||
private static readonly INamedValueInfo[] s_stepNamedValues = new INamedValueInfo[]
|
||||
{
|
||||
@@ -643,6 +644,7 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating
|
||||
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Runner),
|
||||
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Env),
|
||||
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Needs),
|
||||
new NamedValueInfo<NoOperationNamedValue>(PipelineTemplateConstants.Vars),
|
||||
};
|
||||
private static readonly IFunctionInfo[] s_stepConditionFunctions = new IFunctionInfo[]
|
||||
{
|
||||
|
||||
@@ -465,6 +465,7 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating
|
||||
PipelineTemplateConstants.Job,
|
||||
PipelineTemplateConstants.Runner,
|
||||
PipelineTemplateConstants.Env,
|
||||
PipelineTemplateConstants.Vars,
|
||||
};
|
||||
private readonly String[] s_expressionFunctionNames = new[]
|
||||
{
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
"workflow-env": {
|
||||
"context": [
|
||||
"github",
|
||||
"secrets"
|
||||
"secrets",
|
||||
"vars"
|
||||
],
|
||||
"mapping": {
|
||||
"loose-key-type": "non-empty-string",
|
||||
@@ -86,6 +87,7 @@
|
||||
"context": [
|
||||
"github",
|
||||
"needs",
|
||||
"vars",
|
||||
"always(0,0)",
|
||||
"failure(0,MAX)",
|
||||
"cancelled(0,0)",
|
||||
@@ -98,6 +100,7 @@
|
||||
"context": [
|
||||
"github",
|
||||
"needs",
|
||||
"vars",
|
||||
"always(0,0)",
|
||||
"failure(0,MAX)",
|
||||
"cancelled(0,0)",
|
||||
@@ -116,7 +119,8 @@
|
||||
"strategy": {
|
||||
"context": [
|
||||
"github",
|
||||
"needs"
|
||||
"needs",
|
||||
"vars"
|
||||
],
|
||||
"mapping": {
|
||||
"properties": {
|
||||
@@ -156,7 +160,8 @@
|
||||
"github",
|
||||
"needs",
|
||||
"strategy",
|
||||
"matrix"
|
||||
"matrix",
|
||||
"vars"
|
||||
],
|
||||
"one-of": [
|
||||
"non-empty-string",
|
||||
@@ -182,7 +187,8 @@
|
||||
"needs",
|
||||
"strategy",
|
||||
"matrix",
|
||||
"secrets"
|
||||
"secrets",
|
||||
"vars"
|
||||
],
|
||||
"mapping": {
|
||||
"loose-key-type": "non-empty-string",
|
||||
@@ -204,7 +210,8 @@
|
||||
"strategy",
|
||||
"matrix",
|
||||
"needs",
|
||||
"env"
|
||||
"env",
|
||||
"vars"
|
||||
],
|
||||
"mapping": {
|
||||
"properties": {
|
||||
@@ -281,6 +288,7 @@
|
||||
"job",
|
||||
"runner",
|
||||
"env",
|
||||
"vars",
|
||||
"always(0,0)",
|
||||
"failure(0,0)",
|
||||
"cancelled(0,0)",
|
||||
@@ -299,6 +307,7 @@
|
||||
"job",
|
||||
"runner",
|
||||
"env",
|
||||
"vars",
|
||||
"always(0,0)",
|
||||
"failure(0,0)",
|
||||
"cancelled(0,0)",
|
||||
@@ -326,6 +335,7 @@
|
||||
"job",
|
||||
"runner",
|
||||
"env",
|
||||
"vars",
|
||||
"hashFiles(1,255)"
|
||||
],
|
||||
"mapping": {
|
||||
@@ -345,6 +355,7 @@
|
||||
"job",
|
||||
"runner",
|
||||
"env",
|
||||
"vars",
|
||||
"hashFiles(1,255)"
|
||||
],
|
||||
"mapping": {
|
||||
@@ -358,7 +369,8 @@
|
||||
"github",
|
||||
"needs",
|
||||
"strategy",
|
||||
"matrix"
|
||||
"matrix",
|
||||
"vars"
|
||||
],
|
||||
"one-of": [
|
||||
"string",
|
||||
@@ -384,7 +396,8 @@
|
||||
"github",
|
||||
"needs",
|
||||
"strategy",
|
||||
"matrix"
|
||||
"matrix",
|
||||
"vars"
|
||||
],
|
||||
"mapping": {
|
||||
"loose-key-type": "non-empty-string",
|
||||
@@ -397,7 +410,8 @@
|
||||
"github",
|
||||
"needs",
|
||||
"strategy",
|
||||
"matrix"
|
||||
"matrix",
|
||||
"vars"
|
||||
],
|
||||
"one-of": [
|
||||
"non-empty-string",
|
||||
@@ -409,7 +423,8 @@
|
||||
"context": [
|
||||
"secrets",
|
||||
"env",
|
||||
"github"
|
||||
"github",
|
||||
"vars"
|
||||
],
|
||||
"mapping": {
|
||||
"properties": {
|
||||
@@ -443,7 +458,8 @@
|
||||
"github",
|
||||
"needs",
|
||||
"strategy",
|
||||
"matrix"
|
||||
"matrix",
|
||||
"vars"
|
||||
],
|
||||
"boolean": {}
|
||||
},
|
||||
@@ -453,7 +469,8 @@
|
||||
"github",
|
||||
"needs",
|
||||
"strategy",
|
||||
"matrix"
|
||||
"matrix",
|
||||
"vars"
|
||||
],
|
||||
"number": {}
|
||||
},
|
||||
@@ -463,7 +480,8 @@
|
||||
"github",
|
||||
"needs",
|
||||
"strategy",
|
||||
"matrix"
|
||||
"matrix",
|
||||
"vars"
|
||||
],
|
||||
"string": {}
|
||||
},
|
||||
@@ -479,6 +497,7 @@
|
||||
"job",
|
||||
"runner",
|
||||
"env",
|
||||
"vars",
|
||||
"hashFiles(1,255)"
|
||||
],
|
||||
"boolean": {}
|
||||
@@ -495,6 +514,7 @@
|
||||
"job",
|
||||
"runner",
|
||||
"env",
|
||||
"vars",
|
||||
"hashFiles(1,255)"
|
||||
],
|
||||
"number": {}
|
||||
@@ -510,7 +530,8 @@
|
||||
"steps",
|
||||
"job",
|
||||
"runner",
|
||||
"env"
|
||||
"env",
|
||||
"vars"
|
||||
],
|
||||
"string": {}
|
||||
},
|
||||
@@ -524,7 +545,8 @@
|
||||
"steps",
|
||||
"job",
|
||||
"runner",
|
||||
"env"
|
||||
"env",
|
||||
"vars"
|
||||
],
|
||||
"string": {}
|
||||
},
|
||||
@@ -540,6 +562,7 @@
|
||||
"job",
|
||||
"runner",
|
||||
"env",
|
||||
"vars",
|
||||
"hashFiles(1,255)"
|
||||
],
|
||||
"string": {}
|
||||
|
||||
@@ -844,6 +844,51 @@ namespace GitHub.Runner.Common.Tests.Worker
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Worker")]
|
||||
public void ActionVariables_AddedToVarsContext()
|
||||
{
|
||||
using (TestHostContext hc = CreateTestContext())
|
||||
{
|
||||
TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference();
|
||||
TimelineReference timeline = new TimelineReference();
|
||||
Guid jobId = Guid.NewGuid();
|
||||
string jobName = "some job name";
|
||||
var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, jobName, jobName, null, null, null, new Dictionary<string, VariableValue>(), new List<MaskHint>(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List<Pipelines.ActionStep>(), null, null, null, null);
|
||||
jobRequest.Resources.Repositories.Add(new Pipelines.RepositoryResource()
|
||||
{
|
||||
Alias = Pipelines.PipelineConstants.SelfAlias,
|
||||
Id = "github",
|
||||
Version = "sha1"
|
||||
});
|
||||
jobRequest.ContextData["github"] = new Pipelines.ContextData.DictionaryContextData();
|
||||
|
||||
var inputVarsContext = new DictionaryContextData();
|
||||
|
||||
inputVarsContext["VARIABLE_1"] = new StringContextData("value1");
|
||||
inputVarsContext["VARIABLE_2"] = new StringContextData("value2");
|
||||
jobRequest.ContextData["vars"] = inputVarsContext;
|
||||
|
||||
// Arrange: Setup the paging logger.
|
||||
var pagingLogger1 = new Mock<IPagingLogger>();
|
||||
var jobServerQueue = new Mock<IJobServerQueue>();
|
||||
hc.EnqueueInstance(pagingLogger1.Object);
|
||||
hc.SetSingleton(jobServerQueue.Object);
|
||||
|
||||
var jobContext = new Runner.Worker.ExecutionContext();
|
||||
jobContext.Initialize(hc);
|
||||
|
||||
jobContext.InitializeJob(jobRequest, CancellationToken.None);
|
||||
|
||||
var expected = new DictionaryContextData();
|
||||
expected["VARIABLE_1"] = new StringContextData("value1");
|
||||
expected["VARIABLE_2"] = new StringContextData("value1");
|
||||
|
||||
Assert.True(ExpressionValuesAssertEqual(expected, jobContext.ExpressionValues["vars"] as DictionaryContextData));
|
||||
}
|
||||
}
|
||||
|
||||
private bool ExpressionValuesAssertEqual(DictionaryContextData expect, DictionaryContextData actual)
|
||||
{
|
||||
foreach (var key in expect.Keys.ToList())
|
||||
|
||||
Reference in New Issue
Block a user