Compare commits

...

27 Commits

Author SHA1 Message Date
Ethan Chiu
0e0ab644db Fix GITHUB_ACTION not being set 2020-08-03 20:31:54 -04:00
Ethan Chiu
46245a1a71 Resolve Template Error by Adding ExpressionFunctions 2020-08-03 16:30:37 -04:00
Ethan Chiu
45345dc981 testing... 2020-07-31 15:30:48 -04:00
Ethan Chiu
7ab3d5ad42 progress... 2020-07-28 17:29:43 -04:00
Ethan Chiu
4c02d0a685 new function for inputs within a composite action 2020-07-28 10:36:00 -04:00
Ethan Chiu
3d36af47f1 Experimentation with evaluating inputs in the context 2020-07-27 17:45:20 -04:00
Ethan Chiu
992ce4b924 add new changes 2020-07-27 14:17:30 -04:00
Ethan Chiu
e927bacf3c revert 2020-07-27 14:17:01 -04:00
Ethan Chiu
1ce75f188b Merge branch 'main' of https://github.com/actions/runner into compositeActionProofOfConcept 2020-07-27 14:09:12 -04:00
Ethan Chiu
e0d4270cc1 Remove passing context to all composite steps attribuyte 2020-07-27 13:04:33 -04:00
Ethan Chiu
49893b6ede Merge branch 'main' of https://github.com/actions/runner into users/ethanchewy/compositeRestrictUnknownBehavior 2020-07-27 12:45:45 -04:00
Ethan Chiu
6a46ef1c47 Make shell required + add inputs 2020-07-27 12:32:32 -04:00
Ethan Chiu
80540edd4e Fix templating errors 2020-07-23 13:01:09 -04:00
Ethan Chiu
cc8e2738ef Add 'uses' and 'with' to action yaml and change names to be consistent with workflow yaml 2020-07-23 12:22:38 -04:00
Ethan Chiu
e9dcc05d75 Merge branch 'users/ethanchewy/compositeRestrictUnknownBehavior' of https://github.com/actions/runner into compositeActionProofOfConcept 2020-07-23 12:17:08 -04:00
Ethan Chiu
a24e33bbcc Remove needs in env 2020-07-22 12:48:52 -04:00
Ethan Chiu
5dfb2cc552 revert 2020-07-21 17:55:34 -04:00
Ethan Chiu
143266bc96 Revert "Revert "Add safety check to prevent from checking defaults in ScriptHandler for composite action""
This reverts commit a22fcbc036.
2020-07-21 17:53:29 -04:00
Ethan Chiu
522fbd0546 Remove todos 2020-07-21 17:46:51 -04:00
Ethan Chiu
2bfa135739 Fix ActionManifestManager 2020-07-21 17:46:09 -04:00
Ethan Chiu
3381b951a0 Need to explictly use ActionStep type since we need the .Inputs attribute which is only found in the ActionStep not IStep 2020-07-21 17:36:40 -04:00
Ethan Chiu
a22fcbc036 Revert "Add safety check to prevent from checking defaults in ScriptHandler for composite action"
This reverts commit aeae15de7b.
2020-07-21 14:45:58 -04:00
Ethan Chiu
aeae15de7b Add safety check to prevent from checking defaults in ScriptHandler for composite action 2020-07-21 14:33:58 -04:00
Ethan Chiu
6602117989 new line 2020-07-21 13:11:46 -04:00
Ethan Chiu
89412f35bf Remove secrets + defaults 2020-07-21 11:23:25 -04:00
Ethan Chiu
220793d4e9 Add step-env 2020-07-20 17:46:02 -04:00
Ethan Chiu
645ba099b9 Explicitly define what is allowed for an action 2020-07-20 17:41:57 -04:00
5 changed files with 174 additions and 4 deletions

View File

