mirror of
https://github.com/actions/runner.git
synced 2025-12-13 10:05:23 +00:00
Add necessary files + add functionality to convert to ActionStep object
This commit is contained in:
@@ -7,6 +7,9 @@ using GitHub.DistributedTask.WebApi;
|
||||
using Pipelines = GitHub.DistributedTask.Pipelines;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
||||
using System.Collections.Generic;
|
||||
using GitHub.DistributedTask.Pipelines.ContextData;
|
||||
|
||||
namespace GitHub.Runner.Worker.Handlers
|
||||
{
|
||||
@@ -21,50 +24,103 @@ namespace GitHub.Runner.Worker.Handlers
|
||||
{
|
||||
public CompositeActionExecutionData Data { get; set; }
|
||||
|
||||
public override void PrintActionDetails(ActionRunStage stage)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task RunAsync(ActionRunStage stage)
|
||||
{
|
||||
// Copied from NodEscriptActionHandler.cs
|
||||
// DELETE LATER
|
||||
// await Task.Yield();
|
||||
|
||||
// Copied from ScriptHandler.cs
|
||||
// Validate args.
|
||||
Trace.Entering();
|
||||
ArgUtil.NotNull(Data, nameof(Data));
|
||||
ArgUtil.NotNull(ExecutionContext, nameof(ExecutionContext));
|
||||
ArgUtil.NotNull(Inputs, nameof(Inputs));
|
||||
ArgUtil.Directory(ActionDirectory, nameof(ActionDirectory));
|
||||
|
||||
// Update the env dictionary.
|
||||
AddInputsToEnvironment();
|
||||
AddPrependPathToEnvironment();
|
||||
var githubContext = ExecutionContext.ExpressionValues["github"] as GitHubContext;
|
||||
ArgUtil.NotNull(githubContext, nameof(githubContext));
|
||||
|
||||
// expose context to environment
|
||||
// for example, this is how we know what OS the runner is running on
|
||||
foreach (var context in ExecutionContext.ExpressionValues)
|
||||
var tempDirectory = HostContext.GetDirectory(WellKnownDirectory.Temp);
|
||||
|
||||
// Resolve steps
|
||||
var target = Data.Steps;
|
||||
|
||||
// For now, just assume it is 1 Run step
|
||||
// We will adapt this in the future.
|
||||
var runStepInputs= target[0].Inputs;
|
||||
|
||||
|
||||
|
||||
// For now assume it's just a run step.
|
||||
// runStep.TryGetValue("run", out var runDefaults);
|
||||
string prependPath = string.Join(Path.PathSeparator.ToString(), runStep..Reverse<string>());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Copied from ScriptHandler.cs and ScriptHandlerHelpers.cs to handle bash commands.
|
||||
string argFormat;
|
||||
string shellCommand;
|
||||
string shellCommandPath = null;
|
||||
bool validateShellOnHost = !(StepHost is ContainerStepHost);
|
||||
string prependPath = string.Join(Path.PathSeparator.ToString(), ExecutionContext.PrependPath.Reverse<string>());
|
||||
string shell = null;
|
||||
if (!Inputs.TryGetValue("shell", out shell) || string.IsNullOrEmpty(shell))
|
||||
{
|
||||
if (context.Value is IEnvironmentContextData runtimeContext && runtimeContext != null)
|
||||
// TODO: figure out how defaults interact with template later
|
||||
// for now, we won't check job.defaults if we are inside a template.
|
||||
if (string.IsNullOrEmpty(ExecutionContext.ScopeName) && ExecutionContext.JobDefaults.TryGetValue("run", out var runDefaults))
|
||||
{
|
||||
foreach (var env in runtimeContext.GetRuntimeEnvironmentVariables())
|
||||
runDefaults.TryGetValue("shell", out shell);
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(shell))
|
||||
{
|
||||
#if OS_WINDOWS
|
||||
shellCommand = "pwsh";
|
||||
if (validateShellOnHost)
|
||||
{
|
||||
shellCommandPath = WhichUtil.Which(shellCommand, require: false, Trace, prependPath);
|
||||
if (string.IsNullOrEmpty(shellCommandPath))
|
||||
{
|
||||
Environment[env.Key] = env.Value;
|
||||
shellCommand = "powershell";
|
||||
Trace.Info($"Defaulting to {shellCommand}");
|
||||
shellCommandPath = WhichUtil.Which(shellCommand, require: true, Trace, prependPath);
|
||||
}
|
||||
}
|
||||
#else
|
||||
shellCommand = "sh";
|
||||
if (validateShellOnHost)
|
||||
{
|
||||
shellCommandPath = WhichUtil.Which("bash", false, Trace, prependPath) ?? WhichUtil.Which("sh", true, Trace, prependPath);
|
||||
}
|
||||
#endif
|
||||
argFormat = ScriptHandlerHelpers.GetScriptArgumentsFormat(shellCommand);
|
||||
}
|
||||
else
|
||||
{
|
||||
var parsed = ScriptHandlerHelpers.ParseShellOptionString(shell);
|
||||
shellCommand = parsed.shellCommand;
|
||||
if (validateShellOnHost)
|
||||
{
|
||||
shellCommandPath = WhichUtil.Which(parsed.shellCommand, true, Trace, prependPath);
|
||||
}
|
||||
|
||||
argFormat = $"{parsed.shellArgs}".TrimStart();
|
||||
if (string.IsNullOrEmpty(argFormat))
|
||||
{
|
||||
argFormat = ScriptHandlerHelpers.GetScriptArgumentsFormat(shellCommand);
|
||||
}
|
||||
}
|
||||
|
||||
// Add Actions Runtime server info
|
||||
var systemConnection = ExecutionContext.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));
|
||||
Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri;
|
||||
Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken];
|
||||
if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
|
||||
{
|
||||
Environment["ACTIONS_CACHE_URL"] = cacheUrl;
|
||||
}
|
||||
|
||||
// Resolve steps
|
||||
// How do I handle the MappingToken?
|
||||
MappingToken target = null;
|
||||
if (stage == ActionRunStage.Main)
|
||||
{
|
||||
target = Data.Steps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user