mirror of
https://github.com/actions/runner.git
synced 2025-12-14 13:43:33 +00:00
Sanity check for fileTable add + remove unn. code
This commit is contained in:
@@ -33,13 +33,10 @@ namespace GitHub.Runner.Worker
|
|||||||
public sealed class ActionManifestManager : RunnerService, IActionManifestManager
|
public sealed class ActionManifestManager : RunnerService, IActionManifestManager
|
||||||
{
|
{
|
||||||
private TemplateSchema _actionManifestSchema;
|
private TemplateSchema _actionManifestSchema;
|
||||||
private IHostContext _hostContext;
|
|
||||||
public override void Initialize(IHostContext hostContext)
|
public override void Initialize(IHostContext hostContext)
|
||||||
{
|
{
|
||||||
base.Initialize(hostContext);
|
base.Initialize(hostContext);
|
||||||
|
|
||||||
_hostContext = hostContext;
|
|
||||||
|
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
var json = default(string);
|
var json = default(string);
|
||||||
using (var stream = assembly.GetManifestResourceStream("GitHub.Runner.Worker.action_yaml.json"))
|
using (var stream = assembly.GetManifestResourceStream("GitHub.Runner.Worker.action_yaml.json"))
|
||||||
@@ -62,11 +59,11 @@ namespace GitHub.Runner.Worker
|
|||||||
// Clean up file name real quick
|
// Clean up file name real quick
|
||||||
// Instead of using Regex which can be computationally expensive,
|
// Instead of using Regex which can be computationally expensive,
|
||||||
// we can just remove the # of characters from the fileName according to the length of the basePath
|
// we can just remove the # of characters from the fileName according to the length of the basePath
|
||||||
string basePath = _hostContext.GetDirectory(WellKnownDirectory.Actions);
|
string basePath = HostContext.GetDirectory(WellKnownDirectory.Actions);
|
||||||
string fileName = manifestFile;
|
string fileRelativePath = manifestFile;
|
||||||
if (manifestFile.Length > basePath.Length + 1)
|
if (manifestFile.Length > basePath.Length + 1)
|
||||||
{
|
{
|
||||||
fileName = manifestFile.Remove(0, basePath.Length + 1);
|
fileRelativePath = manifestFile.Remove(0, basePath.Length + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -74,10 +71,13 @@ namespace GitHub.Runner.Worker
|
|||||||
var token = default(TemplateToken);
|
var token = default(TemplateToken);
|
||||||
|
|
||||||
// Get the file ID
|
// Get the file ID
|
||||||
var fileId = templateContext.GetFileId(fileName);
|
var fileId = templateContext.GetFileId(fileRelativePath);
|
||||||
|
|
||||||
// Add this file to the FileTable in executionContext
|
// Add this file to the FileTable in executionContext if it hasn't been added already
|
||||||
executionContext.FileTable.Add(fileName);
|
if (fileId > executionContext.FileTable.Count)
|
||||||
|
{
|
||||||
|
executionContext.FileTable.Add(fileRelativePath);
|
||||||
|
}
|
||||||
|
|
||||||
// Read the file
|
// Read the file
|
||||||
var fileContent = File.ReadAllText(manifestFile);
|
var fileContent = File.ReadAllText(manifestFile);
|
||||||
@@ -107,7 +107,7 @@ namespace GitHub.Runner.Worker
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "runs":
|
case "runs":
|
||||||
actionDefinition.Execution = ConvertRuns(executionContext, templateContext, actionPair.Value, fileId);
|
actionDefinition.Execution = ConvertRuns(executionContext, templateContext, actionPair.Value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Trace.Info($"Ignore action property {propertyName}.");
|
Trace.Info($"Ignore action property {propertyName}.");
|
||||||
@@ -129,7 +129,7 @@ namespace GitHub.Runner.Worker
|
|||||||
executionContext.Error(error.Message);
|
executionContext.Error(error.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ArgumentException($"Fail to load {fileName}");
|
throw new ArgumentException($"Fail to load {fileRelativePath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionDefinition.Execution == null)
|
if (actionDefinition.Execution == null)
|
||||||
@@ -311,8 +311,7 @@ namespace GitHub.Runner.Worker
|
|||||||
private ActionExecutionData ConvertRuns(
|
private ActionExecutionData ConvertRuns(
|
||||||
IExecutionContext executionContext,
|
IExecutionContext executionContext,
|
||||||
TemplateContext context,
|
TemplateContext context,
|
||||||
TemplateToken inputsToken,
|
TemplateToken inputsToken)
|
||||||
Int32 fileID)
|
|
||||||
{
|
{
|
||||||
var runsMapping = inputsToken.AssertMapping("runs");
|
var runsMapping = inputsToken.AssertMapping("runs");
|
||||||
var usingToken = default(StringToken);
|
var usingToken = default(StringToken);
|
||||||
@@ -379,7 +378,7 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
var steps = run.Value.AssertSequence("steps");
|
var steps = run.Value.AssertSequence("steps");
|
||||||
var evaluator = executionContext.ToPipelineTemplateEvaluator();
|
var evaluator = executionContext.ToPipelineTemplateEvaluator();
|
||||||
stepsLoaded = evaluator.LoadCompositeSteps(steps, context.GetFileTable());
|
stepsLoaded = evaluator.LoadCompositeSteps(steps);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
throw new Exception("You aren't supposed to be using Composite Actions yet!");
|
throw new Exception("You aren't supposed to be using Composite Actions yet!");
|
||||||
|
|||||||
@@ -160,20 +160,12 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ActionStep> LoadCompositeSteps(
|
public List<ActionStep> LoadCompositeSteps(
|
||||||
TemplateToken token,
|
TemplateToken token)
|
||||||
IReadOnlyList<String> fileTable)
|
|
||||||
{
|
{
|
||||||
var result = default(List<ActionStep>);
|
var result = default(List<ActionStep>);
|
||||||
if (token != null && token.Type != TokenType.Null)
|
if (token != null && token.Type != TokenType.Null)
|
||||||
{
|
{
|
||||||
// Create New Context Object
|
|
||||||
var context = CreateContext(null, null, setMissingContext: false);
|
var context = CreateContext(null, null, setMissingContext: false);
|
||||||
|
|
||||||
// Pass original filetable to the new context:
|
|
||||||
foreach (var f in fileTable) {
|
|
||||||
context.GetFileId(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
token = TemplateEvaluator.Evaluate(context, PipelineTemplateConstants.StepsInTemplate, token, 0, null, omitHeader: true);
|
token = TemplateEvaluator.Evaluate(context, PipelineTemplateConstants.StepsInTemplate, token, 0, null, omitHeader: true);
|
||||||
|
|||||||
Reference in New Issue
Block a user