@@ -30,6 +30,8 @@ namespace GitHub.Runner.Worker
Dictionary<string, string> EvaluateContainerEnvironment(IExecutionContext executionContext, MappingToken token, IDictionary<string, PipelineContextData> extraExpressionValues);
string EvaluateDefaultInput(IExecutionContext executionContext, string inputName, TemplateToken token);
// string EvaluateDefaultInputInsideComposite(IExecutionContext executionContext, string inputName, TemplateToken token);
}
public sealed class ActionManifestManager : RunnerService, IActionManifestManager
@@ -282,6 +284,9 @@ namespace GitHub.Runner.Worker
if (token != null)
{
var templateContext = CreateTemplateContext(executionContext);
Trace.Info($"Template context GitHub: {StringUtil.ConvertToJson(templateContext.ExpressionValues["github"])}");
Trace.Info($"Template context keys: {StringUtil.ConvertToJson(templateContext.ExpressionValues.Keys)}");
try
{
var evaluateResult = TemplateEvaluator.Evaluate(templateContext, "input-default-context", token, 0, null, omitHeader: true);
@@ -304,6 +309,83 @@ namespace GitHub.Runner.Worker
return result;
}
// public string EvaluateDefaultInputInsideComposite(
// IExecutionContext executionContext,
// string inputName,
// TemplateToken token)
// {
// string result = "";
// if (token != null)
// {
// // Add GitHub Expression Values
// var githubContext = executionContext.ExpressionValues["github"];
// Trace.Info($"GitHub Context EvaluateDefaultInputInsideComposite: {StringUtil.ConvertToJson(githubContext)}");
// var temp = new Dictionary<string, PipelineContextData>();
// temp["github"] = githubContext;
// // Trace.Info($"Token: {StringUtil.ConvertToJson(token)}");
// var templateContext = CreateTemplateContext(executionContext, temp);
// try
// {
// var evaluateResult = TemplateEvaluator.Evaluate(templateContext, "uses-input", token, 0, null, omitHeader: true);
// Trace.Info($"Input '{inputName}': default value evaluate result: {StringUtil.ConvertToJson(evaluateResult)}");
// templateContext.Errors.Check();
// // Can't evaluate the default github.respository, etc.
// // TODO: restrict to only be used for composite "uses" steps
// // Find better way to isolate only
// // We could create a whitelist for just checkout?
// // (ex: "repo", "token", etc.)
// // if (evaluateResult is BasicExpressionToken)
// // {
// // // var evaluateResult2 = TemplateEvaluator.Evaluate(templateContext, "step-with", token, 0, null, omitHeader: true);
// // // templateContext.Errors.Check();
// // // Trace.Info($"Test2 Input '{inputName}': default value evaluate result: {StringUtil.ConvertToJson(evaluateResult2)}");
// // // var result2 = evaluateResult2.AssertString($"default value for input '{inputName}'").Value;
// // // TODO 6/28 => Try just getting it from the getgithubcontext lmao.
// // // Trace.Info($"Basic expr token: {evaluateResult}");
// // var stringVersion = evaluateResult.AssertString($"default value for input '{inputName}'").Value;
// // // no we have to use the template evaluator since it's a
// // // var githubTokenSplit =
// // // // Evaluate it
// // // var evaluateResult = executionContext.GetGitHubContext("");
// // return result2;
// // }
// // Trace.Info($"Input '{inputName}': default value evaluate result: {StringUtil.ConvertToJson(evaluateResult)}");
// // String
// result = evaluateResult.AssertString($"default value for input '{inputName}'").Value;
// }
// catch (Exception ex) when (!(ex is TemplateValidationException))
// {
// Trace.Error(ex);
// templateContext.Errors.Add(ex);
// }
// templateContext.Errors.Check();
// }
// return result;
// }
private TemplateContext CreateTemplateContext(
IExecutionContext executionContext,
IDictionary<string, PipelineContextData> extraExpressionValues = null)

View File

@@ -169,6 +169,25 @@ namespace GitHub.Runner.Worker
validInputs.Add("entryPoint");
validInputs.Add("args");
}
Trace.Info($"Repo: {ExecutionContext.GetGitHubContext("repository")}");
// Since we don't pass the GitHub Context attributes to the composite action,
// We need to explitly set the default values of certain things we need like the
// default repository
// if (ExecutionContext.GetGitHubContext("repository") == null)
// {
// ExecutionContext.SetGitHubContext("repository", definition.Directory);
// }
// var githubContext = ExecutionContext.ExpressionValues["github"] as GitHubContext;
// foreach (var pair in githubContext)
// {
// ExecutionContext.SetGitHubContext(pair.Key, pair.Value as StringContextData);
// }
// Merge the default inputs from the definition
if (definition.Data?.Inputs != null)
{
@@ -179,7 +198,17 @@ namespace GitHub.Runner.Worker
validInputs.Add(key);
if (!inputs.ContainsKey(key))
{
Trace.Info($"Definition Input Key: {key}");
// if (ExecutionContext.InsideComposite)
// {
// inputs[key] = manifestManager.EvaluateDefaultInputInsideComposite(ExecutionContext, key, input.Value);
// }
// else
// {
// inputs[key] = manifestManager.EvaluateDefaultInput(ExecutionContext, key, input.Value);
// }
inputs[key] = manifestManager.EvaluateDefaultInput(ExecutionContext, key, input.Value);
Trace.Info($"Definition Input Value: {inputs[key]}");
}
}
}

