mirror of
https://github.com/actions/runner.git
synced 2026-02-03 11:17:13 +08:00
Compare commits
1 Commits
main
...
users/eric
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9167ce7c07 |
@@ -318,6 +318,17 @@ namespace GitHub.Runner.Worker
|
||||
context.AddIssue(issue, ExecutionContextLogOptions.Default);
|
||||
}
|
||||
|
||||
if (!context.Global.HasDeprecatedSetOutput)
|
||||
{
|
||||
context.Global.HasDeprecatedSetOutput = true;
|
||||
var telemetry = new JobTelemetry
|
||||
{
|
||||
Type = JobTelemetryType.ActionCommand,
|
||||
Message = "DeprecatedCommand: set-output"
|
||||
};
|
||||
context.Global.JobTelemetry.Add(telemetry);
|
||||
}
|
||||
|
||||
if (!command.Properties.TryGetValue(SetOutputCommandProperties.Name, out string outputName) || string.IsNullOrEmpty(outputName))
|
||||
{
|
||||
throw new Exception("Required field 'name' is missing in ##[set-output] command.");
|
||||
@@ -353,6 +364,17 @@ namespace GitHub.Runner.Worker
|
||||
context.AddIssue(issue, ExecutionContextLogOptions.Default);
|
||||
}
|
||||
|
||||
if (!context.Global.HasDeprecatedSaveState)
|
||||
{
|
||||
context.Global.HasDeprecatedSaveState = true;
|
||||
var telemetry = new JobTelemetry
|
||||
{
|
||||
Type = JobTelemetryType.ActionCommand,
|
||||
Message = "DeprecatedCommand: save-state"
|
||||
};
|
||||
context.Global.JobTelemetry.Add(telemetry);
|
||||
}
|
||||
|
||||
if (!command.Properties.TryGetValue(SaveStateCommandProperties.Name, out string stateName) || string.IsNullOrEmpty(stateName))
|
||||
{
|
||||
throw new Exception("Required field 'name' is missing in ##[save-state] command.");
|
||||
|
||||
@@ -31,5 +31,7 @@ namespace GitHub.Runner.Worker
|
||||
public JObject ContainerHookState { get; set; }
|
||||
public bool HasTemplateEvaluatorMismatch { get; set; }
|
||||
public bool HasActionManifestMismatch { get; set; }
|
||||
public bool HasDeprecatedSetOutput { get; set; }
|
||||
public bool HasDeprecatedSaveState { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,6 +457,8 @@ namespace GitHub.Runner.Common.Tests.Worker
|
||||
new SetEnvCommandExtension(),
|
||||
new WarningCommandExtension(),
|
||||
new AddMaskCommandExtension(),
|
||||
new SetOutputCommandExtension(),
|
||||
new SaveStateCommandExtension(),
|
||||
};
|
||||
foreach (var command in commands)
|
||||
{
|
||||
@@ -499,5 +501,53 @@ namespace GitHub.Runner.Common.Tests.Worker
|
||||
};
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Worker")]
|
||||
public void SetOutputCommand_EmitsTelemetryOnce()
|
||||
{
|
||||
using (TestHostContext hc = CreateTestContext())
|
||||
{
|
||||
_ec.Object.Global.JobTelemetry = new List<JobTelemetry>();
|
||||
var reference = string.Empty;
|
||||
_ec.Setup(x => x.SetOutput(It.IsAny<string>(), It.IsAny<string>(), out reference));
|
||||
|
||||
// First set-output should add telemetry
|
||||
Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::set-output name=foo::bar", null));
|
||||
Assert.Single(_ec.Object.Global.JobTelemetry);
|
||||
Assert.Equal(JobTelemetryType.ActionCommand, _ec.Object.Global.JobTelemetry[0].Type);
|
||||
Assert.Equal("DeprecatedCommand: set-output", _ec.Object.Global.JobTelemetry[0].Message);
|
||||
Assert.True(_ec.Object.Global.HasDeprecatedSetOutput);
|
||||
|
||||
// Second set-output should not add another telemetry entry
|
||||
Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::set-output name=foo2::bar2", null));
|
||||
Assert.Single(_ec.Object.Global.JobTelemetry);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Worker")]
|
||||
public void SaveStateCommand_EmitsTelemetryOnce()
|
||||
{
|
||||
using (TestHostContext hc = CreateTestContext())
|
||||
{
|
||||
_ec.Object.Global.JobTelemetry = new List<JobTelemetry>();
|
||||
_ec.Setup(x => x.IsEmbedded).Returns(false);
|
||||
_ec.Setup(x => x.IntraActionState).Returns(new Dictionary<string, string>());
|
||||
|
||||
// First save-state should add telemetry
|
||||
Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::save-state name=foo::bar", null));
|
||||
Assert.Single(_ec.Object.Global.JobTelemetry);
|
||||
Assert.Equal(JobTelemetryType.ActionCommand, _ec.Object.Global.JobTelemetry[0].Type);
|
||||
Assert.Equal("DeprecatedCommand: save-state", _ec.Object.Global.JobTelemetry[0].Message);
|
||||
Assert.True(_ec.Object.Global.HasDeprecatedSaveState);
|
||||
|
||||
// Second save-state should not add another telemetry entry
|
||||
Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::save-state name=foo2::bar2", null));
|
||||
Assert.Single(_ec.Object.Global.JobTelemetry);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user