mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +00:00
Compare commits
7 Commits
v2.291.1
...
users/eric
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5097eb3fe4 | ||
|
|
912078dcdf | ||
|
|
660784ecbe | ||
|
|
eeeff071c7 | ||
|
|
1e1d225896 | ||
|
|
a6ece8b1bf | ||
|
|
40e004c60d |
10
.github/workflows/release.yml
vendored
10
.github/workflows/release.yml
vendored
@@ -101,11 +101,11 @@ jobs:
|
|||||||
working-directory: src
|
working-directory: src
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
#- name: L0
|
- name: L0
|
||||||
# run: |
|
run: |
|
||||||
# ${{ matrix.devScript }} test
|
${{ matrix.devScript }} test
|
||||||
# working-directory: src
|
working-directory: src
|
||||||
# if: matrix.runtime != 'linux-arm64' && matrix.runtime != 'linux-arm'
|
if: matrix.runtime != 'linux-arm64' && matrix.runtime != 'linux-arm'
|
||||||
|
|
||||||
# Create runner package tar.gz/zip
|
# Create runner package tar.gz/zip
|
||||||
- name: Package Release
|
- name: Package Release
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
- Fixed a bug where windows path separators were used in generated folders (#1617)
|
- Fixed an issue where websockets failed to successfully close when posting log lines (#1790)
|
||||||
- Fixed an issue where runner's invoked via `run.sh` or `run.cmd` did not properly restart after update (#1812). This fix applies to all future updates after installing this version
|
|
||||||
|
|
||||||
## Misc
|
|
||||||
- Relaxed Actions Summary size limit to 1MiB (#1839)
|
|
||||||
|
|
||||||
## Windows x64
|
## Windows x64
|
||||||
We recommend configuring the runner in a root folder of the Windows drive (e.g. "C:\actions-runner"). This will help avoid issues related to service identity folder permissions and long file path restrictions on Windows.
|
We recommend configuring the runner in a root folder of the Windows drive (e.g. "C:\actions-runner"). This will help avoid issues related to service identity folder permissions and long file path restrictions on Windows.
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2.291.1
|
<Update to ./src/runnerversion when creating release>
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace GitHub.Runner.Common
|
|||||||
public static class CommandLine
|
public static class CommandLine
|
||||||
{
|
{
|
||||||
//if you are adding a new arg, please make sure you update the
|
//if you are adding a new arg, please make sure you update the
|
||||||
//validOptions dictionary as well present in the CommandSettings.cs
|
//validArgs array as well present in the CommandSettings.cs
|
||||||
public static class Args
|
public static class Args
|
||||||
{
|
{
|
||||||
public static readonly string Auth = "auth";
|
public static readonly string Auth = "auth";
|
||||||
@@ -121,7 +121,7 @@ namespace GitHub.Runner.Common
|
|||||||
}
|
}
|
||||||
|
|
||||||
//if you are adding a new flag, please make sure you update the
|
//if you are adding a new flag, please make sure you update the
|
||||||
//validOptions dictionary as well present in the CommandSettings.cs
|
//validFlags array as well present in the CommandSettings.cs
|
||||||
public static class Flags
|
public static class Flags
|
||||||
{
|
{
|
||||||
public static readonly string Check = "check";
|
public static readonly string Check = "check";
|
||||||
@@ -150,7 +150,6 @@ namespace GitHub.Runner.Common
|
|||||||
{
|
{
|
||||||
public static readonly string DiskSpaceWarning = "runner.diskspace.warning";
|
public static readonly string DiskSpaceWarning = "runner.diskspace.warning";
|
||||||
public static readonly string Node12Warning = "DistributedTask.AddWarningToNode12Action";
|
public static readonly string Node12Warning = "DistributedTask.AddWarningToNode12Action";
|
||||||
public static readonly string UseContainerPathForTemplate = "DistributedTask.UseContainerPathForTemplate";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly string InternalTelemetryIssueDataKey = "_internal_telemetry";
|
public static readonly string InternalTelemetryIssueDataKey = "_internal_telemetry";
|
||||||
|
|||||||
76
src/Runner.Common/RunServer.cs
Normal file
76
src/Runner.Common/RunServer.cs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using GitHub.DistributedTask.Pipelines;
|
||||||
|
using GitHub.DistributedTask.WebApi;
|
||||||
|
using GitHub.Runner.Common.Util;
|
||||||
|
using GitHub.Runner.Sdk;
|
||||||
|
using GitHub.Services.Common;
|
||||||
|
using GitHub.Services.WebApi;
|
||||||
|
|
||||||
|
namespace GitHub.Runner.Common
|
||||||
|
{
|
||||||
|
[ServiceLocator(Default = typeof(RunServer))]
|
||||||
|
public interface IRunServer : IRunnerService
|
||||||
|
{
|
||||||
|
Task ConnectAsync(Uri serverUrl, VssCredentials credentials);
|
||||||
|
|
||||||
|
Task<AgentJobRequestMessage> GetJobMessageAsync(string id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RunServer : RunnerService, IRunServer
|
||||||
|
{
|
||||||
|
private bool _hasConnection;
|
||||||
|
private VssConnection _connection;
|
||||||
|
private TaskAgentHttpClient _taskAgentClient;
|
||||||
|
|
||||||
|
public async Task ConnectAsync(Uri serverUrl, VssCredentials credentials)
|
||||||
|
{
|
||||||
|
_connection = await EstablishVssConnection(serverUrl, credentials, TimeSpan.FromSeconds(100));
|
||||||
|
_taskAgentClient = _connection.GetClient<TaskAgentHttpClient>();
|
||||||
|
_hasConnection = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<VssConnection> EstablishVssConnection(Uri serverUrl, VssCredentials credentials, TimeSpan timeout)
|
||||||
|
{
|
||||||
|
Trace.Info($"EstablishVssConnection");
|
||||||
|
Trace.Info($"Establish connection with {timeout.TotalSeconds} seconds timeout.");
|
||||||
|
int attemptCount = 5;
|
||||||
|
while (attemptCount-- > 0)
|
||||||
|
{
|
||||||
|
var connection = VssUtil.CreateConnection(serverUrl, credentials, timeout: timeout);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await connection.ConnectAsync();
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (attemptCount > 0)
|
||||||
|
{
|
||||||
|
Trace.Info($"Catch exception during connect. {attemptCount} attempt left.");
|
||||||
|
Trace.Error(ex);
|
||||||
|
|
||||||
|
await HostContext.Delay(TimeSpan.FromMilliseconds(100), CancellationToken.None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// should never reach here.
|
||||||
|
throw new InvalidOperationException(nameof(EstablishVssConnection));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckConnection()
|
||||||
|
{
|
||||||
|
if (!_hasConnection)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"SetConnection");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<AgentJobRequestMessage> GetJobMessageAsync(string id)
|
||||||
|
{
|
||||||
|
CheckConnection();
|
||||||
|
return _taskAgentClient.GetJobMessageAsync(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,57 +17,43 @@ namespace GitHub.Runner.Listener
|
|||||||
private readonly IPromptManager _promptManager;
|
private readonly IPromptManager _promptManager;
|
||||||
private readonly Tracing _trace;
|
private readonly Tracing _trace;
|
||||||
|
|
||||||
// Valid flags for all commands
|
private readonly string[] validCommands =
|
||||||
private readonly string[] genericOptions =
|
|
||||||
{
|
{
|
||||||
Constants.Runner.CommandLine.Flags.Help,
|
Constants.Runner.CommandLine.Commands.Configure,
|
||||||
Constants.Runner.CommandLine.Flags.Version,
|
Constants.Runner.CommandLine.Commands.Remove,
|
||||||
Constants.Runner.CommandLine.Flags.Commit,
|
Constants.Runner.CommandLine.Commands.Run,
|
||||||
Constants.Runner.CommandLine.Flags.Check
|
Constants.Runner.CommandLine.Commands.Warmup,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Valid flags and args for specific command - key: command, value: array of valid flags and args
|
private readonly string[] validFlags =
|
||||||
private readonly Dictionary<string, string[]> validOptions = new Dictionary<string, string[]>
|
|
||||||
{
|
{
|
||||||
// Valid configure flags and args
|
Constants.Runner.CommandLine.Flags.Check,
|
||||||
[Constants.Runner.CommandLine.Commands.Configure] =
|
Constants.Runner.CommandLine.Flags.Commit,
|
||||||
new string[]
|
Constants.Runner.CommandLine.Flags.DisableUpdate,
|
||||||
{
|
Constants.Runner.CommandLine.Flags.Ephemeral,
|
||||||
Constants.Runner.CommandLine.Flags.DisableUpdate,
|
Constants.Runner.CommandLine.Flags.Help,
|
||||||
Constants.Runner.CommandLine.Flags.Ephemeral,
|
Constants.Runner.CommandLine.Flags.Once,
|
||||||
Constants.Runner.CommandLine.Flags.Replace,
|
Constants.Runner.CommandLine.Flags.Replace,
|
||||||
Constants.Runner.CommandLine.Flags.RunAsService,
|
Constants.Runner.CommandLine.Flags.RunAsService,
|
||||||
Constants.Runner.CommandLine.Flags.Unattended,
|
Constants.Runner.CommandLine.Flags.Unattended,
|
||||||
Constants.Runner.CommandLine.Args.Auth,
|
Constants.Runner.CommandLine.Flags.Version
|
||||||
Constants.Runner.CommandLine.Args.Labels,
|
};
|
||||||
Constants.Runner.CommandLine.Args.MonitorSocketAddress,
|
|
||||||
Constants.Runner.CommandLine.Args.Name,
|
private readonly string[] validArgs =
|
||||||
Constants.Runner.CommandLine.Args.PAT,
|
{
|
||||||
Constants.Runner.CommandLine.Args.RunnerGroup,
|
Constants.Runner.CommandLine.Args.Auth,
|
||||||
Constants.Runner.CommandLine.Args.Token,
|
Constants.Runner.CommandLine.Args.Labels,
|
||||||
Constants.Runner.CommandLine.Args.Url,
|
Constants.Runner.CommandLine.Args.MonitorSocketAddress,
|
||||||
Constants.Runner.CommandLine.Args.UserName,
|
Constants.Runner.CommandLine.Args.Name,
|
||||||
Constants.Runner.CommandLine.Args.WindowsLogonAccount,
|
Constants.Runner.CommandLine.Args.PAT,
|
||||||
Constants.Runner.CommandLine.Args.WindowsLogonPassword,
|
Constants.Runner.CommandLine.Args.RunnerGroup,
|
||||||
Constants.Runner.CommandLine.Args.Work
|
Constants.Runner.CommandLine.Args.StartupType,
|
||||||
},
|
Constants.Runner.CommandLine.Args.Token,
|
||||||
// Valid remove flags and args
|
Constants.Runner.CommandLine.Args.Url,
|
||||||
[Constants.Runner.CommandLine.Commands.Remove] =
|
Constants.Runner.CommandLine.Args.UserName,
|
||||||
new string[]
|
Constants.Runner.CommandLine.Args.WindowsLogonAccount,
|
||||||
{
|
Constants.Runner.CommandLine.Args.WindowsLogonPassword,
|
||||||
Constants.Runner.CommandLine.Args.Token,
|
Constants.Runner.CommandLine.Args.Work
|
||||||
Constants.Runner.CommandLine.Args.PAT
|
|
||||||
},
|
|
||||||
// Valid run flags and args
|
|
||||||
[Constants.Runner.CommandLine.Commands.Run] =
|
|
||||||
new string[]
|
|
||||||
{
|
|
||||||
Constants.Runner.CommandLine.Flags.Once,
|
|
||||||
Constants.Runner.CommandLine.Args.StartupType
|
|
||||||
},
|
|
||||||
// valid warmup flags and args
|
|
||||||
[Constants.Runner.CommandLine.Commands.Warmup] =
|
|
||||||
new string[] { }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Commands.
|
// Commands.
|
||||||
@@ -140,48 +126,17 @@ namespace GitHub.Runner.Listener
|
|||||||
List<string> unknowns = new List<string>();
|
List<string> unknowns = new List<string>();
|
||||||
|
|
||||||
// detect unknown commands
|
// detect unknown commands
|
||||||
unknowns.AddRange(_parser.Commands.Where(x => !validOptions.Keys.Contains(x, StringComparer.OrdinalIgnoreCase)));
|
unknowns.AddRange(_parser.Commands.Where(x => !validCommands.Contains(x, StringComparer.OrdinalIgnoreCase)));
|
||||||
|
|
||||||
if (unknowns.Count == 0)
|
// detect unknown flags
|
||||||
{
|
unknowns.AddRange(_parser.Flags.Where(x => !validFlags.Contains(x, StringComparer.OrdinalIgnoreCase)));
|
||||||
// detect unknown flags and args for valid commands
|
|
||||||
foreach (var command in _parser.Commands)
|
// detect unknown args
|
||||||
{
|
unknowns.AddRange(_parser.Args.Keys.Where(x => !validArgs.Contains(x, StringComparer.OrdinalIgnoreCase)));
|
||||||
if (validOptions.TryGetValue(command, out string[] options))
|
|
||||||
{
|
|
||||||
unknowns.AddRange(_parser.Flags.Where(x => !options.Contains(x, StringComparer.OrdinalIgnoreCase) && !genericOptions.Contains(x, StringComparer.OrdinalIgnoreCase)));
|
|
||||||
unknowns.AddRange(_parser.Args.Keys.Where(x => !options.Contains(x, StringComparer.OrdinalIgnoreCase)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return unknowns;
|
return unknowns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCommandName()
|
|
||||||
{
|
|
||||||
string command = string.Empty;
|
|
||||||
|
|
||||||
if (Configure)
|
|
||||||
{
|
|
||||||
command = Constants.Runner.CommandLine.Commands.Configure;
|
|
||||||
}
|
|
||||||
else if (Remove)
|
|
||||||
{
|
|
||||||
command = Constants.Runner.CommandLine.Commands.Remove;
|
|
||||||
}
|
|
||||||
else if (Run)
|
|
||||||
{
|
|
||||||
command = Constants.Runner.CommandLine.Commands.Run;
|
|
||||||
}
|
|
||||||
else if (Warmup)
|
|
||||||
{
|
|
||||||
command = Constants.Runner.CommandLine.Commands.Warmup;
|
|
||||||
}
|
|
||||||
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Interactive flags.
|
// Interactive flags.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -666,16 +666,16 @@ namespace GitHub.Runner.Listener
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
request = await runnerServer.RenewAgentRequestAsync(poolId, requestId, lockToken, orchestrationId, token);
|
// request = await runnerServer.RenewAgentRequestAsync(poolId, requestId, lockToken, orchestrationId, token);
|
||||||
Trace.Info($"Successfully renew job request {requestId}, job is valid till {request.LockedUntil.Value}");
|
// Trace.Info($"Successfully renew job request {requestId}, job is valid till {request.LockedUntil.Value}");
|
||||||
|
|
||||||
if (!firstJobRequestRenewed.Task.IsCompleted)
|
if (!firstJobRequestRenewed.Task.IsCompleted)
|
||||||
{
|
{
|
||||||
// fire first renew succeed event.
|
// fire first renew succeed event.
|
||||||
firstJobRequestRenewed.TrySetResult(0);
|
firstJobRequestRenewed.TrySetResult(0);
|
||||||
|
|
||||||
// Update settings if the runner name has been changed server-side
|
// // Update settings if the runner name has been changed server-side
|
||||||
UpdateAgentNameIfNeeded(request.ReservedAgent?.Name);
|
// UpdateAgentNameIfNeeded(request.ReservedAgent?.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encounteringError > 0)
|
if (encounteringError > 0)
|
||||||
|
|||||||
13
src/Runner.Listener/MessageRef.cs
Normal file
13
src/Runner.Listener/MessageRef.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace GitHub.Runner.Listener
|
||||||
|
{
|
||||||
|
[DataContract]
|
||||||
|
public sealed class RunnerJobRequestRef
|
||||||
|
{
|
||||||
|
[DataMember(Name = "id")]
|
||||||
|
public string Id { get; set; }
|
||||||
|
[DataMember(Name = "runner_request_id")]
|
||||||
|
public string RunnerRequestId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -95,15 +95,7 @@ namespace GitHub.Runner.Listener
|
|||||||
var unknownCommandlines = command.Validate();
|
var unknownCommandlines = command.Validate();
|
||||||
if (unknownCommandlines.Count > 0)
|
if (unknownCommandlines.Count > 0)
|
||||||
{
|
{
|
||||||
string commandName = command.GetCommandName();
|
terminal.WriteError($"Unrecognized command-line input arguments: '{string.Join(", ", unknownCommandlines)}'. For usage refer to: .\\config.cmd --help or ./config.sh --help");
|
||||||
if (string.IsNullOrEmpty(commandName))
|
|
||||||
{
|
|
||||||
terminal.WriteError($"This command does not recognize the command-line input arguments: '{string.Join(", ", unknownCommandlines)}'. For usage refer to: .\\config.cmd --help or ./config.sh --help");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
terminal.WriteError($"Unrecognized command-line input arguments for command {commandName}: '{string.Join(", ", unknownCommandlines)}'. For usage refer to: .\\config.cmd --help or ./config.sh --help");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defer to the Runner class to execute the command.
|
// Defer to the Runner class to execute the command.
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ using GitHub.Runner.Sdk;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using GitHub.Runner.Listener.Check;
|
using GitHub.Runner.Listener.Check;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace GitHub.Runner.Listener
|
namespace GitHub.Runner.Listener
|
||||||
{
|
{
|
||||||
@@ -457,6 +461,35 @@ namespace GitHub.Runner.Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Broker flow
|
||||||
|
else if (string.Equals(message.MessageType, JobRequestMessageTypes.RunnerJobRequest, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
if (autoUpdateInProgress || runOnceJobReceived)
|
||||||
|
{
|
||||||
|
skipMessageDeletion = true;
|
||||||
|
Trace.Info($"Skip message deletion for job request message '{message.MessageId}'.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var messageRef = StringUtil.ConvertFromJson<RunnerJobRequestRef>(message.Body);
|
||||||
|
|
||||||
|
// Create connection
|
||||||
|
var credMgr = HostContext.GetService<ICredentialManager>();
|
||||||
|
var creds = credMgr.LoadCredentials();
|
||||||
|
|
||||||
|
// todo: add retries
|
||||||
|
var runServer = HostContext.CreateService<IRunServer>();
|
||||||
|
await runServer.ConnectAsync(new Uri(settings.ServerUrl), creds);
|
||||||
|
var jobMessage = await runServer.GetJobMessageAsync(messageRef.RunnerRequestId);
|
||||||
|
|
||||||
|
jobDispatcher.Run(jobMessage, runOnce);
|
||||||
|
if (runOnce)
|
||||||
|
{
|
||||||
|
Trace.Info("One time used runner received job message.");
|
||||||
|
runOnceJobReceived = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (string.Equals(message.MessageType, JobCancelMessage.MessageType, StringComparison.OrdinalIgnoreCase))
|
else if (string.Equals(message.MessageType, JobCancelMessage.MessageType, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var cancelJobMessage = JsonUtility.FromString<JobCancelMessage>(message.Body);
|
var cancelJobMessage = JsonUtility.FromString<JobCancelMessage>(message.Body);
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ namespace GitHub.Runner.Sdk
|
|||||||
settings.SendTimeout = TimeSpan.FromSeconds(Math.Min(Math.Max(httpRequestTimeoutSeconds, 100), 1200));
|
settings.SendTimeout = TimeSpan.FromSeconds(Math.Min(Math.Max(httpRequestTimeoutSeconds, 100), 1200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings.AllowAutoRedirect = true;
|
||||||
|
|
||||||
// Remove Invariant from the list of accepted languages.
|
// Remove Invariant from the list of accepted languages.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GitHub.DistributedTask.ObjectTemplating;
|
using GitHub.DistributedTask.ObjectTemplating;
|
||||||
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
||||||
@@ -10,6 +9,7 @@ using GitHub.DistributedTask.Pipelines.ObjectTemplating;
|
|||||||
using GitHub.Runner.Common;
|
using GitHub.Runner.Common;
|
||||||
using GitHub.Runner.Common.Util;
|
using GitHub.Runner.Common.Util;
|
||||||
using GitHub.Runner.Sdk;
|
using GitHub.Runner.Sdk;
|
||||||
|
using GitHub.Runner.Worker;
|
||||||
using GitHub.Runner.Worker.Handlers;
|
using GitHub.Runner.Worker.Handlers;
|
||||||
using Pipelines = GitHub.DistributedTask.Pipelines;
|
using Pipelines = GitHub.DistributedTask.Pipelines;
|
||||||
|
|
||||||
@@ -171,16 +171,8 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
// Load the inputs.
|
// Load the inputs.
|
||||||
ExecutionContext.Debug("Loading inputs");
|
ExecutionContext.Debug("Loading inputs");
|
||||||
Dictionary<string, string> inputs;
|
var templateEvaluator = ExecutionContext.ToPipelineTemplateEvaluator();
|
||||||
if (ExecutionContext.Global.Variables.GetBoolean(Constants.Runner.Features.UseContainerPathForTemplate) ?? false)
|
var inputs = templateEvaluator.EvaluateStepInputs(Action.Inputs, ExecutionContext.ExpressionValues, ExecutionContext.ExpressionFunctions);
|
||||||
{
|
|
||||||
inputs = EvaluateStepInputs(stepHost);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var templateEvaluator = ExecutionContext.ToPipelineTemplateEvaluator();
|
|
||||||
inputs = templateEvaluator.EvaluateStepInputs(Action.Inputs, ExecutionContext.ExpressionValues, ExecutionContext.ExpressionFunctions);
|
|
||||||
}
|
|
||||||
|
|
||||||
var userInputs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
var userInputs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||||
foreach (KeyValuePair<string, string> input in inputs)
|
foreach (KeyValuePair<string, string> input in inputs)
|
||||||
@@ -307,15 +299,6 @@ namespace GitHub.Runner.Worker
|
|||||||
return didFullyEvaluate;
|
return didFullyEvaluate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<String, String> EvaluateStepInputs(IStepHost stepHost)
|
|
||||||
{
|
|
||||||
DictionaryContextData expressionValues = ExecutionContext.GetExpressionValues(stepHost);
|
|
||||||
var templateEvaluator = ExecutionContext.ToPipelineTemplateEvaluator();
|
|
||||||
var inputs = templateEvaluator.EvaluateStepInputs(Action.Inputs, expressionValues, ExecutionContext.ExpressionFunctions);
|
|
||||||
|
|
||||||
return inputs;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GenerateDisplayName(ActionStep action, DictionaryContextData contextData, IExecutionContext context, out bool didFullyEvaluate)
|
private string GenerateDisplayName(ActionStep action, DictionaryContextData contextData, IExecutionContext context, out bool didFullyEvaluate)
|
||||||
{
|
{
|
||||||
ArgUtil.NotNull(context, nameof(context));
|
ArgUtil.NotNull(context, nameof(context));
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Web;
|
||||||
using GitHub.DistributedTask.Expressions2;
|
using GitHub.DistributedTask.Expressions2;
|
||||||
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
||||||
|
using GitHub.DistributedTask.Pipelines;
|
||||||
using GitHub.DistributedTask.Pipelines.ContextData;
|
using GitHub.DistributedTask.Pipelines.ContextData;
|
||||||
using GitHub.DistributedTask.Pipelines.ObjectTemplating;
|
using GitHub.DistributedTask.Pipelines.ObjectTemplating;
|
||||||
using GitHub.DistributedTask.WebApi;
|
using GitHub.DistributedTask.WebApi;
|
||||||
@@ -15,7 +20,7 @@ using GitHub.Runner.Common;
|
|||||||
using GitHub.Runner.Common.Util;
|
using GitHub.Runner.Common.Util;
|
||||||
using GitHub.Runner.Sdk;
|
using GitHub.Runner.Sdk;
|
||||||
using GitHub.Runner.Worker.Container;
|
using GitHub.Runner.Worker.Container;
|
||||||
using GitHub.Runner.Worker.Handlers;
|
using GitHub.Services.WebApi;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using ObjectTemplating = GitHub.DistributedTask.ObjectTemplating;
|
using ObjectTemplating = GitHub.DistributedTask.ObjectTemplating;
|
||||||
using Pipelines = GitHub.DistributedTask.Pipelines;
|
using Pipelines = GitHub.DistributedTask.Pipelines;
|
||||||
@@ -110,6 +115,7 @@ namespace GitHub.Runner.Worker
|
|||||||
void UpdateGlobalStepsContext();
|
void UpdateGlobalStepsContext();
|
||||||
|
|
||||||
void WriteWebhookPayload();
|
void WriteWebhookPayload();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ExecutionContext : RunnerService, IExecutionContext
|
public sealed class ExecutionContext : RunnerService, IExecutionContext
|
||||||
@@ -1193,66 +1199,6 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
return new TemplateTraceWriter(context);
|
return new TemplateTraceWriter(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DictionaryContextData GetExpressionValues(this IExecutionContext context, IStepHost stepHost)
|
|
||||||
{
|
|
||||||
if (stepHost is ContainerStepHost)
|
|
||||||
{
|
|
||||||
|
|
||||||
var expressionValues = context.ExpressionValues.Clone() as DictionaryContextData;
|
|
||||||
context.UpdatePathsInExpressionValues("github", expressionValues, stepHost);
|
|
||||||
context.UpdatePathsInExpressionValues("runner", expressionValues, stepHost);
|
|
||||||
return expressionValues;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return context.ExpressionValues.Clone() as DictionaryContextData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void UpdatePathsInExpressionValues(this IExecutionContext context, string contextName, DictionaryContextData expressionValues, IStepHost stepHost)
|
|
||||||
{
|
|
||||||
var dict = expressionValues[contextName].AssertDictionary($"expected context {contextName} to be a dictionary");
|
|
||||||
context.ResolvePathsInExpressionValuesDictionary(dict, stepHost);
|
|
||||||
expressionValues[contextName] = dict;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ResolvePathsInExpressionValuesDictionary(this IExecutionContext context, DictionaryContextData dict, IStepHost stepHost)
|
|
||||||
{
|
|
||||||
foreach (var key in dict.Keys.ToList())
|
|
||||||
{
|
|
||||||
if (dict[key] is StringContextData)
|
|
||||||
{
|
|
||||||
var value = dict[key].ToString();
|
|
||||||
if (!string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
dict[key] = new StringContextData(stepHost.ResolvePathForStepHost(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (dict[key] is DictionaryContextData)
|
|
||||||
{
|
|
||||||
var innerDict = dict[key].AssertDictionary("expected dictionary");
|
|
||||||
context.ResolvePathsInExpressionValuesDictionary(innerDict, stepHost);
|
|
||||||
var updatedDict = new DictionaryContextData();
|
|
||||||
foreach (var k in innerDict.Keys.ToList())
|
|
||||||
{
|
|
||||||
updatedDict[k] = innerDict[k];
|
|
||||||
}
|
|
||||||
dict[key] = updatedDict;
|
|
||||||
}
|
|
||||||
else if (dict[key] is CaseSensitiveDictionaryContextData)
|
|
||||||
{
|
|
||||||
var innerDict = dict[key].AssertDictionary("expected dictionary");
|
|
||||||
context.ResolvePathsInExpressionValuesDictionary(innerDict, stepHost);
|
|
||||||
var updatedDict = new CaseSensitiveDictionaryContextData();
|
|
||||||
foreach (var k in innerDict.Keys.ToList())
|
|
||||||
{
|
|
||||||
updatedDict[k] = innerDict[k];
|
|
||||||
}
|
|
||||||
dict[key] = updatedDict;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class TemplateTraceWriter : ObjectTemplating.ITraceWriter
|
internal sealed class TemplateTraceWriter : ObjectTemplating.ITraceWriter
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
void InitializeFiles(IExecutionContext context, ContainerInfo container);
|
void InitializeFiles(IExecutionContext context, ContainerInfo container);
|
||||||
void ProcessFiles(IExecutionContext context, ContainerInfo container);
|
void ProcessFiles(IExecutionContext context, ContainerInfo container);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class FileCommandManager : RunnerService, IFileCommandManager
|
public sealed class FileCommandManager : RunnerService, IFileCommandManager
|
||||||
@@ -57,7 +57,7 @@ namespace GitHub.Runner.Worker
|
|||||||
TryDeleteFile(newPath);
|
TryDeleteFile(newPath);
|
||||||
File.Create(newPath).Dispose();
|
File.Create(newPath).Dispose();
|
||||||
|
|
||||||
var pathToSet = container != null ? container.TranslateToContainerPath(newPath) : newPath;
|
var pathToSet = container != null ? container.TranslateToContainerPath(newPath) : newPath;
|
||||||
context.SetGitHubContext(fileCommand.ContextName, pathToSet);
|
context.SetGitHubContext(fileCommand.ContextName, pathToSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
foreach (var fileCommand in _commandExtensions)
|
foreach (var fileCommand in _commandExtensions)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fileCommand.ProcessCommand(context, Path.Combine(_fileCommandDirectory, fileCommand.FilePrefix + _fileSuffix),container);
|
fileCommand.ProcessCommand(context, Path.Combine(_fileCommandDirectory, fileCommand.FilePrefix + _fileSuffix),container);
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
public sealed class CreateStepSummaryCommand : RunnerService, IFileCommandExtension
|
public sealed class CreateStepSummaryCommand : RunnerService, IFileCommandExtension
|
||||||
{
|
{
|
||||||
public const int AttachmentSizeLimit = 1024 * 1024;
|
private const int _attachmentSizeLimit = 128 * 1024;
|
||||||
|
|
||||||
public string ContextName => "step_summary";
|
public string ContextName => "step_summary";
|
||||||
public string FilePrefix => "step_summary_";
|
public string FilePrefix => "step_summary_";
|
||||||
@@ -296,9 +296,9 @@ namespace GitHub.Runner.Worker
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileSize > AttachmentSizeLimit)
|
if (fileSize > _attachmentSizeLimit)
|
||||||
{
|
{
|
||||||
context.Error(String.Format(Constants.Runner.UnsupportedSummarySize, AttachmentSizeLimit / 1024, fileSize / 1024));
|
context.Error(String.Format(Constants.Runner.UnsupportedSummarySize, _attachmentSizeLimit / 1024, fileSize / 1024));
|
||||||
Trace.Info($"Step Summary file ({filePath}) is too large ({fileSize} bytes); skipping attachment upload");
|
Trace.Info($"Step Summary file ({filePath}) is too large ({fileSize} bytes); skipping attachment upload");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -151,11 +151,6 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.Contains("fatal: unsafe repository", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
_executionContext.StepTelemetry.ErrorMessages.Add(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regular output
|
// Regular output
|
||||||
_executionContext.Output(line);
|
_executionContext.Output(line);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Channels;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using GitHub.DistributedTask.WebApi;
|
||||||
|
using GitHub.Runner.Common.Util;
|
||||||
using GitHub.Runner.Worker.Container;
|
using GitHub.Runner.Worker.Container;
|
||||||
|
using GitHub.Services.WebApi;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using GitHub.Runner.Common;
|
using GitHub.Runner.Common;
|
||||||
using GitHub.Runner.Sdk;
|
using GitHub.Runner.Sdk;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using GitHub.DistributedTask.Pipelines.ContextData;
|
|
||||||
|
|
||||||
namespace GitHub.Runner.Worker.Handlers
|
namespace GitHub.Runner.Worker.Handlers
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -132,7 +132,7 @@
|
|||||||
"continue-on-error": "boolean-steps-context",
|
"continue-on-error": "boolean-steps-context",
|
||||||
"working-directory": "string-steps-context",
|
"working-directory": "string-steps-context",
|
||||||
"shell": {
|
"shell": {
|
||||||
"type": "string-steps-context",
|
"type": "non-empty-string",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace GitHub.Services.Common.ClientStorage
|
|||||||
private readonly string m_filePath;
|
private readonly string m_filePath;
|
||||||
private readonly VssFileStorageReader m_reader;
|
private readonly VssFileStorageReader m_reader;
|
||||||
private readonly IVssClientStorageWriter m_writer;
|
private readonly IVssClientStorageWriter m_writer;
|
||||||
|
|
||||||
private const char c_defaultPathSeparator = '\\';
|
private const char c_defaultPathSeparator = '\\';
|
||||||
private const bool c_defaultIgnoreCaseInPaths = false;
|
private const bool c_defaultIgnoreCaseInPaths = false;
|
||||||
|
|
||||||
@@ -191,7 +192,7 @@ namespace GitHub.Services.Common.ClientStorage
|
|||||||
// Windows Impersonation is being used.
|
// Windows Impersonation is being used.
|
||||||
|
|
||||||
// Check to see if we can find the user's local application data directory.
|
// Check to see if we can find the user's local application data directory.
|
||||||
string subDir = Path.Combine("GitHub", "ActionsService");
|
string subDir = "GitHub\\ActionsService";
|
||||||
string path = Environment.GetEnvironmentVariable("localappdata");
|
string path = Environment.GetEnvironmentVariable("localappdata");
|
||||||
SafeGetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
SafeGetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||||
if (string.IsNullOrEmpty(path))
|
if (string.IsNullOrEmpty(path))
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ using System.Net.Http.Headers;
|
|||||||
using System.Net.Http.Formatting;
|
using System.Net.Http.Formatting;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using GitHub.DistributedTask.Pipelines;
|
||||||
using GitHub.Services.Common;
|
using GitHub.Services.Common;
|
||||||
using GitHub.Services.WebApi;
|
using GitHub.Services.WebApi;
|
||||||
|
|
||||||
@@ -703,6 +704,31 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
cancellationToken: cancellationToken);
|
cancellationToken: cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [Preview API]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="messageId"></param>
|
||||||
|
/// <param name="userState"></param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public virtual Task<Pipelines.AgentJobRequestMessage> GetJobMessageAsync(
|
||||||
|
string messageId,
|
||||||
|
object userState = null,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
HttpMethod httpMethod = new HttpMethod("GET");
|
||||||
|
Guid locationId = new Guid("25adab70-1379-4186-be8e-b643061ebe3a");
|
||||||
|
object routeValues = new { messageId = messageId };
|
||||||
|
|
||||||
|
return SendAsync<Pipelines.AgentJobRequestMessage>(
|
||||||
|
httpMethod,
|
||||||
|
locationId,
|
||||||
|
routeValues: routeValues,
|
||||||
|
version: new ApiResourceVersion(6.0, 1),
|
||||||
|
userState: userState,
|
||||||
|
cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// [Preview API]
|
/// [Preview API]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,5 +5,6 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
public static class JobRequestMessageTypes
|
public static class JobRequestMessageTypes
|
||||||
{
|
{
|
||||||
public const String PipelineAgentJobRequest = "PipelineAgentJobRequest";
|
public const String PipelineAgentJobRequest = "PipelineAgentJobRequest";
|
||||||
|
public const String RunnerJobRequest = "RunnerJobRequest";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -708,85 +708,33 @@ namespace GitHub.Runner.Common.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Fact]
|
||||||
[InlineData("configure", "once")]
|
|
||||||
[InlineData("remove", "disableupdate")]
|
|
||||||
[InlineData("remove", "ephemeral")]
|
|
||||||
[InlineData("remove", "once")]
|
|
||||||
[InlineData("remove", "replace")]
|
|
||||||
[InlineData("remove", "runasservice")]
|
|
||||||
[InlineData("remove", "unattended")]
|
|
||||||
[InlineData("run", "disableupdate")]
|
|
||||||
[InlineData("run", "ephemeral")]
|
|
||||||
[InlineData("run", "replace")]
|
|
||||||
[InlineData("run", "runasservice")]
|
|
||||||
[InlineData("run", "unattended")]
|
|
||||||
[InlineData("warmup", "disableupdate")]
|
|
||||||
[InlineData("warmup", "ephemeral")]
|
|
||||||
[InlineData("warmup", "once")]
|
|
||||||
[InlineData("warmup", "replace")]
|
|
||||||
[InlineData("warmup", "runasservice")]
|
|
||||||
[InlineData("warmup", "unattended")]
|
|
||||||
[Trait("Level", "L0")]
|
[Trait("Level", "L0")]
|
||||||
[Trait("Category", nameof(CommandSettings))]
|
[Trait("Category", nameof(CommandSettings))]
|
||||||
public void ValidateInvalidFlagCommandCombination(string validCommand, string flag)
|
public void ValidateFlags()
|
||||||
{
|
{
|
||||||
using (TestHostContext hc = CreateTestContext())
|
using (TestHostContext hc = CreateTestContext())
|
||||||
{
|
{
|
||||||
// Arrange.
|
// Arrange.
|
||||||
var command = new CommandSettings(hc, args: new string[] { validCommand, $"--{flag}" });
|
var command = new CommandSettings(hc, args: new string[] { "--badflag" });
|
||||||
|
|
||||||
// Assert.
|
// Assert.
|
||||||
Assert.Contains(flag, command.Validate());
|
Assert.Contains("badflag", command.Validate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Fact]
|
||||||
[InlineData("remove", "auth", "bar arg value")]
|
|
||||||
[InlineData("remove", "labels", "bar arg value")]
|
|
||||||
[InlineData("remove", "monitorsocketaddress", "bar arg value")]
|
|
||||||
[InlineData("remove", "name", "bar arg value")]
|
|
||||||
[InlineData("remove", "runnergroup", "bar arg value")]
|
|
||||||
[InlineData("remove", "url", "bar arg value")]
|
|
||||||
[InlineData("remove", "username", "bar arg value")]
|
|
||||||
[InlineData("remove", "windowslogonaccount", "bar arg value")]
|
|
||||||
[InlineData("remove", "windowslogonpassword", "bar arg value")]
|
|
||||||
[InlineData("remove", "work", "bar arg value")]
|
|
||||||
[InlineData("run", "auth", "bad arg value")]
|
|
||||||
[InlineData("run", "labels", "bad arg value")]
|
|
||||||
[InlineData("run", "monitorsocketaddress", "bad arg value")]
|
|
||||||
[InlineData("run", "name", "bad arg value")]
|
|
||||||
[InlineData("run", "pat", "bad arg value")]
|
|
||||||
[InlineData("run", "runnergroup", "bad arg value")]
|
|
||||||
[InlineData("run", "token", "bad arg value")]
|
|
||||||
[InlineData("run", "url", "bad arg value")]
|
|
||||||
[InlineData("run", "username", "bad arg value")]
|
|
||||||
[InlineData("run", "windowslogonaccount", "bad arg value")]
|
|
||||||
[InlineData("run", "windowslogonpassword", "bad arg value")]
|
|
||||||
[InlineData("run", "work", "bad arg value")]
|
|
||||||
[InlineData("warmup", "auth", "bad arg value")]
|
|
||||||
[InlineData("warmup", "labels", "bad arg value")]
|
|
||||||
[InlineData("warmup", "monitorsocketaddress", "bad arg value")]
|
|
||||||
[InlineData("warmup", "name", "bad arg value")]
|
|
||||||
[InlineData("warmup", "pat", "bad arg value")]
|
|
||||||
[InlineData("warmup", "runnergroup", "bad arg value")]
|
|
||||||
[InlineData("warmup", "token", "bad arg value")]
|
|
||||||
[InlineData("warmup", "url", "bad arg value")]
|
|
||||||
[InlineData("warmup", "username", "bad arg value")]
|
|
||||||
[InlineData("warmup", "windowslogonaccount", "bad arg value")]
|
|
||||||
[InlineData("warmup", "windowslogonpassword", "bad arg value")]
|
|
||||||
[InlineData("warmup", "work", "bad arg value")]
|
|
||||||
[Trait("Level", "L0")]
|
[Trait("Level", "L0")]
|
||||||
[Trait("Category", nameof(CommandSettings))]
|
[Trait("Category", nameof(CommandSettings))]
|
||||||
public void ValidateInvalidArgCommandCombination(string validCommand, string arg, string argValue)
|
public void ValidateArgs()
|
||||||
{
|
{
|
||||||
using (TestHostContext hc = CreateTestContext())
|
using (TestHostContext hc = CreateTestContext())
|
||||||
{
|
{
|
||||||
// Arrange.
|
// Arrange.
|
||||||
var command = new CommandSettings(hc, args: new string[] { validCommand, $"--{arg}", argValue });
|
var command = new CommandSettings(hc, args: new string[] { "--badargname", "bad arg value" });
|
||||||
|
|
||||||
// Assert.
|
// Assert.
|
||||||
Assert.Contains(arg, command.Validate());
|
Assert.Contains("badargname", command.Validate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,73 +758,6 @@ namespace GitHub.Runner.Common.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("configure", "help")]
|
|
||||||
[InlineData("configure", "version")]
|
|
||||||
[InlineData("configure", "commit")]
|
|
||||||
[InlineData("configure", "check")]
|
|
||||||
[InlineData("configure", "disableupdate")]
|
|
||||||
[InlineData("configure", "ephemeral")]
|
|
||||||
[InlineData("configure", "replace")]
|
|
||||||
[InlineData("configure", "runasservice")]
|
|
||||||
[InlineData("configure", "unattended")]
|
|
||||||
[InlineData("remove", "help")]
|
|
||||||
[InlineData("remove", "version")]
|
|
||||||
[InlineData("remove", "commit")]
|
|
||||||
[InlineData("remove", "check")]
|
|
||||||
[InlineData("run", "help")]
|
|
||||||
[InlineData("run", "version")]
|
|
||||||
[InlineData("run", "commit")]
|
|
||||||
[InlineData("run", "check")]
|
|
||||||
[InlineData("run", "once")]
|
|
||||||
[InlineData("warmup", "help")]
|
|
||||||
[InlineData("warmup", "version")]
|
|
||||||
[InlineData("warmup", "commit")]
|
|
||||||
[InlineData("warmup", "check")]
|
|
||||||
[Trait("Level", "L0")]
|
|
||||||
[Trait("Category", nameof(CommandSettings))]
|
|
||||||
public void ValidateGoodFlagCommandCombination(string validCommand, string flag)
|
|
||||||
{
|
|
||||||
using (TestHostContext hc = CreateTestContext())
|
|
||||||
{
|
|
||||||
// Arrange.
|
|
||||||
var command = new CommandSettings(hc, args: new string[] { validCommand, $"--{flag}" });
|
|
||||||
|
|
||||||
// Assert.
|
|
||||||
Assert.True(command.Validate().Count == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("configure", "auth", "good arg value")]
|
|
||||||
[InlineData("configure", "labels", "good arg value")]
|
|
||||||
[InlineData("configure", "monitorsocketaddress", "good arg value")]
|
|
||||||
[InlineData("configure", "name", "good arg value")]
|
|
||||||
[InlineData("configure", "pat", "good arg value")]
|
|
||||||
[InlineData("configure", "runnergroup", "good arg value")]
|
|
||||||
[InlineData("configure", "token", "good arg value")]
|
|
||||||
[InlineData("configure", "url", "good arg value")]
|
|
||||||
[InlineData("configure", "username", "good arg value")]
|
|
||||||
[InlineData("configure", "windowslogonaccount", "good arg value")]
|
|
||||||
[InlineData("configure", "windowslogonpassword", "good arg value")]
|
|
||||||
[InlineData("configure", "work", "good arg value")]
|
|
||||||
[InlineData("remove", "token", "good arg value")]
|
|
||||||
[InlineData("remove", "pat", "good arg value")]
|
|
||||||
[InlineData("run", "startuptype", "good arg value")]
|
|
||||||
[Trait("Level", "L0")]
|
|
||||||
[Trait("Category", nameof(CommandSettings))]
|
|
||||||
public void ValidateGoodArgCommandCombination(string validCommand, string arg, string argValue)
|
|
||||||
{
|
|
||||||
using (TestHostContext hc = CreateTestContext())
|
|
||||||
{
|
|
||||||
// Arrange.
|
|
||||||
var command = new CommandSettings(hc, args: new string[] { validCommand, $"--{arg}", argValue });
|
|
||||||
|
|
||||||
// Assert.
|
|
||||||
Assert.True(command.Validate().Count == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private TestHostContext CreateTestContext([CallerMemberName] string testName = "")
|
private TestHostContext CreateTestContext([CallerMemberName] string testName = "")
|
||||||
{
|
{
|
||||||
TestHostContext hc = new TestHostContext(this, testName);
|
TestHostContext hc = new TestHostContext(this, testName);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
using (var hostContext = Setup(featureFlagState: "false"))
|
using (var hostContext = Setup(featureFlagState: "false"))
|
||||||
{
|
{
|
||||||
var stepSummaryFile = Path.Combine(_rootDirectory, "feature-off");
|
var stepSummaryFile = Path.Combine(_rootDirectory, "feature-off");
|
||||||
|
|
||||||
_createStepCommand.ProcessCommand(_executionContext.Object, stepSummaryFile, null);
|
_createStepCommand.ProcessCommand(_executionContext.Object, stepSummaryFile, null);
|
||||||
_jobExecutionContext.Complete();
|
_jobExecutionContext.Complete();
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
using (var hostContext = Setup())
|
using (var hostContext = Setup())
|
||||||
{
|
{
|
||||||
var stepSummaryFile = Path.Combine(_rootDirectory, "empty-file");
|
var stepSummaryFile = Path.Combine(_rootDirectory, "empty-file");
|
||||||
File.WriteAllBytes(stepSummaryFile, new byte[CreateStepSummaryCommand.AttachmentSizeLimit + 1]);
|
File.WriteAllBytes(stepSummaryFile, new byte[128 * 1024 + 1]);
|
||||||
|
|
||||||
_createStepCommand.ProcessCommand(_executionContext.Object, stepSummaryFile, null);
|
_createStepCommand.ProcessCommand(_executionContext.Object, stepSummaryFile, null);
|
||||||
_jobExecutionContext.Complete();
|
_jobExecutionContext.Complete();
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ using System.Threading;
|
|||||||
using GitHub.DistributedTask.Pipelines.ContextData;
|
using GitHub.DistributedTask.Pipelines.ContextData;
|
||||||
using GitHub.DistributedTask.WebApi;
|
using GitHub.DistributedTask.WebApi;
|
||||||
using GitHub.Runner.Worker;
|
using GitHub.Runner.Worker;
|
||||||
using GitHub.Runner.Worker.Container;
|
|
||||||
using GitHub.Runner.Worker.Handlers;
|
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
using GitHub.DistributedTask.ObjectTemplating.Tokens;
|
||||||
@@ -726,149 +724,5 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
|
|
||||||
return hc;
|
return hc;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
[Trait("Level", "L0")]
|
|
||||||
[Trait("Category", "Worker")]
|
|
||||||
public void GetExpressionValues_ContainerStepHost()
|
|
||||||
{
|
|
||||||
using (TestHostContext hc = CreateTestContext())
|
|
||||||
{
|
|
||||||
const string source = "/home/username/Projects/work/runner/_layout";
|
|
||||||
var containerInfo = new ContainerInfo();
|
|
||||||
containerInfo.ContainerId = "test";
|
|
||||||
|
|
||||||
containerInfo.AddPathTranslateMapping($"{source}/_work", "/__w");
|
|
||||||
containerInfo.AddPathTranslateMapping($"{source}/_temp", "/__t");
|
|
||||||
containerInfo.AddPathTranslateMapping($"{source}/externals", "/__e");
|
|
||||||
|
|
||||||
containerInfo.AddPathTranslateMapping($"{source}/_work/_temp/_github_home", "/github/home");
|
|
||||||
containerInfo.AddPathTranslateMapping($"{source}/_work/_temp/_github_workflow", "/github/workflow");
|
|
||||||
|
|
||||||
foreach (var v in new List<string>() {
|
|
||||||
$"{source}/_work",
|
|
||||||
$"{source}/externals",
|
|
||||||
$"{source}/_work/_temp",
|
|
||||||
$"{source}/_work/_actions",
|
|
||||||
$"{source}/_work/_tool",
|
|
||||||
})
|
|
||||||
{
|
|
||||||
containerInfo.MountVolumes.Add(new MountVolume(v, containerInfo.TranslateToContainerPath(v)));
|
|
||||||
};
|
|
||||||
|
|
||||||
var stepHost = new ContainerStepHost();
|
|
||||||
stepHost.Container = containerInfo;
|
|
||||||
|
|
||||||
var ec = new Runner.Worker.ExecutionContext();
|
|
||||||
ec.Initialize(hc);
|
|
||||||
|
|
||||||
var inputGithubContext = new GitHubContext();
|
|
||||||
var inputeRunnerContext = new RunnerContext();
|
|
||||||
|
|
||||||
// string context data
|
|
||||||
inputGithubContext["action_path"] = new StringContextData("/home/username/Projects/work/runner/_layout/_work/_actions/owner/composite/main");
|
|
||||||
inputGithubContext["action"] = new StringContextData("__owner_composite");
|
|
||||||
inputGithubContext["api_url"] = new StringContextData("https://api.github.com/custom/path");
|
|
||||||
inputGithubContext["env"] = new StringContextData("/home/username/Projects/work/runner/_layout/_work/_temp/_runner_file_commands/set_env_265698aa-7f38-40f5-9316-5c01a3153672");
|
|
||||||
inputGithubContext["path"] = new StringContextData("/home/username/Projects/work/runner/_layout/_work/_temp/_runner_file_commands/add_path_265698aa-7f38-40f5-9316-5c01a3153672");
|
|
||||||
inputGithubContext["event_path"] = new StringContextData("/home/username/Projects/work/runner/_layout/_work/_temp/_github_workflow/event.json");
|
|
||||||
inputGithubContext["repository"] = new StringContextData("owner/repo-name");
|
|
||||||
inputGithubContext["run_id"] = new StringContextData("2033211332");
|
|
||||||
inputGithubContext["workflow"] = new StringContextData("Name of Workflow");
|
|
||||||
inputGithubContext["workspace"] = new StringContextData("/home/username/Projects/work/runner/_layout/_work/step-order/step-order");
|
|
||||||
inputeRunnerContext["temp"] = new StringContextData("/home/username/Projects/work/runner/_layout/_work/_temp");
|
|
||||||
inputeRunnerContext["tool_cache"] = new StringContextData("/home/username/Projects/work/runner/_layout/_work/_tool");
|
|
||||||
|
|
||||||
// dictionary context data
|
|
||||||
var githubEvent = new DictionaryContextData();
|
|
||||||
githubEvent["inputs"] = null;
|
|
||||||
githubEvent["ref"] = new StringContextData("refs/heads/main");
|
|
||||||
githubEvent["repository"] = new DictionaryContextData();
|
|
||||||
githubEvent["sender"] = new DictionaryContextData();
|
|
||||||
githubEvent["workflow"] = new StringContextData(".github/workflows/composite_step_host_translate.yaml");
|
|
||||||
|
|
||||||
inputGithubContext["event"] = githubEvent;
|
|
||||||
|
|
||||||
ec.ExpressionValues["github"] = inputGithubContext;
|
|
||||||
ec.ExpressionValues["runner"] = inputeRunnerContext;
|
|
||||||
|
|
||||||
var ecExpect = new Runner.Worker.ExecutionContext();
|
|
||||||
ecExpect.Initialize(hc);
|
|
||||||
|
|
||||||
var expectedGithubEvent = new DictionaryContextData();
|
|
||||||
expectedGithubEvent["inputs"] = null;
|
|
||||||
expectedGithubEvent["ref"] = new StringContextData("refs/heads/main");
|
|
||||||
expectedGithubEvent["repository"] = new DictionaryContextData();
|
|
||||||
expectedGithubEvent["sender"] = new DictionaryContextData();
|
|
||||||
expectedGithubEvent["workflow"] = new StringContextData(".github/workflows/composite_step_host_translate.yaml");
|
|
||||||
var expectedGithubContext = new GitHubContext();
|
|
||||||
var expectedRunnerContext = new RunnerContext();
|
|
||||||
expectedGithubContext["action_path"] = new StringContextData("/__w/_actions/owner/composite/main");
|
|
||||||
expectedGithubContext["action"] = new StringContextData("__owner_composite");
|
|
||||||
expectedGithubContext["api_url"] = new StringContextData("https://api.github.com/custom/path");
|
|
||||||
expectedGithubContext["env"] = new StringContextData("/__w/_temp/_runner_file_commands/set_env_265698aa-7f38-40f5-9316-5c01a3153672");
|
|
||||||
expectedGithubContext["path"] = new StringContextData("/__w/_temp/_runner_file_commands/add_path_265698aa-7f38-40f5-9316-5c01a3153672");
|
|
||||||
expectedGithubContext["event_path"] = new StringContextData("/github/workflow/event.json");
|
|
||||||
expectedGithubContext["repository"] = new StringContextData("owner/repo-name");
|
|
||||||
expectedGithubContext["run_id"] = new StringContextData("2033211332");
|
|
||||||
expectedGithubContext["workflow"] = new StringContextData("Name of Workflow");
|
|
||||||
expectedGithubContext["workspace"] = new StringContextData("/__w/step-order/step-order");
|
|
||||||
expectedGithubContext["event"] = expectedGithubEvent;
|
|
||||||
expectedRunnerContext["temp"] = new StringContextData("/__w/_temp");
|
|
||||||
expectedRunnerContext["tool_cache"] = new StringContextData("/__w/_tool");
|
|
||||||
|
|
||||||
ecExpect.ExpressionValues["github"] = expectedGithubContext;
|
|
||||||
ecExpect.ExpressionValues["runner"] = expectedRunnerContext;
|
|
||||||
|
|
||||||
var translatedExpressionValues = ec.GetExpressionValues(stepHost);
|
|
||||||
|
|
||||||
foreach (var contextName in new string[] { "github", "runner" })
|
|
||||||
{
|
|
||||||
var dict = translatedExpressionValues[contextName].AssertDictionary($"expected context github to be a dictionary");
|
|
||||||
var expectedExpressionValues = ecExpect.ExpressionValues[contextName].AssertDictionary("expect dict");
|
|
||||||
foreach (var key in dict.Keys.ToList())
|
|
||||||
{
|
|
||||||
if (dict[key] is StringContextData)
|
|
||||||
{
|
|
||||||
var expect = dict[key].AssertString("expect string");
|
|
||||||
var outcome = expectedExpressionValues[key].AssertString("expect string");
|
|
||||||
Assert.Equal(expect.Value, outcome.Value);
|
|
||||||
}
|
|
||||||
else if (dict[key] is DictionaryContextData || dict[key] is CaseSensitiveDictionaryContextData)
|
|
||||||
{
|
|
||||||
var expectDict = dict[key].AssertDictionary("expect dict");
|
|
||||||
var actualDict = expectedExpressionValues[key].AssertDictionary("expect dict");
|
|
||||||
Assert.True(ExpressionValuesAssertEqual(expectDict, actualDict));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool ExpressionValuesAssertEqual(DictionaryContextData expect, DictionaryContextData actual)
|
|
||||||
{
|
|
||||||
foreach (var key in expect.Keys.ToList())
|
|
||||||
{
|
|
||||||
if (expect[key] is StringContextData)
|
|
||||||
{
|
|
||||||
var expectValue = expect[key].AssertString("expect string");
|
|
||||||
var actualValue = actual[key].AssertString("expect string");
|
|
||||||
if (expectValue.Equals(actualValue))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (expect[key] is DictionaryContextData || expect[key] is CaseSensitiveDictionaryContextData)
|
|
||||||
{
|
|
||||||
var expectDict = expect[key].AssertDictionary("expect dict");
|
|
||||||
var actualDict = actual[key].AssertDictionary("expect dict");
|
|
||||||
if (!ExpressionValuesAssertEqual(expectDict, actualDict))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using GitHub.Runner.Sdk;
|
using GitHub.Runner.Sdk;
|
||||||
using GitHub.Runner.Worker;
|
using GitHub.Runner.Worker;
|
||||||
using GitHub.Runner.Worker.Container;
|
using GitHub.Runner.Worker.Container;
|
||||||
@@ -937,19 +937,6 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
[Trait("Level", "L0")]
|
|
||||||
[Trait("Category", "Worker")]
|
|
||||||
public void CaptureTelemetryForGitUnsafeRepository()
|
|
||||||
{
|
|
||||||
using (Setup())
|
|
||||||
using (_outputManager)
|
|
||||||
{
|
|
||||||
Process("fatal: unsafe repository ('/github/workspace' is owned by someone else)");
|
|
||||||
Assert.Contains("fatal: unsafe repository ('/github/workspace' is owned by someone else)", _executionContext.Object.StepTelemetry.ErrorMessages);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private TestHostContext Setup(
|
private TestHostContext Setup(
|
||||||
[CallerMemberName] string name = "",
|
[CallerMemberName] string name = "",
|
||||||
IssueMatchersConfig matchers = null,
|
IssueMatchersConfig matchers = null,
|
||||||
@@ -975,8 +962,6 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
Variables = _variables,
|
Variables = _variables,
|
||||||
WriteDebug = true,
|
WriteDebug = true,
|
||||||
});
|
});
|
||||||
_executionContext.Setup(x => x.StepTelemetry)
|
|
||||||
.Returns(new DTWebApi.ActionsStepTelemetry());
|
|
||||||
_executionContext.Setup(x => x.GetMatchers())
|
_executionContext.Setup(x => x.GetMatchers())
|
||||||
.Returns(matchers?.Matchers ?? new List<IssueMatcherConfig>());
|
.Returns(matchers?.Matchers ?? new List<IssueMatcherConfig>());
|
||||||
_executionContext.Setup(x => x.Add(It.IsAny<OnMatcherChanged>()))
|
_executionContext.Setup(x => x.Add(It.IsAny<OnMatcherChanged>()))
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ using Xunit;
|
|||||||
using GitHub.Runner.Worker;
|
using GitHub.Runner.Worker;
|
||||||
using GitHub.Runner.Worker.Handlers;
|
using GitHub.Runner.Worker.Handlers;
|
||||||
using GitHub.Runner.Worker.Container;
|
using GitHub.Runner.Worker.Container;
|
||||||
using GitHub.DistributedTask.Pipelines.ContextData;
|
|
||||||
using System.Linq;
|
|
||||||
using GitHub.DistributedTask.Pipelines;
|
|
||||||
|
|
||||||
namespace GitHub.Runner.Common.Tests.Worker
|
namespace GitHub.Runner.Common.Tests.Worker
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2.291.1
|
2.289.2
|
||||||
|
|||||||
Reference in New Issue
Block a user