mirror of
https://github.com/actions/runner.git
synced 2025-12-10 20:36:49 +00:00
Compare commits
3 Commits
v2.286.1
...
h10s-assoc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
558f6d1a29 | ||
|
|
fbd859454b | ||
|
|
904eb7df8a |
@@ -150,7 +150,8 @@ namespace GitHub.Runner.Worker
|
|||||||
containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.PullActionContainerAsync,
|
containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.PullActionContainerAsync,
|
||||||
condition: $"{PipelineTemplateConstants.Success}()",
|
condition: $"{PipelineTemplateConstants.Success}()",
|
||||||
displayName: $"Pull {imageToPull.Key}",
|
displayName: $"Pull {imageToPull.Key}",
|
||||||
data: new ContainerSetupInfo(imageToPull.Value, imageToPull.Key)));
|
data: new ContainerSetupInfo(imageToPull.Value, imageToPull.Key),
|
||||||
|
repositoryRef: null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +164,8 @@ namespace GitHub.Runner.Worker
|
|||||||
containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.BuildActionContainerAsync,
|
containerSetupSteps.Add(new JobExtensionRunner(runAsync: this.BuildActionContainerAsync,
|
||||||
condition: $"{PipelineTemplateConstants.Success}()",
|
condition: $"{PipelineTemplateConstants.Success}()",
|
||||||
displayName: $"Build {setupInfo.ActionRepository}",
|
displayName: $"Build {setupInfo.ActionRepository}",
|
||||||
data: new ContainerSetupInfo(imageToBuild.Value, setupInfo.Dockerfile, setupInfo.WorkingDirectory)));
|
data: new ContainerSetupInfo(imageToBuild.Value, setupInfo.Dockerfile, setupInfo.WorkingDirectory),
|
||||||
|
repositoryRef: setupInfo.RepositoryRef));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,6 +778,7 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
|
|
||||||
var setupInfo = new ActionContainer();
|
var setupInfo = new ActionContainer();
|
||||||
|
setupInfo.RepositoryRef = repositoryReference;
|
||||||
string destDirectory = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Actions), repositoryReference.Name.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar), repositoryReference.Ref);
|
string destDirectory = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Actions), repositoryReference.Name.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar), repositoryReference.Ref);
|
||||||
string actionEntryDirectory = destDirectory;
|
string actionEntryDirectory = destDirectory;
|
||||||
string dockerFileRelativePath = repositoryReference.Name;
|
string dockerFileRelativePath = repositoryReference.Name;
|
||||||
@@ -1022,5 +1025,6 @@ namespace GitHub.Runner.Worker
|
|||||||
public string Dockerfile { get; set; }
|
public string Dockerfile { get; set; }
|
||||||
public string WorkingDirectory { get; set; }
|
public string WorkingDirectory { get; set; }
|
||||||
public string ActionRepository { get; set; }
|
public string ActionRepository { get; set; }
|
||||||
|
public Pipelines.RepositoryPathReference RepositoryRef { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ namespace GitHub.Runner.Worker
|
|||||||
var postJobStep = new JobExtensionRunner(runAsync: this.StopContainersAsync,
|
var postJobStep = new JobExtensionRunner(runAsync: this.StopContainersAsync,
|
||||||
condition: $"{PipelineTemplateConstants.Always}()",
|
condition: $"{PipelineTemplateConstants.Always}()",
|
||||||
displayName: "Stop containers",
|
displayName: "Stop containers",
|
||||||
data: data);
|
data: data,
|
||||||
|
repositoryRef: null);
|
||||||
|
|
||||||
executionContext.Debug($"Register post job cleanup for stopping/deleting containers.");
|
executionContext.Debug($"Register post job cleanup for stopping/deleting containers.");
|
||||||
executionContext.RegisterPostJobStep(postJobStep);
|
executionContext.RegisterPostJobStep(postJobStep);
|
||||||
|
|||||||
@@ -260,7 +260,9 @@ namespace GitHub.Runner.Worker
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
step.ExecutionContext = Root.CreatePostChild(step.DisplayName, IntraActionState);
|
string refName = step.GetRefName();
|
||||||
|
|
||||||
|
step.ExecutionContext = Root.CreatePostChild(step.DisplayName, refName, IntraActionState);
|
||||||
Root.PostJobSteps.Push(step);
|
Root.PostJobSteps.Push(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,6 +270,12 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
Trace.Entering();
|
Trace.Entering();
|
||||||
|
|
||||||
|
// TODO: Null out old, non-json refNames only if a FF is set.
|
||||||
|
if (refName != null && !refName.StartsWith("{"))
|
||||||
|
{
|
||||||
|
refName = null;
|
||||||
|
}
|
||||||
|
|
||||||
var child = new ExecutionContext();
|
var child = new ExecutionContext();
|
||||||
child.Initialize(HostContext);
|
child.Initialize(HostContext);
|
||||||
child.ScopeName = scopeName;
|
child.ScopeName = scopeName;
|
||||||
@@ -852,7 +860,7 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
Interlocked.Add(ref _totalThrottlingDelayInMilliseconds, Convert.ToInt64(data.Delay.TotalMilliseconds));
|
Interlocked.Add(ref _totalThrottlingDelayInMilliseconds, Convert.ToInt64(data.Delay.TotalMilliseconds));
|
||||||
|
|
||||||
if (!_throttlingReported &&
|
if (!_throttlingReported &&
|
||||||
_totalThrottlingDelayInMilliseconds > _throttlingDelayReportThreshold)
|
_totalThrottlingDelayInMilliseconds > _throttlingDelayReportThreshold)
|
||||||
{
|
{
|
||||||
this.Warning(string.Format("The job is currently being throttled by the server. You may experience delays in console line output, job status reporting, and action log uploads."));
|
this.Warning(string.Format("The job is currently being throttled by the server. You may experience delays in console line output, job status reporting, and action log uploads."));
|
||||||
@@ -861,7 +869,7 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IExecutionContext CreatePostChild(string displayName, Dictionary<string, string> intraActionState)
|
private IExecutionContext CreatePostChild(string displayName, string refName, Dictionary<string, string> intraActionState)
|
||||||
{
|
{
|
||||||
if (!_expandedForPostJob)
|
if (!_expandedForPostJob)
|
||||||
{
|
{
|
||||||
@@ -871,7 +879,9 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
|
|
||||||
var newGuid = Guid.NewGuid();
|
var newGuid = Guid.NewGuid();
|
||||||
return CreateChild(newGuid, displayName, newGuid.ToString("N"), null, null, intraActionState, _childTimelineRecordOrder - Root.PostJobSteps.Count);
|
|
||||||
|
// TODO: Check feature flag here, conditionally set refName to newGuid.ToString("N").
|
||||||
|
return CreateChild(newGuid, displayName, refName, null, null, intraActionState, _childTimelineRecordOrder - Root.PostJobSteps.Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
src/Runner.Worker/IStepExtensions.cs
Normal file
31
src/Runner.Worker/IStepExtensions.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace GitHub.Runner.Worker
|
||||||
|
{
|
||||||
|
public static class IStepExtensions
|
||||||
|
{
|
||||||
|
public static string GetRefName(this IStep step, string defaultRefName = null)
|
||||||
|
{
|
||||||
|
// TODO: Really check a feature flag.
|
||||||
|
if (s_featureFlagEnabled)
|
||||||
|
{
|
||||||
|
if (step is JobExtensionRunner extensionRunner && extensionRunner.RepositoryRef != null)
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(extensionRunner.RepositoryRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (step is IActionRunner actionRunner && actionRunner.Action?.Reference != null)
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(actionRunner.Action.Reference);
|
||||||
|
}
|
||||||
|
|
||||||
|
// RefName should always be valid json or null.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultRefName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool s_featureFlagEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -213,9 +213,10 @@ namespace GitHub.Runner.Worker
|
|||||||
containers.AddRange(jobContext.ServiceContainers);
|
containers.AddRange(jobContext.ServiceContainers);
|
||||||
|
|
||||||
preJobSteps.Add(new JobExtensionRunner(runAsync: containerProvider.StartContainersAsync,
|
preJobSteps.Add(new JobExtensionRunner(runAsync: containerProvider.StartContainersAsync,
|
||||||
condition: $"{PipelineTemplateConstants.Success}()",
|
condition: $"{PipelineTemplateConstants.Success}()",
|
||||||
displayName: "Initialize containers",
|
displayName: "Initialize containers",
|
||||||
data: (object)containers));
|
data: (object)containers,
|
||||||
|
repositoryRef: null));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add action steps
|
// Add action steps
|
||||||
@@ -260,18 +261,19 @@ namespace GitHub.Runner.Worker
|
|||||||
// Create execution context for pre-job steps
|
// Create execution context for pre-job steps
|
||||||
foreach (var step in preJobSteps)
|
foreach (var step in preJobSteps)
|
||||||
{
|
{
|
||||||
if (step is JobExtensionRunner)
|
if (step is JobExtensionRunner extensionStep)
|
||||||
{
|
{
|
||||||
JobExtensionRunner extensionStep = step as JobExtensionRunner;
|
ArgUtil.NotNull(extensionStep, step.DisplayName);
|
||||||
ArgUtil.NotNull(extensionStep, extensionStep.DisplayName);
|
|
||||||
Guid stepId = Guid.NewGuid();
|
Guid stepId = Guid.NewGuid();
|
||||||
extensionStep.ExecutionContext = jobContext.CreateChild(stepId, extensionStep.DisplayName, null, null, stepId.ToString("N"));
|
var refName = step.GetRefName(defaultRefName: null);
|
||||||
|
extensionStep.ExecutionContext = jobContext.CreateChild(stepId, extensionStep.DisplayName, refName, null, stepId.ToString("N"));
|
||||||
}
|
}
|
||||||
else if (step is IActionRunner actionStep)
|
else if (step is IActionRunner actionStep)
|
||||||
{
|
{
|
||||||
ArgUtil.NotNull(actionStep, step.DisplayName);
|
ArgUtil.NotNull(actionStep, step.DisplayName);
|
||||||
Guid stepId = Guid.NewGuid();
|
Guid stepId = Guid.NewGuid();
|
||||||
actionStep.ExecutionContext = jobContext.CreateChild(stepId, actionStep.DisplayName, stepId.ToString("N"), null, null, intraActionStates[actionStep.Action.Id]);
|
var refName = step.GetRefName(defaultRefName: stepId.ToString("N"));
|
||||||
|
actionStep.ExecutionContext = jobContext.CreateChild(stepId, actionStep.DisplayName, refName, null, null, intraActionStates[actionStep.Action.Id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +284,8 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
ArgUtil.NotNull(actionStep, step.DisplayName);
|
ArgUtil.NotNull(actionStep, step.DisplayName);
|
||||||
intraActionStates.TryGetValue(actionStep.Action.Id, out var intraActionState);
|
intraActionStates.TryGetValue(actionStep.Action.Id, out var intraActionState);
|
||||||
actionStep.ExecutionContext = jobContext.CreateChild(actionStep.Action.Id, actionStep.DisplayName, actionStep.Action.Name, actionStep.Action.ScopeName, actionStep.Action.ContextName, intraActionState);
|
var refName = step.GetRefName(defaultRefName: actionStep.Action.Name);
|
||||||
|
actionStep.ExecutionContext = jobContext.CreateChild(actionStep.Action.Id, actionStep.DisplayName, refName, actionStep.Action.ScopeName, actionStep.Action.ContextName, intraActionState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GitHub.DistributedTask.Expressions2;
|
|
||||||
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
||||||
|
using GitHub.DistributedTask.Pipelines;
|
||||||
|
|
||||||
namespace GitHub.Runner.Worker
|
namespace GitHub.Runner.Worker
|
||||||
{
|
{
|
||||||
@@ -9,22 +9,26 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
private readonly object _data;
|
private readonly object _data;
|
||||||
private readonly Func<IExecutionContext, object, Task> _runAsync;
|
private readonly Func<IExecutionContext, object, Task> _runAsync;
|
||||||
|
private readonly RepositoryPathReference _repositoryRef;
|
||||||
|
|
||||||
public JobExtensionRunner(
|
public JobExtensionRunner(
|
||||||
Func<IExecutionContext, object, Task> runAsync,
|
Func<IExecutionContext, object, Task> runAsync,
|
||||||
string condition,
|
string condition,
|
||||||
string displayName,
|
string displayName,
|
||||||
object data)
|
object data,
|
||||||
|
RepositoryPathReference repositoryRef)
|
||||||
{
|
{
|
||||||
_runAsync = runAsync;
|
_runAsync = runAsync;
|
||||||
Condition = condition;
|
Condition = condition;
|
||||||
DisplayName = displayName;
|
DisplayName = displayName;
|
||||||
_data = data;
|
_data = data;
|
||||||
|
_repositoryRef = repositoryRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Condition { get; set; }
|
public string Condition { get; set; }
|
||||||
public TemplateToken ContinueOnError => new BooleanToken(null, null, null, false);
|
public TemplateToken ContinueOnError => new BooleanToken(null, null, null, false);
|
||||||
public string DisplayName { get; set; }
|
public string DisplayName { get; set; }
|
||||||
|
public RepositoryPathReference RepositoryRef => _repositoryRef;
|
||||||
public IExecutionContext ExecutionContext { get; set; }
|
public IExecutionContext ExecutionContext { get; set; }
|
||||||
public TemplateToken Timeout => new NumberToken(null, null, null, 0);
|
public TemplateToken Timeout => new NumberToken(null, null, null, 0);
|
||||||
public object Data => _data;
|
public object Data => _data;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace GitHub.DistributedTask.Pipelines
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
[KnownType(typeof(ContainerRegistryReference))]
|
[KnownType(typeof(ContainerRegistryReference))]
|
||||||
[KnownType(typeof(RepositoryPathReference))]
|
[KnownType(typeof(RepositoryPathReference))]
|
||||||
[KnownType(typeof(ScriptReference))]
|
[KnownType(typeof(ScriptReference))]
|
||||||
[JsonConverter(typeof(ActionStepDefinitionReferenceConverter))]
|
[JsonConverter(typeof(ActionStepDefinitionReferenceConverter))]
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
public abstract class ActionStepDefinitionReference
|
public abstract class ActionStepDefinitionReference
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
jobExtension.Initialize(hc);
|
jobExtension.Initialize(hc);
|
||||||
|
|
||||||
_actionManager.Setup(x => x.PrepareActionsAsync(It.IsAny<IExecutionContext>(), It.IsAny<IEnumerable<Pipelines.JobStep>>()))
|
_actionManager.Setup(x => x.PrepareActionsAsync(It.IsAny<IExecutionContext>(), It.IsAny<IEnumerable<Pipelines.JobStep>>()))
|
||||||
.Returns(Task.FromResult(new PrepareResult(new List<JobExtensionRunner>() { new JobExtensionRunner(null, "", "prepare1", null), new JobExtensionRunner(null, "", "prepare2", null) }, new Dictionary<Guid, IActionRunner>())));
|
.Returns(Task.FromResult(new PrepareResult(new List<JobExtensionRunner>() { new JobExtensionRunner(null, "", "prepare1", null, null), new JobExtensionRunner(null, "", "prepare2", null, null) }, new Dictionary<Guid, IActionRunner>())));
|
||||||
|
|
||||||
List<IStep> result = await jobExtension.InitializeJob(_jobEc, _message);
|
List<IStep> result = await jobExtension.InitializeJob(_jobEc, _message);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user