mirror of
https://github.com/actions/runner.git
synced 2025-12-10 20:36:49 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
709bd6113d | ||
|
|
d2c6a4e4bc | ||
|
|
d11bd3d8be | ||
|
|
761785620f | ||
|
|
416771d4b1 | ||
|
|
9499f477a2 | ||
|
|
6bc6d475f9 | ||
|
|
ca2b1bc6d5 |
5
.github/workflows/release.yml
vendored
5
.github/workflows/release.yml
vendored
@@ -89,7 +89,7 @@ jobs:
|
|||||||
- runtime: osx-x64
|
- runtime: osx-x64
|
||||||
os: macOS-latest
|
os: macOS-latest
|
||||||
devScript: ./dev.sh
|
devScript: ./dev.sh
|
||||||
|
|
||||||
- runtime: osx-arm64
|
- runtime: osx-arm64
|
||||||
os: macOS-latest
|
os: macOS-latest
|
||||||
devScript: ./dev.sh
|
devScript: ./dev.sh
|
||||||
@@ -158,7 +158,7 @@ jobs:
|
|||||||
id: sha_noruntime_noexternals
|
id: sha_noruntime_noexternals
|
||||||
name: Compute SHA256
|
name: Compute SHA256
|
||||||
working-directory: _package_trims/trim_runtime_externals
|
working-directory: _package_trims/trim_runtime_externals
|
||||||
|
|
||||||
- name: Create trimmedpackages.json for ${{ matrix.runtime }}
|
- name: Create trimmedpackages.json for ${{ matrix.runtime }}
|
||||||
if: matrix.runtime == 'win-x64'
|
if: matrix.runtime == 'win-x64'
|
||||||
uses: actions/github-script@0.3.0
|
uses: actions/github-script@0.3.0
|
||||||
@@ -288,7 +288,6 @@ jobs:
|
|||||||
release_name: "v${{ steps.releaseNote.outputs.version }}"
|
release_name: "v${{ steps.releaseNote.outputs.version }}"
|
||||||
body: |
|
body: |
|
||||||
${{ steps.releaseNote.outputs.note }}
|
${{ steps.releaseNote.outputs.note }}
|
||||||
prerelease: true
|
|
||||||
|
|
||||||
# Upload release assets (full runner packages)
|
# Upload release assets (full runner packages)
|
||||||
- name: Upload Release Asset (win-x64)
|
- name: Upload Release Asset (win-x64)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ The `installdependencies.sh` script should install all required dependencies on
|
|||||||
|
|
||||||
Debian based OS (Debian, Ubuntu, Linux Mint)
|
Debian based OS (Debian, Ubuntu, Linux Mint)
|
||||||
|
|
||||||
- liblttng-ust0
|
- liblttng-ust1 or liblttng-ust0
|
||||||
- libkrb5-3
|
- libkrb5-3
|
||||||
- zlib1g
|
- zlib1g
|
||||||
- libssl1.1, libssl1.0.2 or libssl1.0.0
|
- libssl1.1, libssl1.0.2 or libssl1.0.0
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
## Features
|
## Features
|
||||||
|
- Added support for a JIT runner config (#1925)
|
||||||
|
- Added `ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION` env option to force actions to run on a specific node version (#1913)
|
||||||
## Bugs
|
## Bugs
|
||||||
- Fixed an issue where container environment variables names or values could escape the docker command (#2108)
|
- Fixed a bug where container hooks passed in path as a string rather then an array of strings (#1948)
|
||||||
- Sanitize Windows ENVs (#2280)
|
|
||||||
|
|
||||||
## Misc
|
## Misc
|
||||||
|
- Minor cleanup of error messages when running container hooks (#1949)
|
||||||
|
|
||||||
## 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.293.2
|
2.294.0
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$apt_get update && $apt_get install -y liblttng-ust0 libkrb5-3 zlib1g
|
$apt_get update && $apt_get install -y libkrb5-3 zlib1g
|
||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
echo "'$apt_get' failed with exit code '$?'"
|
echo "'$apt_get' failed with exit code '$?'"
|
||||||
@@ -94,6 +94,14 @@ then
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apt_get_with_fallbacks liblttng-ust1 liblttng-ust0
|
||||||
|
if [ $? -ne 0 ]
|
||||||
|
then
|
||||||
|
echo "'$apt_get' failed with exit code '$?'"
|
||||||
|
print_errormessage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
apt_get_with_fallbacks libssl1.1$ libssl1.0.2$ libssl1.0.0$
|
apt_get_with_fallbacks libssl1.1$ libssl1.0.2$ libssl1.0.0$
|
||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ namespace GitHub.Runner.Common
|
|||||||
public static class Args
|
public static class Args
|
||||||
{
|
{
|
||||||
public static readonly string Auth = "auth";
|
public static readonly string Auth = "auth";
|
||||||
|
public static readonly string JitConfig = "jitconfig";
|
||||||
public static readonly string Labels = "labels";
|
public static readonly string Labels = "labels";
|
||||||
public static readonly string MonitorSocketAddress = "monitorsocketaddress";
|
public static readonly string MonitorSocketAddress = "monitorsocketaddress";
|
||||||
public static readonly string Name = "name";
|
public static readonly string Name = "name";
|
||||||
@@ -241,6 +242,7 @@ namespace GitHub.Runner.Common
|
|||||||
|
|
||||||
// Set this env var to "node12" to downgrade the node version for internal functions (e.g hashfiles). This does NOT affect the version of node actions.
|
// Set this env var to "node12" to downgrade the node version for internal functions (e.g hashfiles). This does NOT affect the version of node actions.
|
||||||
public static readonly string ForcedInternalNodeVersion = "ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION";
|
public static readonly string ForcedInternalNodeVersion = "ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION";
|
||||||
|
public static readonly string ForcedActionsNodeVersion = "ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class System
|
public static class System
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace GitHub.Runner.Common
|
|||||||
{
|
{
|
||||||
Task ConnectAsync(Uri serverUrl, VssCredentials credentials);
|
Task ConnectAsync(Uri serverUrl, VssCredentials credentials);
|
||||||
|
|
||||||
Task<AgentJobRequestMessage> GetJobMessageAsync(string id);
|
Task<AgentJobRequestMessage> GetJobMessageAsync(string id, CancellationToken token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class RunServer : RunnerService, IRunServer
|
public sealed class RunServer : RunnerService, IRunServer
|
||||||
@@ -67,10 +67,40 @@ namespace GitHub.Runner.Common
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<AgentJobRequestMessage> GetJobMessageAsync(string id)
|
public Task<AgentJobRequestMessage> GetJobMessageAsync(string id, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
CheckConnection();
|
CheckConnection();
|
||||||
return _taskAgentClient.GetJobMessageAsync(id);
|
var jobMessage = RetryRequest<AgentJobRequestMessage>(async () =>
|
||||||
|
{
|
||||||
|
return await _taskAgentClient.GetJobMessageAsync(id, cancellationToken);
|
||||||
|
}, cancellationToken);
|
||||||
|
return jobMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<T> RetryRequest<T>(Func<Task<T>> func,
|
||||||
|
CancellationToken cancellationToken,
|
||||||
|
int maxRetryAttemptsCount = 5
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var retryCount = 0;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
retryCount++;
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await func();
|
||||||
|
}
|
||||||
|
// TODO: Add handling of non-retriable exceptions: https://github.com/github/actions-broker/issues/122
|
||||||
|
catch (Exception ex) when (retryCount < maxRetryAttemptsCount)
|
||||||
|
{
|
||||||
|
Trace.Error("Catch exception during get full job message");
|
||||||
|
Trace.Error(ex);
|
||||||
|
var backOff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(15));
|
||||||
|
Trace.Warning($"Back off {backOff.TotalSeconds} seconds before next retry. {maxRetryAttemptsCount - retryCount} attempt left.");
|
||||||
|
await Task.Delay(backOff, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,14 @@ namespace GitHub.Runner.Common.Util
|
|||||||
|
|
||||||
public static string GetInternalNodeVersion()
|
public static string GetInternalNodeVersion()
|
||||||
{
|
{
|
||||||
var forcedNodeVersion = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedInternalNodeVersion);
|
var forcedInternalNodeVersion = Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedInternalNodeVersion);
|
||||||
return !string.IsNullOrEmpty(forcedNodeVersion) && BuiltInNodeVersions.Contains(forcedNodeVersion) ? forcedNodeVersion : _defaultNodeVersion;
|
var isForcedInternalNodeVersion = !string.IsNullOrEmpty(forcedInternalNodeVersion) && BuiltInNodeVersions.Contains(forcedInternalNodeVersion);
|
||||||
|
|
||||||
|
if (isForcedInternalNodeVersion)
|
||||||
|
{
|
||||||
|
return forcedInternalNodeVersion;
|
||||||
|
}
|
||||||
|
return _defaultNodeVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ namespace GitHub.Runner.Listener
|
|||||||
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.Args.Auth,
|
||||||
|
Constants.Runner.CommandLine.Args.JitConfig,
|
||||||
Constants.Runner.CommandLine.Args.Labels,
|
Constants.Runner.CommandLine.Args.Labels,
|
||||||
Constants.Runner.CommandLine.Args.MonitorSocketAddress,
|
Constants.Runner.CommandLine.Args.MonitorSocketAddress,
|
||||||
Constants.Runner.CommandLine.Args.Name,
|
Constants.Runner.CommandLine.Args.Name,
|
||||||
@@ -213,6 +214,12 @@ namespace GitHub.Runner.Listener
|
|||||||
validator: Validators.AuthSchemeValidator);
|
validator: Validators.AuthSchemeValidator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetJitConfig()
|
||||||
|
{
|
||||||
|
return GetArg(
|
||||||
|
name: Constants.Runner.CommandLine.Args.JitConfig);
|
||||||
|
}
|
||||||
|
|
||||||
public string GetRunnerName()
|
public string GetRunnerName()
|
||||||
{
|
{
|
||||||
return GetArgOrPrompt(
|
return GetArgOrPrompt(
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GitHub.DistributedTask.WebApi;
|
using GitHub.DistributedTask.WebApi;
|
||||||
@@ -192,6 +194,30 @@ namespace GitHub.Runner.Listener
|
|||||||
return Constants.Runner.ReturnCode.Success;
|
return Constants.Runner.ReturnCode.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var base64JitConfig = command.GetJitConfig();
|
||||||
|
if (!string.IsNullOrEmpty(base64JitConfig))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var decodedJitConfig = Encoding.UTF8.GetString(Convert.FromBase64String(base64JitConfig));
|
||||||
|
var jitConfig = StringUtil.ConvertFromJson<Dictionary<string, string>>(decodedJitConfig);
|
||||||
|
foreach (var config in jitConfig)
|
||||||
|
{
|
||||||
|
var configFile = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), config.Key);
|
||||||
|
var configContent = Encoding.UTF8.GetString(Convert.FromBase64String(config.Value));
|
||||||
|
File.WriteAllText(configFile, configContent, Encoding.UTF8);
|
||||||
|
File.SetAttributes(configFile, File.GetAttributes(configFile) | FileAttributes.Hidden);
|
||||||
|
Trace.Info($"Save {configContent.Length} chars to '{configFile}'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Trace.Error(ex);
|
||||||
|
_term.WriteError(ex.Message);
|
||||||
|
return Constants.Runner.ReturnCode.TerminatedError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RunnerSettings settings = configManager.LoadSettings();
|
RunnerSettings settings = configManager.LoadSettings();
|
||||||
|
|
||||||
var store = HostContext.GetService<IConfigurationStore>();
|
var store = HostContext.GetService<IConfigurationStore>();
|
||||||
@@ -474,10 +500,9 @@ namespace GitHub.Runner.Listener
|
|||||||
var credMgr = HostContext.GetService<ICredentialManager>();
|
var credMgr = HostContext.GetService<ICredentialManager>();
|
||||||
var creds = credMgr.LoadCredentials();
|
var creds = credMgr.LoadCredentials();
|
||||||
|
|
||||||
// todo: add retries https://github.com/github/actions-broker/issues/49
|
|
||||||
var runServer = HostContext.CreateService<IRunServer>();
|
var runServer = HostContext.CreateService<IRunServer>();
|
||||||
await runServer.ConnectAsync(new Uri(settings.ServerUrl), creds);
|
await runServer.ConnectAsync(new Uri(settings.ServerUrl), creds);
|
||||||
var jobMessage = await runServer.GetJobMessageAsync(messageRef.RunnerRequestId);
|
var jobMessage = await runServer.GetJobMessageAsync(messageRef.RunnerRequestId, messageQueueLoopTokenSource.Token);
|
||||||
|
|
||||||
jobDispatcher.Run(jobMessage, runOnce);
|
jobDispatcher.Run(jobMessage, runOnce);
|
||||||
if (runOnce)
|
if (runOnce)
|
||||||
|
|||||||
@@ -264,17 +264,7 @@ namespace GitHub.Runner.Sdk
|
|||||||
{
|
{
|
||||||
foreach (KeyValuePair<string, string> kvp in environment)
|
foreach (KeyValuePair<string, string> kvp in environment)
|
||||||
{
|
{
|
||||||
#if OS_WINDOWS
|
|
||||||
string tempKey = String.IsNullOrWhiteSpace(kvp.Key) ? kvp.Key : kvp.Key.Split('\0')[0];
|
|
||||||
string tempValue = String.IsNullOrWhiteSpace(kvp.Value) ? kvp.Value : kvp.Value.Split('\0')[0];
|
|
||||||
if(!String.IsNullOrWhiteSpace(tempKey))
|
|
||||||
{
|
|
||||||
_proc.StartInfo.Environment[tempKey] = tempValue;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
_proc.StartInfo.Environment[kvp.Key] = kvp.Value;
|
_proc.StartInfo.Environment[kvp.Key] = kvp.Value;
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ namespace GitHub.Runner.Worker.Container.ContainerHooks
|
|||||||
EntryPointArgs = entryPointArgs.Split(' ').Select(arg => arg.Trim()),
|
EntryPointArgs = entryPointArgs.Split(' ').Select(arg => arg.Trim()),
|
||||||
EntryPoint = entryPoint,
|
EntryPoint = entryPoint,
|
||||||
EnvironmentVariables = environmentVariables,
|
EnvironmentVariables = environmentVariables,
|
||||||
PrependPath = prependPath,
|
PrependPath = context.Global.PrependPath.Reverse<string>(),
|
||||||
WorkingDirectory = workingDirectory,
|
WorkingDirectory = workingDirectory,
|
||||||
},
|
},
|
||||||
State = context.Global.ContainerHookState
|
State = context.Global.ContainerHookState
|
||||||
@@ -174,8 +174,7 @@ namespace GitHub.Runner.Worker.Container.ContainerHooks
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Trace.Error(ex);
|
throw new Exception($"Executing the custom container implementation failed. Please contact your self hosted runner administrator.", ex);
|
||||||
throw new Exception($"Custom container implementation failed with error: {ex.Message} Please contact your self hosted runner administrator.", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace GitHub.Runner.Worker.Container.ContainerHooks
|
|||||||
public IEnumerable<string> EntryPointArgs { get; set; }
|
public IEnumerable<string> EntryPointArgs { get; set; }
|
||||||
public string EntryPoint { get; set; }
|
public string EntryPoint { get; set; }
|
||||||
public IDictionary<string, string> EnvironmentVariables { get; set; }
|
public IDictionary<string, string> EnvironmentVariables { get; set; }
|
||||||
public string PrependPath { get; set; }
|
public IEnumerable<string> PrependPath { get; set; }
|
||||||
public string WorkingDirectory { get; set; }
|
public string WorkingDirectory { get; set; }
|
||||||
public bool IsRequireAlpineInResponse() => false;
|
public bool IsRequireAlpineInResponse() => false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,11 +131,11 @@ namespace GitHub.Runner.Worker.Container
|
|||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(env.Value))
|
if (String.IsNullOrEmpty(env.Value))
|
||||||
{
|
{
|
||||||
dockerOptions.Add(DockerUtil.CreateEscapedOption("-e", env.Key));
|
dockerOptions.Add($"-e \"{env.Key}\"");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dockerOptions.Add(DockerUtil.CreateEscapedOption("-e", env.Key, env.Value));
|
dockerOptions.Add($"-e \"{env.Key}={env.Value.Replace("\"", "\\\"")}\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ namespace GitHub.Runner.Worker.Container
|
|||||||
{
|
{
|
||||||
// e.g. -e MY_SECRET maps the value into the exec'ed process without exposing
|
// e.g. -e MY_SECRET maps the value into the exec'ed process without exposing
|
||||||
// the value directly in the command
|
// the value directly in the command
|
||||||
dockerOptions.Add(DockerUtil.CreateEscapedOption("-e", env.Key));
|
dockerOptions.Add($"-e {env.Key}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watermark for GitHub Action environment
|
// Watermark for GitHub Action environment
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ namespace GitHub.Runner.Worker.Container
|
|||||||
{
|
{
|
||||||
public class DockerUtil
|
public class DockerUtil
|
||||||
{
|
{
|
||||||
private static readonly Regex QuoteEscape = new Regex(@"(\\*)" + "\"", RegexOptions.Compiled);
|
|
||||||
private static readonly Regex EndOfStringEscape = new Regex(@"(\\+)$", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
public static List<PortMapping> ParseDockerPort(IList<string> portMappingLines)
|
public static List<PortMapping> ParseDockerPort(IList<string> portMappingLines)
|
||||||
{
|
{
|
||||||
const string targetPort = "targetPort";
|
const string targetPort = "targetPort";
|
||||||
@@ -20,7 +17,7 @@ namespace GitHub.Runner.Worker.Container
|
|||||||
string pattern = $"^(?<{targetPort}>\\d+)/(?<{proto}>\\w+) -> (?<{host}>.+):(?<{hostPort}>\\d+)$";
|
string pattern = $"^(?<{targetPort}>\\d+)/(?<{proto}>\\w+) -> (?<{host}>.+):(?<{hostPort}>\\d+)$";
|
||||||
|
|
||||||
List<PortMapping> portMappings = new List<PortMapping>();
|
List<PortMapping> portMappings = new List<PortMapping>();
|
||||||
foreach (var line in portMappingLines)
|
foreach(var line in portMappingLines)
|
||||||
{
|
{
|
||||||
Match m = Regex.Match(line, pattern, RegexOptions.None, TimeSpan.FromSeconds(1));
|
Match m = Regex.Match(line, pattern, RegexOptions.None, TimeSpan.FromSeconds(1));
|
||||||
if (m.Success)
|
if (m.Success)
|
||||||
@@ -64,44 +61,5 @@ namespace GitHub.Runner.Worker.Container
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CreateEscapedOption(string flag, string key)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(key))
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return $"{flag} {EscapeString(key)}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string CreateEscapedOption(string flag, string key, string value)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(key))
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
var escapedString = EscapeString($"{key}={value}");
|
|
||||||
return $"{flag} {escapedString}";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string EscapeString(string value)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
// Dotnet escaping rules are weird here, we can only escape \ if it precedes a "
|
|
||||||
// If a double quotation mark follows two or an even number of backslashes, each proceeding backslash pair is replaced with one backslash and the double quotation mark is removed.
|
|
||||||
// If a double quotation mark follows an odd number of backslashes, including just one, each preceding pair is replaced with one backslash and the remaining backslash is removed; however, in this case the double quotation mark is not removed.
|
|
||||||
// https://docs.microsoft.com/en-us/dotnet/api/system.environment.getcommandlineargs?redirectedfrom=MSDN&view=net-6.0#remarks
|
|
||||||
|
|
||||||
// First, find any \ followed by a " and double the number of \ + 1.
|
|
||||||
value = QuoteEscape.Replace(value, @"$1$1\" + "\"");
|
|
||||||
// Next, what if it ends in `\`, it would escape the end quote. So, we need to detect that at the end of the string and perform the same escape
|
|
||||||
// Luckily, we can just use the $ character with detects the end of string in regex
|
|
||||||
value = EndOfStringEscape.Replace(value, @"$1$1");
|
|
||||||
// Finally, wrap it in quotes
|
|
||||||
return $"\"{value}\"";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using GitHub.DistributedTask.Pipelines.ContextData;
|
|||||||
using GitHub.DistributedTask.WebApi;
|
using GitHub.DistributedTask.WebApi;
|
||||||
using GitHub.Runner.Common;
|
using GitHub.Runner.Common;
|
||||||
using GitHub.Runner.Sdk;
|
using GitHub.Runner.Sdk;
|
||||||
|
using GitHub.Runner.Common.Util;
|
||||||
using GitHub.Runner.Worker.Container;
|
using GitHub.Runner.Worker.Container;
|
||||||
using GitHub.Runner.Worker.Container.ContainerHooks;
|
using GitHub.Runner.Worker.Container.ContainerHooks;
|
||||||
|
|
||||||
@@ -104,6 +105,12 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
Data.NodeVersion = "node16";
|
Data.NodeVersion = "node16";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
string forcedNodeVersion = System.Environment.GetEnvironmentVariable(Constants.Variables.Agent.ForcedActionsNodeVersion);
|
||||||
|
|
||||||
|
if (forcedNodeVersion == "node16" && Data.NodeVersion != "node16")
|
||||||
|
{
|
||||||
|
Data.NodeVersion = "node16";
|
||||||
|
}
|
||||||
var nodeRuntimeVersion = await StepHost.DetermineNodeRuntimeVersion(ExecutionContext, Data.NodeVersion);
|
var nodeRuntimeVersion = await StepHost.DetermineNodeRuntimeVersion(ExecutionContext, Data.NodeVersion);
|
||||||
string file = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), nodeRuntimeVersion, "bin", $"node{IOUtil.ExeExtension}");
|
string file = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), nodeRuntimeVersion, "bin", $"node{IOUtil.ExeExtension}");
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
TranslateToContainerPath(environment);
|
TranslateToContainerPath(environment);
|
||||||
await containerHookManager.RunScriptStepAsync(context,
|
await containerHookManager.RunScriptStepAsync(context,
|
||||||
Container,
|
Container,
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
fileName,
|
fileName,
|
||||||
arguments,
|
arguments,
|
||||||
environment,
|
environment,
|
||||||
@@ -216,7 +216,7 @@ namespace GitHub.Runner.Worker.Handlers
|
|||||||
{
|
{
|
||||||
// e.g. -e MY_SECRET maps the value into the exec'ed process without exposing
|
// e.g. -e MY_SECRET maps the value into the exec'ed process without exposing
|
||||||
// the value directly in the command
|
// the value directly in the command
|
||||||
dockerCommandArgs.Add(DockerUtil.CreateEscapedOption("-e", env.Key));
|
dockerCommandArgs.Add($"-e {env.Key}");
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(PrependPath))
|
if (!string.IsNullOrEmpty(PrependPath))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -144,54 +144,5 @@ namespace GitHub.Runner.Common.Tests.Worker.Container
|
|||||||
var actual = DockerUtil.ParseRegistryHostnameFromImageName(input);
|
var actual = DockerUtil.ParseRegistryHostnameFromImageName(input);
|
||||||
Assert.Equal(expected, actual);
|
Assert.Equal(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[Trait("Level", "L0")]
|
|
||||||
[Trait("Category", "Worker")]
|
|
||||||
[InlineData("", "")]
|
|
||||||
[InlineData("foo", "foo")]
|
|
||||||
[InlineData("foo \\ bar", "foo \\ bar")]
|
|
||||||
[InlineData("foo \\", "foo \\\\")]
|
|
||||||
[InlineData("foo \\\\", "foo \\\\\\\\")]
|
|
||||||
[InlineData("foo \\\" bar", "foo \\\\\\\" bar")]
|
|
||||||
[InlineData("foo \\\\\" bar", "foo \\\\\\\\\\\" bar")]
|
|
||||||
public void CreateEscapedOption_keyOnly(string input, string escaped)
|
|
||||||
{
|
|
||||||
var flag = "--example";
|
|
||||||
var actual = DockerUtil.CreateEscapedOption(flag, input);
|
|
||||||
string expected;
|
|
||||||
if (String.IsNullOrEmpty(input))
|
|
||||||
{
|
|
||||||
expected = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
expected = $"{flag} \"{escaped}\"";
|
|
||||||
}
|
|
||||||
Assert.Equal(expected, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[Trait("Level", "L0")]
|
|
||||||
[Trait("Category", "Worker")]
|
|
||||||
[InlineData("foo", "bar", "foo=bar")]
|
|
||||||
[InlineData("foo\\", "bar", "foo\\=bar")]
|
|
||||||
[InlineData("foo\\", "bar\\", "foo\\=bar\\\\")]
|
|
||||||
[InlineData("foo \\","bar \\", "foo \\=bar \\\\")]
|
|
||||||
public void CreateEscapedOption_keyValue(string keyInput, string valueInput, string escapedString)
|
|
||||||
{
|
|
||||||
var flag = "--example";
|
|
||||||
var actual = DockerUtil.CreateEscapedOption(flag, keyInput, valueInput);
|
|
||||||
string expected;
|
|
||||||
if (String.IsNullOrEmpty(keyInput))
|
|
||||||
{
|
|
||||||
expected = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
expected = $"{flag} \"{escapedString}\"";
|
|
||||||
}
|
|
||||||
Assert.Equal(expected, actual);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,76 +129,7 @@ namespace GitHub.Runner.Common.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if OS_WINDOWS
|
|
||||||
[Fact]
|
|
||||||
[Trait("Level", "L0")]
|
|
||||||
[Trait("Category", "Common")]
|
|
||||||
public async Task SetTestEnvWithNullInKey()
|
|
||||||
{
|
|
||||||
using (TestHostContext hc = new(this))
|
|
||||||
{
|
|
||||||
Tracing trace = hc.GetTrace();
|
|
||||||
|
|
||||||
Int32 exitCode = -1;
|
|
||||||
var processInvoker = new ProcessInvokerWrapper();
|
|
||||||
processInvoker.Initialize(hc);
|
|
||||||
var stdout = new List<string>();
|
|
||||||
var stderr = new List<string>();
|
|
||||||
processInvoker.OutputDataReceived += (object sender, ProcessDataReceivedEventArgs e) =>
|
|
||||||
{
|
|
||||||
trace.Info(e.Data);
|
|
||||||
stdout.Add(e.Data);
|
|
||||||
};
|
|
||||||
processInvoker.ErrorDataReceived += (object sender, ProcessDataReceivedEventArgs e) =>
|
|
||||||
{
|
|
||||||
trace.Info(e.Data);
|
|
||||||
stderr.Add(e.Data);
|
|
||||||
};
|
|
||||||
|
|
||||||
exitCode = await processInvoker.ExecuteAsync("", "cmd.exe", "/c \"echo %TEST%\"", new Dictionary<string, string>() { { "TEST\0second", "first" } }, CancellationToken.None);
|
|
||||||
|
|
||||||
|
|
||||||
trace.Info("Exit Code: {0}", exitCode);
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
Assert.Equal("first", stdout.First(x => !string.IsNullOrWhiteSpace(x)));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
[Trait("Level", "L0")]
|
|
||||||
[Trait("Category", "Common")]
|
|
||||||
public async Task SetTestEnvWithNullInValue()
|
|
||||||
{
|
|
||||||
using (TestHostContext hc = new(this))
|
|
||||||
{
|
|
||||||
Tracing trace = hc.GetTrace();
|
|
||||||
|
|
||||||
Int32 exitCode = -1;
|
|
||||||
var processInvoker = new ProcessInvokerWrapper();
|
|
||||||
processInvoker.Initialize(hc);
|
|
||||||
var stdout = new List<string>();
|
|
||||||
var stderr = new List<string>();
|
|
||||||
processInvoker.OutputDataReceived += (object sender, ProcessDataReceivedEventArgs e) =>
|
|
||||||
{
|
|
||||||
trace.Info(e.Data);
|
|
||||||
stdout.Add(e.Data);
|
|
||||||
};
|
|
||||||
processInvoker.ErrorDataReceived += (object sender, ProcessDataReceivedEventArgs e) =>
|
|
||||||
{
|
|
||||||
trace.Info(e.Data);
|
|
||||||
stderr.Add(e.Data);
|
|
||||||
};
|
|
||||||
|
|
||||||
exitCode = await processInvoker.ExecuteAsync("", "cmd.exe", "/c \"echo %TEST%\"", new Dictionary<string, string>() { { "TEST", "first\0second" } }, CancellationToken.None);
|
|
||||||
|
|
||||||
trace.Info("Exit Code: {0}", exitCode);
|
|
||||||
Assert.Equal(0, exitCode);
|
|
||||||
Assert.Equal("first", stdout.First(x => !string.IsNullOrWhiteSpace(x)));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Trait("Level", "L0")]
|
[Trait("Level", "L0")]
|
||||||
[Trait("Category", "Common")]
|
[Trait("Category", "Common")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2.293.2
|
2.294.0
|
||||||
|
|||||||
Reference in New Issue
Block a user