diff --git a/src/Runner.Common/ConfigurationStore.cs b/src/Runner.Common/ConfigurationStore.cs index ccf9298fa..11a7504d5 100644 --- a/src/Runner.Common/ConfigurationStore.cs +++ b/src/Runner.Common/ConfigurationStore.cs @@ -139,7 +139,6 @@ namespace GitHub.Runner.Common public bool HasCredentials() { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); Trace.Info("HasCredentials()"); bool credsStored = (new FileInfo(_credFilePath)).Exists; Trace.Info("stored {0}", credsStored); @@ -149,14 +148,13 @@ namespace GitHub.Runner.Common public bool IsConfigured() { Trace.Info("IsConfigured()"); - bool configured = HostContext.RunMode == RunMode.Local || (new FileInfo(_configFilePath)).Exists; + bool configured = new FileInfo(_configFilePath).Exists; Trace.Info("IsConfigured: {0}", configured); return configured; } public bool IsServiceConfigured() { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); Trace.Info("IsServiceConfigured()"); bool serviceConfigured = (new FileInfo(_serviceConfigFilePath)).Exists; Trace.Info($"IsServiceConfigured: {serviceConfigured}"); @@ -165,7 +163,6 @@ namespace GitHub.Runner.Common public CredentialData GetCredentials() { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); if (_creds == null) { _creds = IOUtil.LoadObject(_credFilePath); @@ -195,7 +192,6 @@ namespace GitHub.Runner.Common public void SaveCredential(CredentialData credential) { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); Trace.Info("Saving {0} credential @ {1}", credential.Scheme, _credFilePath); if (File.Exists(_credFilePath)) { @@ -211,7 +207,6 @@ namespace GitHub.Runner.Common public void SaveSettings(RunnerSettings settings) { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); Trace.Info("Saving runner settings."); if (File.Exists(_configFilePath)) { @@ -227,13 +222,11 @@ namespace GitHub.Runner.Common public void DeleteCredential() { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); IOUtil.Delete(_credFilePath, default(CancellationToken)); } public void DeleteSettings() { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); IOUtil.Delete(_configFilePath, default(CancellationToken)); } diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index c7c0b7a0e..bb48aeaa8 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -2,12 +2,6 @@ namespace GitHub.Runner.Common { - public enum RunMode - { - Normal, // Keep "Normal" first (default value). - Local, - } - public enum WellKnownDirectory { Bin, diff --git a/src/Runner.Common/HostContext.cs b/src/Runner.Common/HostContext.cs index f49932adc..f20a9c4e4 100644 --- a/src/Runner.Common/HostContext.cs +++ b/src/Runner.Common/HostContext.cs @@ -20,7 +20,6 @@ namespace GitHub.Runner.Common { public interface IHostContext : IDisposable { - RunMode RunMode { get; set; } StartupType StartupType { get; set; } CancellationToken RunnerShutdownToken { get; } ShutdownReason RunnerShutdownReason { get; } @@ -58,7 +57,6 @@ namespace GitHub.Runner.Common private readonly ProductInfoHeaderValue _userAgent = new ProductInfoHeaderValue($"GitHubActionsRunner-{BuildConstants.RunnerPackage.PackageName}", BuildConstants.RunnerPackage.Version); private CancellationTokenSource _runnerShutdownTokenSource = new CancellationTokenSource(); private object _perfLock = new object(); - private RunMode _runMode = RunMode.Normal; private Tracing _trace; private Tracing _vssTrace; private Tracing _httpTrace; @@ -194,20 +192,6 @@ namespace GitHub.Runner.Common } } - public RunMode RunMode - { - get - { - return _runMode; - } - - set - { - _trace.Info($"Set run mode: {value}"); - _runMode = value; - } - } - public string GetDirectory(WellKnownDirectory directory) { string path; diff --git a/src/Runner.Common/JobServer.cs b/src/Runner.Common/JobServer.cs index d7576199e..860555419 100644 --- a/src/Runner.Common/JobServer.cs +++ b/src/Runner.Common/JobServer.cs @@ -32,11 +32,6 @@ namespace GitHub.Runner.Common public async Task ConnectAsync(VssConnection jobConnection) { - if (HostContext.RunMode == RunMode.Local) - { - return; - } - _connection = jobConnection; int attemptCount = 5; while (!_connection.HasAuthenticated && attemptCount-- > 0) @@ -73,88 +68,48 @@ namespace GitHub.Runner.Common public Task AppendLogContentAsync(Guid scopeIdentifier, string hubName, Guid planId, int logId, Stream uploadStream, CancellationToken cancellationToken) { - if (HostContext.RunMode == RunMode.Local) - { - return Task.FromResult(null); - } - CheckConnection(); return _taskClient.AppendLogContentAsync(scopeIdentifier, hubName, planId, logId, uploadStream, cancellationToken: cancellationToken); } public Task AppendTimelineRecordFeedAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId, Guid timelineRecordId, Guid stepId, IList lines, CancellationToken cancellationToken) { - if (HostContext.RunMode == RunMode.Local) - { - return Task.CompletedTask; - } - CheckConnection(); return _taskClient.AppendTimelineRecordFeedAsync(scopeIdentifier, hubName, planId, timelineId, timelineRecordId, stepId, lines, cancellationToken: cancellationToken); } public Task CreateAttachmentAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId, Guid timelineRecordId, string type, string name, Stream uploadStream, CancellationToken cancellationToken) { - if (HostContext.RunMode == RunMode.Local) - { - return Task.FromResult(null); - } - CheckConnection(); return _taskClient.CreateAttachmentAsync(scopeIdentifier, hubName, planId, timelineId, timelineRecordId, type, name, uploadStream, cancellationToken: cancellationToken); } public Task CreateLogAsync(Guid scopeIdentifier, string hubName, Guid planId, TaskLog log, CancellationToken cancellationToken) { - if (HostContext.RunMode == RunMode.Local) - { - return Task.FromResult(null); - } - CheckConnection(); return _taskClient.CreateLogAsync(scopeIdentifier, hubName, planId, log, cancellationToken: cancellationToken); } public Task CreateTimelineAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId, CancellationToken cancellationToken) { - if (HostContext.RunMode == RunMode.Local) - { - return Task.FromResult(null); - } - CheckConnection(); return _taskClient.CreateTimelineAsync(scopeIdentifier, hubName, planId, new Timeline(timelineId), cancellationToken: cancellationToken); } public Task> UpdateTimelineRecordsAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId, IEnumerable records, CancellationToken cancellationToken) { - if (HostContext.RunMode == RunMode.Local) - { - return Task.FromResult>(null); - } - CheckConnection(); return _taskClient.UpdateTimelineRecordsAsync(scopeIdentifier, hubName, planId, timelineId, records, cancellationToken: cancellationToken); } public Task RaisePlanEventAsync(Guid scopeIdentifier, string hubName, Guid planId, T eventData, CancellationToken cancellationToken) where T : JobEvent { - if (HostContext.RunMode == RunMode.Local) - { - return Task.CompletedTask; - } - CheckConnection(); return _taskClient.RaisePlanEventAsync(scopeIdentifier, hubName, planId, eventData, cancellationToken: cancellationToken); } public Task GetTimelineAsync(Guid scopeIdentifier, string hubName, Guid planId, Guid timelineId, CancellationToken cancellationToken) { - if (HostContext.RunMode == RunMode.Local) - { - return Task.FromResult(null); - } - CheckConnection(); return _taskClient.GetTimelineAsync(scopeIdentifier, hubName, planId, timelineId, includeRecords: true, cancellationToken: cancellationToken); } diff --git a/src/Runner.Common/JobServerQueue.cs b/src/Runner.Common/JobServerQueue.cs index 5ffd7eac2..787daeffd 100644 --- a/src/Runner.Common/JobServerQueue.cs +++ b/src/Runner.Common/JobServerQueue.cs @@ -63,7 +63,6 @@ namespace GitHub.Runner.Common private Task[] _allDequeueTasks; private readonly TaskCompletionSource _jobCompletionSource = new TaskCompletionSource(); private bool _queueInProcess = false; - private ITerminal _term; public event EventHandler JobServerQueueThrottling; @@ -85,11 +84,6 @@ namespace GitHub.Runner.Common public void Start(Pipelines.AgentJobRequestMessage jobRequest) { Trace.Entering(); - if (HostContext.RunMode == RunMode.Local) - { - _term = HostContext.GetService(); - return; - } if (_queueInProcess) { @@ -129,11 +123,6 @@ namespace GitHub.Runner.Common // TimelineUpdate queue error will become critical when timeline records contain output variabls. public async Task ShutdownAsync() { - if (HostContext.RunMode == RunMode.Local) - { - return; - } - if (!_queueInProcess) { Trace.Info("No-op, all queue process tasks have been stopped."); @@ -169,32 +158,11 @@ namespace GitHub.Runner.Common public void QueueWebConsoleLine(Guid stepRecordId, string line) { Trace.Verbose("Enqueue web console line queue: {0}", line); - if (HostContext.RunMode == RunMode.Local) - { - if ((line ?? string.Empty).StartsWith("##[section]")) - { - Console.WriteLine("******************************************************************************"); - Console.WriteLine(line.Substring("##[section]".Length)); - Console.WriteLine("******************************************************************************"); - } - else - { - Console.WriteLine(line); - } - - return; - } - _webConsoleLineQueue.Enqueue(new ConsoleLineInfo(stepRecordId, line)); } public void QueueFileUpload(Guid timelineId, Guid timelineRecordId, string type, string name, string path, bool deleteSource) { - if (HostContext.RunMode == RunMode.Local) - { - return; - } - ArgUtil.NotEmpty(timelineId, nameof(timelineId)); ArgUtil.NotEmpty(timelineRecordId, nameof(timelineRecordId)); @@ -215,11 +183,6 @@ namespace GitHub.Runner.Common public void QueueTimelineRecordUpdate(Guid timelineId, TimelineRecord timelineRecord) { - if (HostContext.RunMode == RunMode.Local) - { - return; - } - ArgUtil.NotEmpty(timelineId, nameof(timelineId)); ArgUtil.NotNull(timelineRecord, nameof(timelineRecord)); ArgUtil.NotEmpty(timelineRecord.Id, nameof(timelineRecord.Id)); diff --git a/src/Runner.Common/RunnerServer.cs b/src/Runner.Common/RunnerServer.cs index 23200d46b..f06635aad 100644 --- a/src/Runner.Common/RunnerServer.cs +++ b/src/Runner.Common/RunnerServer.cs @@ -66,11 +66,6 @@ namespace GitHub.Runner.Common public async Task ConnectAsync(Uri serverUrl, VssCredentials credentials) { - if (HostContext.RunMode == RunMode.Local) - { - return; - } - var createGenericConnection = EstablishVssConnection(serverUrl, credentials, TimeSpan.FromSeconds(100)); var createMessageConnection = EstablishVssConnection(serverUrl, credentials, TimeSpan.FromSeconds(60)); var createRequestConnection = EstablishVssConnection(serverUrl, credentials, TimeSpan.FromSeconds(60)); @@ -303,29 +298,18 @@ namespace GitHub.Runner.Common public Task RenewAgentRequestAsync(int poolId, long requestId, Guid lockToken, CancellationToken cancellationToken = default(CancellationToken)) { - if (HostContext.RunMode == RunMode.Local) - { - return Task.FromResult(JsonUtility.FromString("{ lockedUntil: \"" + DateTime.Now.Add(TimeSpan.FromMinutes(5)).ToString("u") + "\" }")); - } - CheckConnection(RunnerConnectionType.JobRequest); return _requestTaskAgentClient.RenewAgentRequestAsync(poolId, requestId, lockToken, cancellationToken: cancellationToken); } public Task FinishAgentRequestAsync(int poolId, long requestId, Guid lockToken, DateTime finishTime, TaskResult result, CancellationToken cancellationToken = default(CancellationToken)) { - if (HostContext.RunMode == RunMode.Local) - { - return Task.FromResult(null); - } - CheckConnection(RunnerConnectionType.JobRequest); return _requestTaskAgentClient.FinishAgentRequestAsync(poolId, requestId, lockToken, finishTime, result, cancellationToken: cancellationToken); } public Task GetAgentRequestAsync(int poolId, long requestId, CancellationToken cancellationToken = default(CancellationToken)) { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); CheckConnection(RunnerConnectionType.JobRequest); return _requestTaskAgentClient.GetAgentRequestAsync(poolId, requestId, cancellationToken: cancellationToken); } @@ -335,7 +319,6 @@ namespace GitHub.Runner.Common //----------------------------------------------------------------- public Task> GetPackagesAsync(string packageType, string platform, int top, CancellationToken cancellationToken) { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); CheckConnection(RunnerConnectionType.Generic); return _genericTaskAgentClient.GetPackagesAsync(packageType, platform, top, cancellationToken: cancellationToken); } diff --git a/src/Runner.Listener/Configuration/ConfigurationManager.cs b/src/Runner.Listener/Configuration/ConfigurationManager.cs index df394ac2e..ba9662642 100644 --- a/src/Runner.Listener/Configuration/ConfigurationManager.cs +++ b/src/Runner.Listener/Configuration/ConfigurationManager.cs @@ -79,7 +79,6 @@ namespace GitHub.Runner.Listener.Configuration _term.WriteLine("| |", ConsoleColor.White); _term.WriteLine("--------------------------------------------------------------------------------", ConsoleColor.White); - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); Trace.Info(nameof(ConfigureAsync)); if (IsConfigured()) { @@ -397,7 +396,6 @@ namespace GitHub.Runner.Listener.Configuration public async Task UnconfigureAsync(CommandSettings command) { - ArgUtil.Equal(RunMode.Normal, HostContext.RunMode, nameof(HostContext.RunMode)); string currentAction = string.Empty; _term.WriteSection("Runner removal"); diff --git a/src/Runner.Listener/JobDispatcher.cs b/src/Runner.Listener/JobDispatcher.cs index d48f2f6ce..867fffb3b 100644 --- a/src/Runner.Listener/JobDispatcher.cs +++ b/src/Runner.Listener/JobDispatcher.cs @@ -367,37 +367,29 @@ namespace GitHub.Runner.Listener ArgUtil.NotNullOrEmpty(pipeHandleOut, nameof(pipeHandleOut)); ArgUtil.NotNullOrEmpty(pipeHandleIn, nameof(pipeHandleIn)); - if (HostContext.RunMode == RunMode.Normal) + // Save STDOUT from worker, worker will use STDOUT report unhandle exception. + processInvoker.OutputDataReceived += delegate (object sender, ProcessDataReceivedEventArgs stdout) { - // Save STDOUT from worker, worker will use STDOUT report unhandle exception. - processInvoker.OutputDataReceived += delegate (object sender, ProcessDataReceivedEventArgs stdout) + if (!string.IsNullOrEmpty(stdout.Data)) { - if (!string.IsNullOrEmpty(stdout.Data)) + lock (_outputLock) { - lock (_outputLock) - { - workerOutput.Add(stdout.Data); - } + workerOutput.Add(stdout.Data); } - }; + } + }; - // Save STDERR from worker, worker will use STDERR on crash. - processInvoker.ErrorDataReceived += delegate (object sender, ProcessDataReceivedEventArgs stderr) - { - if (!string.IsNullOrEmpty(stderr.Data)) - { - lock (_outputLock) - { - workerOutput.Add(stderr.Data); - } - } - }; - } - else if (HostContext.RunMode == RunMode.Local) + // Save STDERR from worker, worker will use STDERR on crash. + processInvoker.ErrorDataReceived += delegate (object sender, ProcessDataReceivedEventArgs stderr) { - processInvoker.OutputDataReceived += (object sender, ProcessDataReceivedEventArgs e) => Console.WriteLine(e.Data); - processInvoker.ErrorDataReceived += (object sender, ProcessDataReceivedEventArgs e) => Console.WriteLine(e.Data); - } + if (!string.IsNullOrEmpty(stderr.Data)) + { + lock (_outputLock) + { + workerOutput.Add(stderr.Data); + } + } + }; // Start the child process. HostContext.WritePerfCounter("StartingWorkerProcess"); @@ -724,11 +716,6 @@ namespace GitHub.Runner.Listener private async Task CompleteJobRequestAsync(int poolId, Pipelines.AgentJobRequestMessage message, Guid lockToken, TaskResult result, string detailInfo = null) { Trace.Entering(); - if (HostContext.RunMode == RunMode.Local) - { - _localRunJobResult.Value[message.RequestId] = result; - return; - } if (PlanUtil.GetFeatures(message.Plan).HasFlag(PlanFeatures.JobCompletedPlanEvent)) {