View File

@@ -5,11 +5,14 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using GitHub.DistributedTask.Expressions2;
using GitHub.DistributedTask.ObjectTemplating.Tokens;
using GitHub.DistributedTask.Pipelines.ContextData;
using GitHub.DistributedTask.Pipelines.ObjectTemplating;
using GitHub.DistributedTask.WebApi;
using GitHub.Runner.Common;
using GitHub.Runner.Sdk;
using GitHub.Runner.Worker.Expressions;
using Pipelines = GitHub.DistributedTask.Pipelines;
@@ -35,6 +38,8 @@ namespace GitHub.Runner.Worker.Handlers
var githubContext = ExecutionContext.ExpressionValues["github"] as GitHubContext;
ArgUtil.NotNull(githubContext, nameof(githubContext));
// Trace.Info($"Github Context: {StringUtil.ConvertToJson(githubContext)}");
// Resolve action steps
var actionSteps = Data.Steps;
@@ -45,6 +50,8 @@ namespace GitHub.Runner.Worker.Handlers
inputsData[i.Key] = new StringContextData(i.Value);
}
Trace.Info($"Composite Actions Inputs {StringUtil.ConvertToJson(inputsData)}");
// Initialize Composite Steps List of Steps
var compositeSteps = new List<IStep>();
@@ -61,7 +68,7 @@ namespace GitHub.Runner.Worker.Handlers
var compositeGitHubContext = new GitHubContext();
foreach (var pair in githubContext)
{
compositeGitHubContext[pair.Key] = pair.Value;
compositeGitHubContext[pair.Key] = pair.Value.Clone();
}
foreach (Pipelines.ActionStep actionStep in actionSteps)
@@ -76,6 +83,7 @@ namespace GitHub.Runner.Worker.Handlers
// Set GITHUB_ACTION_PATH
step.ExecutionContext.ExpressionValues["github"] = compositeGitHubContext;
step.ExecutionContext.SetGitHubContext("action_path", ActionDirectory);
step.ExecutionContext.ExpressionFunctions.Add(new FunctionInfo<HashFilesFunction>(PipelineTemplateConstants.HashFiles, 1, byte.MaxValue));
compositeSteps.Add(step);
}

View File

@@ -109,9 +109,15 @@
},
"composite-steps": {
"sequence": {
"item-type": "composite-step"
"item-type": "composite-step-types"
}
},
"composite-step-types": {
"one-of": [
"composite-step",
"uses-step"
]
},
"composite-step": {
"mapping": {
"properties": {
@@ -130,6 +136,20 @@
}
}
},
"uses-step": {
"mapping": {
"properties": {
"name": "string-steps-context",
"id": "non-empty-string",
"uses": {
"type": "non-empty-string",
"required": true
},
"with": "step-with",
"env": "step-env"
}
}
},
"container-runs-context": {
"context": [
"inputs"
@@ -195,6 +215,37 @@
"loose-key-type": "non-empty-string",
"loose-value-type": "string"
}
},
"step-with": {
"context": [
"github",
"inputs",
"strategy",
"matrix",
"steps",
"job",
"runner",
"env",
"hashFiles(1,255)"
],
"mapping": {
"loose-key-type": "non-empty-string",
"loose-value-type": "string"
}
},
"uses-input": {
"context": [
"github",
"inputs",
"strategy",
"matrix",
"steps",
"job",
"runner",
"env",
"hashFiles(1,255)"
],
"string": {}
}
}
}
}

View File

@@ -1 +1 @@
2.272.0
2.274.0