mirror of
https://github.com/actions/runner.git
synced 2025-12-14 13:17:08 +00:00
Filter NODE_OPTIONS from env for file output (#2775)
Copies logic that used to be in ::set::env before its deprecation
This commit is contained in:
@@ -141,6 +141,28 @@ namespace GitHub.Runner.Worker
|
|||||||
var pairs = new EnvFileKeyValuePairs(context, filePath);
|
var pairs = new EnvFileKeyValuePairs(context, filePath);
|
||||||
foreach (var pair in pairs)
|
foreach (var pair in pairs)
|
||||||
{
|
{
|
||||||
|
var isBlocked = false;
|
||||||
|
foreach (var blocked in _setEnvBlockList)
|
||||||
|
{
|
||||||
|
if (string.Equals(blocked, pair.Key, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
// Log Telemetry and let user know they shouldn't do this
|
||||||
|
var issue = new Issue()
|
||||||
|
{
|
||||||
|
Type = IssueType.Error,
|
||||||
|
Message = $"Can't store {blocked} output parameter using '$GITHUB_ENV' command."
|
||||||
|
};
|
||||||
|
issue.Data[Constants.Runner.InternalTelemetryIssueDataKey] = $"{Constants.Runner.UnsupportedCommand}_{pair.Key}";
|
||||||
|
context.AddIssue(issue, ExecutionContextLogOptions.Default);
|
||||||
|
|
||||||
|
isBlocked = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isBlocked)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
SetEnvironmentVariable(context, pair.Key, pair.Value);
|
SetEnvironmentVariable(context, pair.Key, pair.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,6 +176,11 @@ namespace GitHub.Runner.Worker
|
|||||||
context.SetEnvContext(name, value);
|
context.SetEnvContext(name, value);
|
||||||
context.Debug($"{name}='{value}'");
|
context.Debug($"{name}='{value}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string[] _setEnvBlockList =
|
||||||
|
{
|
||||||
|
"NODE_OPTIONS"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class CreateStepSummaryCommand : RunnerService, IFileCommandExtension
|
public sealed class CreateStepSummaryCommand : RunnerService, IFileCommandExtension
|
||||||
|
|||||||
@@ -183,6 +183,47 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("Level", "L0")]
|
||||||
|
[Trait("Category", "Worker")]
|
||||||
|
public void SetEnvFileCommand_BlockListItemsFiltered()
|
||||||
|
{
|
||||||
|
using (var hostContext = Setup())
|
||||||
|
{
|
||||||
|
var stateFile = Path.Combine(_rootDirectory, "simple");
|
||||||
|
var content = new List<string>
|
||||||
|
{
|
||||||
|
"NODE_OPTIONS=asdf",
|
||||||
|
};
|
||||||
|
WriteContent(stateFile, content);
|
||||||
|
_setEnvFileCommand.ProcessCommand(_executionContext.Object, stateFile, null);
|
||||||
|
Assert.Equal(1, _issues.Count);
|
||||||
|
Assert.Equal(0, _executionContext.Object.Global.EnvironmentVariables.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("Level", "L0")]
|
||||||
|
[Trait("Category", "Worker")]
|
||||||
|
public void SetEnvFileCommand_BlockListItemsFiltered_Heredoc()
|
||||||
|
{
|
||||||
|
using (var hostContext = Setup())
|
||||||
|
{
|
||||||
|
var stateFile = Path.Combine(_rootDirectory, "simple");
|
||||||
|
var content = new List<string>
|
||||||
|
{
|
||||||
|
"NODE_OPTIONS<<EOF",
|
||||||
|
"asdf",
|
||||||
|
"EOF",
|
||||||
|
};
|
||||||
|
WriteContent(stateFile, content);
|
||||||
|
_setEnvFileCommand.ProcessCommand(_executionContext.Object, stateFile, null);
|
||||||
|
Assert.Equal(1, _issues.Count);
|
||||||
|
Assert.Equal(0, _executionContext.Object.Global.EnvironmentVariables.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Trait("Level", "L0")]
|
[Trait("Level", "L0")]
|
||||||
[Trait("Category", "Worker")]
|
[Trait("Category", "Worker")]
|
||||||
|
|||||||
Reference in New Issue
Block a user