Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make timeout for hashFiles() configureable #1844

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions src/Runner.Worker/Expressions/HashFilesFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace GitHub.Runner.Worker.Expressions
{
public sealed class HashFilesFunction : Function
{
private const int _hashFileTimeoutSeconds = 120;
private int _hashFileTimeoutSeconds = 120;

protected sealed override Object EvaluateCore(
EvaluationContext context,
Expand All @@ -33,25 +33,41 @@ protected sealed override Object EvaluateCore(
string githubWorkspace = workspaceData.Value;
bool followSymlink = false;
List<string> patterns = new List<string>();
var firstParameter = true;
foreach (var parameter in Parameters)
{
var parameterString = parameter.Evaluate(context).ConvertToString();
if (firstParameter)
if (parameterString.StartsWith("--"))
{
firstParameter = false;
if (parameterString.StartsWith("--"))
if (string.Equals(parameterString, "--follow-symbolic-links", StringComparison.OrdinalIgnoreCase))
{
if (string.Equals(parameterString, "--follow-symbolic-links", StringComparison.OrdinalIgnoreCase))
followSymlink = true;
continue;
}
else if (parameterString.StartsWith("--timeout=", StringComparison.OrdinalIgnoreCase))
{
var timeoutSecondsString = parameterString.Split("=")[1];
if (!String.IsNullOrEmpty(timeoutSecondsString))
{
followSymlink = true;
continue;
bool parsingSuccess = int.TryParse(timeoutSecondsString, out int timeoutSeconds);
if (parsingSuccess)
{
_hashFileTimeoutSeconds = timeoutSeconds;
continue;
}
else
{
throw new ArgumentOutOfRangeException($"Parsing of {timeoutSecondsString} to integer failed, please provide a number-like parameter like '--timeout=600'.");
}
}
else
{
throw new ArgumentOutOfRangeException($"Invalid glob option {parameterString}, avaliable option: '--follow-symbolic-links'.");
throw new ArgumentOutOfRangeException($"Timeout parameter was empty. Please provide a number-like parameter like '--timeout=600'.");
}
}
else
{
throw new ArgumentOutOfRangeException($"Invalid glob option {parameterString}, avaliable options: '--follow-symbolic-links', '--timeout=[number]'.");
}
}

patterns.Add(parameterString);
Expand Down Expand Up @@ -136,4 +152,4 @@ public void Verbose(string message)
}
}
}
}
}