public void EnablePluginInternalCommand() { using (TestHostContext hc = CreateTestContext()) { _ec.Setup(x => x.Write(It.IsAny <string>(), It.IsAny <string>())) .Returns((string tag, string line) => { hc.GetTrace().Info($"{tag} {line}"); return(1); }); _ec.Setup(x => x.AddIssue(It.IsAny <Issue>(), It.IsAny <string>())) .Callback((Issue issue, string message) => { hc.GetTrace().Info($"{issue.Type} {issue.Message} {message ?? string.Empty}"); }); _commandManager.EnablePluginInternalCommand(); Assert.True(_commandManager.TryProcessCommand(_ec.Object, "##[internal-set-repo-path repoFullName=actions/runner;workspaceRepo=true]somepath", null)); _pipelineDirectoryManager.Verify(x => x.UpdateRepositoryDirectory(_ec.Object, "actions/runner", "somepath", true), Times.Once); } }
public void DisablePluginInternalCommand() { using (TestHostContext _hc = new TestHostContext(this)) { var extensionManger = new Mock <IExtensionManager>(); var directoryManager = new Mock <IPipelineDirectoryManager>(); var pluginCommand = new InternalPluginSetRepoPathCommandExtension(); pluginCommand.Initialize(_hc); var envCommand = new SetEnvCommandExtension(); envCommand.Initialize(_hc); extensionManger.Setup(x => x.GetExtensions <IActionCommandExtension>()) .Returns(new List <IActionCommandExtension>() { pluginCommand, envCommand }); _hc.SetSingleton <IExtensionManager>(extensionManger.Object); _hc.SetSingleton <IPipelineDirectoryManager>(directoryManager.Object); Mock <IExecutionContext> _ec = new Mock <IExecutionContext>(); _ec.Setup(x => x.Write(It.IsAny <string>(), It.IsAny <string>())) .Returns((string tag, string line) => { _hc.GetTrace().Info($"{tag} {line}"); return(1); }); _ec.Setup(x => x.AddIssue(It.IsAny <Issue>(), It.IsAny <string>())) .Callback((Issue issue, string message) => { _hc.GetTrace().Info($"{issue.Type} {issue.Message} {message ?? string.Empty}"); }); ActionCommandManager commandManager = new ActionCommandManager(); commandManager.Initialize(_hc); commandManager.EnablePluginInternalCommand(); Assert.True(commandManager.TryProcessCommand(_ec.Object, "##[internal-set-repo-path repoFullName=actions/runner;workspaceRepo=true]somepath")); commandManager.DisablePluginInternalCommand(); Assert.False(commandManager.TryProcessCommand(_ec.Object, "##[internal-set-repo-path repoFullName=actions/runner;workspaceRepo=true]somepath")); directoryManager.Verify(x => x.UpdateRepositoryDirectory(_ec.Object, "actions/runner", "somepath", true), Times.Once); } }
public async Task RunAsync(ActionRunStage stage) { // Validate args. Trace.Entering(); ArgUtil.NotNull(Data, nameof(Data)); ArgUtil.NotNull(ExecutionContext, nameof(ExecutionContext)); ArgUtil.NotNull(Inputs, nameof(Inputs)); string plugin = null; if (stage == ActionRunStage.Main) { plugin = Data.Plugin; } else if (stage == ActionRunStage.Post) { plugin = Data.Cleanup; } ArgUtil.NotNullOrEmpty(plugin, nameof(plugin)); // Update the env dictionary. AddPrependPathToEnvironment(); // Make sure only particular task get run as runner plugin. var runnerPlugin = HostContext.GetService <IRunnerPluginManager>(); using (var outputManager = new OutputManager(ExecutionContext, ActionCommandManager)) { ActionCommandManager.EnablePluginInternalCommand(); try { await runnerPlugin.RunPluginActionAsync(ExecutionContext, plugin, Inputs, Environment, RuntimeVariables, outputManager.OnDataReceived); } finally { ActionCommandManager.DisablePluginInternalCommand(); } } }