mirror of
https://github.com/actions/runner.git
synced 2025-12-11 12:57:05 +00:00
Remove env in composite action scope
This commit is contained in:
@@ -400,8 +400,6 @@ namespace GitHub.Runner.Worker
|
|||||||
var compositeAction = definition.Data.Execution as CompositeActionExecutionData;
|
var compositeAction = definition.Data.Execution as CompositeActionExecutionData;
|
||||||
Trace.Info($"Load {compositeAction.Steps.Count} action steps.");
|
Trace.Info($"Load {compositeAction.Steps.Count} action steps.");
|
||||||
Trace.Verbose($"Details: {StringUtil.ConvertToJson(compositeAction.Steps)}");
|
Trace.Verbose($"Details: {StringUtil.ConvertToJson(compositeAction.Steps)}");
|
||||||
Trace.Info($"Load: {compositeAction.Environment} environment steps");
|
|
||||||
Trace.Info($"Details: {StringUtil.ConvertToJson(compositeAction.Environment)}");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1287,7 +1285,6 @@ namespace GitHub.Runner.Worker
|
|||||||
public override bool HasPre => false;
|
public override bool HasPre => false;
|
||||||
public override bool HasPost => false;
|
public override bool HasPost => false;
|
||||||
public List<Pipelines.ActionStep> Steps { get; set; }
|
public List<Pipelines.ActionStep> Steps { get; set; }
|
||||||
public MappingToken Environment { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class ActionExecutionData
|
public abstract class ActionExecutionData
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
Dictionary<string, string> EvaluateContainerEnvironment(IExecutionContext executionContext, MappingToken token, IDictionary<string, PipelineContextData> extraExpressionValues);
|
Dictionary<string, string> EvaluateContainerEnvironment(IExecutionContext executionContext, MappingToken token, IDictionary<string, PipelineContextData> extraExpressionValues);
|
||||||
|
|
||||||
public Dictionary<string, string> EvaluateCompositeActionEnvironment(IExecutionContext executionContext, MappingToken token, IDictionary<string, PipelineContextData> extraExpressionValues);
|
|
||||||
string EvaluateDefaultInput(IExecutionContext executionContext, string inputName, TemplateToken token);
|
string EvaluateDefaultInput(IExecutionContext executionContext, string inputName, TemplateToken token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +99,7 @@ namespace GitHub.Runner.Worker
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "runs":
|
case "runs":
|
||||||
actionDefinition.Execution = ConvertRuns(executionContext, context, actionPair.Value, envComposite);
|
actionDefinition.Execution = ConvertRuns(executionContext, context, actionPair.Value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -222,48 +221,6 @@ namespace GitHub.Runner.Worker
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, string> EvaluateCompositeActionEnvironment(
|
|
||||||
IExecutionContext executionContext,
|
|
||||||
MappingToken token,
|
|
||||||
IDictionary<string, PipelineContextData> extraExpressionValues)
|
|
||||||
{
|
|
||||||
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
if (token != null)
|
|
||||||
{
|
|
||||||
var context = CreateContext(executionContext, extraExpressionValues);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var evaluateResult = TemplateEvaluator.Evaluate(context, "runs-env", token, 0, null, omitHeader: true);
|
|
||||||
context.Errors.Check();
|
|
||||||
|
|
||||||
// Mapping
|
|
||||||
var mapping = evaluateResult.AssertMapping("composite env");
|
|
||||||
|
|
||||||
foreach (var pair in mapping)
|
|
||||||
{
|
|
||||||
// Literal key
|
|
||||||
var key = pair.Key.AssertString("composite env key");
|
|
||||||
|
|
||||||
// Literal value
|
|
||||||
var value = pair.Value.AssertString("composite env value");
|
|
||||||
result[key.Value] = value.Value;
|
|
||||||
|
|
||||||
Trace.Info($"Add env {key} = {value}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) when (!(ex is TemplateValidationException))
|
|
||||||
{
|
|
||||||
Trace.Error(ex);
|
|
||||||
context.Errors.Add(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Errors.Check();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
public string EvaluateDefaultInput(
|
public string EvaluateDefaultInput(
|
||||||
IExecutionContext executionContext,
|
IExecutionContext executionContext,
|
||||||
string inputName,
|
string inputName,
|
||||||
@@ -347,8 +304,7 @@ namespace GitHub.Runner.Worker
|
|||||||
private ActionExecutionData ConvertRuns(
|
private ActionExecutionData ConvertRuns(
|
||||||
IExecutionContext executionContext,
|
IExecutionContext executionContext,
|
||||||
TemplateContext context,
|
TemplateContext context,
|
||||||
TemplateToken inputsToken,
|
TemplateToken inputsToken)
|
||||||
MappingToken envComposite)
|
|
||||||
{
|
{
|
||||||
var runsMapping = inputsToken.AssertMapping("runs");
|
var runsMapping = inputsToken.AssertMapping("runs");
|
||||||
var usingToken = default(StringToken);
|
var usingToken = default(StringToken);
|
||||||
@@ -440,7 +396,6 @@ namespace GitHub.Runner.Worker
|
|||||||
Image = imageToken.Value,
|
Image = imageToken.Value,
|
||||||
Arguments = argsToken,
|
Arguments = argsToken,
|
||||||
EntryPoint = entrypointToken?.Value,
|
EntryPoint = entrypointToken?.Value,
|
||||||
Environment = envToken,
|
|
||||||
Pre = preEntrypointToken?.Value,
|
Pre = preEntrypointToken?.Value,
|
||||||
InitCondition = preIfToken?.Value ?? "always()",
|
InitCondition = preIfToken?.Value ?? "always()",
|
||||||
Post = postEntrypointToken?.Value,
|
Post = postEntrypointToken?.Value,
|
||||||
@@ -477,16 +432,10 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
return new CompositeActionExecutionData()
|
return new CompositeActionExecutionData()
|
||||||
{
|
{
|
||||||
Steps = stepsLoaded,
|
Steps = stepsLoaded
|
||||||
Environment = envComposite
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If there is an env set and it's not for composite action, yield an error
|
|
||||||
if (envComposite != null && string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TESTING_COMPOSITE_ACTIONS_ALPHA")))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("You cannot use env unless you are using Composite Actions");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException($"'using: {usingToken.Value}' is not supported, use 'docker' or 'node12' instead.");
|
throw new ArgumentOutOfRangeException($"'using: {usingToken.Value}' is not supported, use 'docker' or 'node12' instead.");
|
||||||
|
|||||||
@@ -51,23 +51,6 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
extraExpressionValues["inputs"] = inputsData;
|
extraExpressionValues["inputs"] = inputsData;
|
||||||
var manifestManager = HostContext.GetService<IActionManifestManager>();
|
var manifestManager = HostContext.GetService<IActionManifestManager>();
|
||||||
|
|
||||||
// Add the composite action environment variables to each step.
|
|
||||||
// If the key already exists, we override it since the composite action env variables will have higher precedence
|
|
||||||
// Note that for each composite action step, it's environment variables will be set in the StepRunner automatically
|
|
||||||
var compositeEnvData = manifestManager.EvaluateCompositeActionEnvironment(ExecutionContext, Data.Environment, extraExpressionValues);
|
|
||||||
var envData = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
// Copy over parent environment
|
|
||||||
foreach (var env in Environment)
|
|
||||||
{
|
|
||||||
envData[env.Key] = env.Value;
|
|
||||||
}
|
|
||||||
// Overwrite with current env
|
|
||||||
foreach (var env in compositeEnvData)
|
|
||||||
{
|
|
||||||
envData[env.Key] = env.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add each composite action step to the front of the queue
|
// Add each composite action step to the front of the queue
|
||||||
int location = 0;
|
int location = 0;
|
||||||
foreach (Pipelines.ActionStep aStep in actionSteps)
|
foreach (Pipelines.ActionStep aStep in actionSteps)
|
||||||
@@ -108,7 +91,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
actionRunner.Condition = aStep.Condition;
|
actionRunner.Condition = aStep.Condition;
|
||||||
actionRunner.DisplayName = aStep.DisplayName;
|
actionRunner.DisplayName = aStep.DisplayName;
|
||||||
|
|
||||||
ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location, envData);
|
ExecutionContext.RegisterNestedStep(actionRunner, inputsData, location, Environment);
|
||||||
location++;
|
location++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
"name": "string",
|
"name": "string",
|
||||||
"description": "string",
|
"description": "string",
|
||||||
"inputs": "inputs",
|
"inputs": "inputs",
|
||||||
"env": "runs-env",
|
|
||||||
"runs": "runs"
|
"runs": "runs"
|
||||||
},
|
},
|
||||||
"loose-key-type": "non-empty-string",
|
"loose-key-type": "non-empty-string",
|
||||||
@@ -44,7 +43,7 @@
|
|||||||
"image": "non-empty-string",
|
"image": "non-empty-string",
|
||||||
"entrypoint": "non-empty-string",
|
"entrypoint": "non-empty-string",
|
||||||
"args": "container-runs-args",
|
"args": "container-runs-args",
|
||||||
"env": "runs-env",
|
"env": "container-runs-env",
|
||||||
"pre-entrypoint": "non-empty-string",
|
"pre-entrypoint": "non-empty-string",
|
||||||
"pre-if": "non-empty-string",
|
"pre-if": "non-empty-string",
|
||||||
"post-entrypoint": "non-empty-string",
|
"post-entrypoint": "non-empty-string",
|
||||||
@@ -57,7 +56,7 @@
|
|||||||
"item-type": "container-runs-context"
|
"item-type": "container-runs-context"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"runs-env": {
|
"container-runs-env": {
|
||||||
"context": [
|
"context": [
|
||||||
"inputs"
|
"inputs"
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user