From 7db53b03712c59db6e5c3a434d98eae91cbb514e Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Fri, 22 Dec 2023 10:04:14 -0500 Subject: [PATCH] Nullify `DreamMaker` --- .../Components/Chat/ChatManager.cs | 6 +- .../Components/Chat/IChatManager.cs | 2 +- .../Chat/Providers/DiscordProvider.cs | 2 +- .../Components/Chat/Providers/IProvider.cs | 2 +- .../Components/Chat/Providers/IrcProvider.cs | 2 +- .../Components/Chat/Providers/Provider.cs | 2 +- .../Components/Deployment/DreamMaker.cs | 93 +++++++++---------- .../Remote/BaseRemoteDeploymentManager.cs | 13 ++- .../Remote/IRemoteDeploymentManager.cs | 8 +- 9 files changed, 67 insertions(+), 63 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs b/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs index 3bedb438c8..d53e997b25 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs @@ -375,7 +375,7 @@ namespace Tgstation.Server.Host.Components.Chat } /// - public Func> QueueDeploymentMessage( + public Func> QueueDeploymentMessage( Models.RevisionInformation revisionInformation, EngineVersion engineVersion, DateTimeOffset? estimatedCompletionTime, @@ -389,7 +389,7 @@ namespace Tgstation.Server.Host.Components.Chat logger.LogTrace("Sending deployment message for RevisionInformation: {revisionInfoId}", revisionInformation.Id); - var callbacks = new List>>>(); + var callbacks = new List>>>(); var task = Task.WhenAll( wdChannels.Select( @@ -431,7 +431,7 @@ namespace Tgstation.Server.Host.Components.Chat Task callbackTask; Func? finalUpdateAction = null; - async Task CallbackTask(string errorMessage, string dreamMakerOutput) + async Task CallbackTask(string? errorMessage, string dreamMakerOutput) { await task; var callbackResults = await ValueTaskExtensions.WhenAll( diff --git a/src/Tgstation.Server.Host/Components/Chat/IChatManager.cs b/src/Tgstation.Server.Host/Components/Chat/IChatManager.cs index e053f7f1de..8a0aa33fe4 100644 --- a/src/Tgstation.Server.Host/Components/Chat/IChatManager.cs +++ b/src/Tgstation.Server.Host/Components/Chat/IChatManager.cs @@ -67,7 +67,7 @@ namespace Tgstation.Server.Host.Components.Chat /// The repository GitHub name, if any. /// if the local deployment commit was pushed to the remote repository. /// A to call to update the message at the deployment's conclusion. Parameters: Error message if any, DreamMaker output if any. Returns an to call to mark the deployment as active/inactive. Parameter: If the deployment is being activated or inactivated. - Func> QueueDeploymentMessage( + Func> QueueDeploymentMessage( Models.RevisionInformation revisionInformation, Api.Models.EngineVersion engineVersion, DateTimeOffset? estimatedCompletionTime, diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs index 6d06322dfc..047febbe00 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs @@ -285,7 +285,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers } /// - public override async ValueTask>>> SendUpdateMessage( + public override async ValueTask>>> SendUpdateMessage( Models.RevisionInformation revisionInformation, EngineVersion engineVersion, DateTimeOffset? estimatedCompletionTime, diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/IProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/IProvider.cs index 01b0d29a5e..845892d9e0 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/IProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/IProvider.cs @@ -92,7 +92,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers /// if the local deployment commit was pushed to the remote repository. /// The for the operation. /// A resulting in a to call to update the message at the deployment's conclusion. Parameters: Error message if any, DreamMaker output if any. Returns another callback which should be called to mark the deployment as active. - ValueTask>>> SendUpdateMessage( + ValueTask>>> SendUpdateMessage( Models.RevisionInformation revisionInformation, Api.Models.EngineVersion engineVersion, DateTimeOffset? estimatedCompletionTime, diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs index f8dfec4197..ad83a80b18 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs @@ -218,7 +218,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers } /// - public override async ValueTask>>> SendUpdateMessage( + public override async ValueTask>>> SendUpdateMessage( Models.RevisionInformation revisionInformation, EngineVersion engineVersion, DateTimeOffset? estimatedCompletionTime, diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/Provider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/Provider.cs index 4123521ad7..6be6b71521 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/Provider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/Provider.cs @@ -197,7 +197,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers public abstract ValueTask SendMessage(Message? replyTo, MessageContent message, ulong channelId, CancellationToken cancellationToken); /// - public abstract ValueTask>>> SendUpdateMessage( + public abstract ValueTask>>> SendUpdateMessage( RevisionInformation revisionInformation, Api.Models.EngineVersion engineVersion, DateTimeOffset? estimatedCompletionTime, diff --git a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs index 89f69f7d7b..f72d848082 100644 --- a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs +++ b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs @@ -25,8 +25,6 @@ using Tgstation.Server.Host.Models; using Tgstation.Server.Host.System; using Tgstation.Server.Host.Utils; -#nullable disable - namespace Tgstation.Server.Host.Components.Deployment { /// @@ -115,12 +113,12 @@ namespace Tgstation.Server.Host.Components.Deployment /// /// The active callback from . /// - Func> currentChatCallback; + Func>? currentChatCallback; /// /// Cached for . /// - string currentDreamMakerOutput; + string? currentDreamMakerOutput; /// /// If a compile job is running. @@ -209,18 +207,18 @@ namespace Tgstation.Server.Host.Components.Deployment currentChatCallback = null; currentDreamMakerOutput = null; - Models.CompileJob compileJob = null; + Models.CompileJob? compileJob = null; try { - string repoOwner = null; - string repoName = null; + string? repoOwner = null; + string? repoName = null; TimeSpan? averageSpan = null; - Models.RepositorySettings repositorySettings = null; - Models.DreamDaemonSettings ddSettings = null; - Models.DreamMakerSettings dreamMakerSettings = null; - IRepository repo = null; - IRemoteDeploymentManager remoteDeploymentManager = null; - Models.RevisionInformation revInfo = null; + Models.RepositorySettings? repositorySettings = null; + Models.DreamDaemonSettings? ddSettings = null; + Models.DreamMakerSettings? dreamMakerSettings = null; + IRepository? repo = null; + IRemoteDeploymentManager? remoteDeploymentManager = null; + Models.RevisionInformation? revInfo = null; await databaseContextFactory.UseContext( async databaseContext => { @@ -270,7 +268,7 @@ namespace Tgstation.Server.Host.Components.Deployment throw new JobException(ErrorCode.RepoMissing); remoteDeploymentManager = remoteDeploymentManagerFactory - .CreateRemoteDeploymentManager(metadata, repo.RemoteGitProvider.Value); + .CreateRemoteDeploymentManager(metadata, repo.RemoteGitProvider!.Value); var repoSha = repo.Head; repoOwner = repo.RemoteRepositoryOwner; @@ -278,13 +276,13 @@ namespace Tgstation.Server.Host.Components.Deployment revInfo = await databaseContext .RevisionInformations .AsQueryable() - .Where(x => x.CommitSha == repoSha && x.Instance.Id == metadata.Id) - .Include(x => x.ActiveTestMerges) - .ThenInclude(x => x.TestMerge) - .ThenInclude(x => x.MergedBy) + .Where(x => x.CommitSha == repoSha && x.InstanceId == metadata.Id) + .Include(x => x.ActiveTestMerges!) + .ThenInclude(x => x.TestMerge!) + .ThenInclude(x => x.MergedBy) .FirstOrDefaultAsync(cancellationToken); - if (revInfo == default) + if (revInfo == null) { revInfo = new Models.RevisionInformation { @@ -312,17 +310,17 @@ namespace Tgstation.Server.Host.Components.Deployment }); var likelyPushedTestMergeCommit = - repositorySettings.PushTestMergeCommits.Value + repositorySettings!.PushTestMergeCommits!.Value && repositorySettings.AccessToken != null && repositorySettings.AccessUser != null; using (repo) compileJob = await Compile( job, - revInfo, - dreamMakerSettings, - ddSettings, - repo, - remoteDeploymentManager, + revInfo!, + dreamMakerSettings!, + ddSettings!, + repo!, + remoteDeploymentManager!, progressReporter, averageSpan, likelyPushedTestMergeCommit, @@ -335,11 +333,11 @@ namespace Tgstation.Server.Host.Components.Deployment async databaseContext => { var fullJob = compileJob.Job; - compileJob.Job = new Models.Job(job.Id.Value); + compileJob.Job = new Models.Job(job.Require(x => x.Id)); var fullRevInfo = compileJob.RevisionInformation; compileJob.RevisionInformation = new Models.RevisionInformation { - Id = revInfo.Id, + Id = revInfo!.Id, }; databaseContext.Jobs.Attach(compileJob.Job); @@ -351,7 +349,7 @@ namespace Tgstation.Server.Host.Components.Deployment logger.LogTrace("Created CompileJob {compileJobId}", compileJob.Id); try { - var chatNotificationAction = currentChatCallback(null, compileJob.Output); + var chatNotificationAction = currentChatCallback!(null, compileJob.Output!); await compileJobConsumer.LoadCompileJob(compileJob, chatNotificationAction, cancellationToken); } catch @@ -370,11 +368,11 @@ namespace Tgstation.Server.Host.Components.Deployment } catch (Exception ex) { - await CleanupFailedCompile(compileJob, remoteDeploymentManager, ex); + await CleanupFailedCompile(compileJob, remoteDeploymentManager!, ex); throw; } - var commentsTask = remoteDeploymentManager.PostDeploymentComments( + var commentsTask = remoteDeploymentManager!.PostDeploymentComments( compileJob, activeCompileJob?.RevisionInformation, repositorySettings, @@ -401,7 +399,7 @@ namespace Tgstation.Server.Host.Components.Deployment { currentChatCallback?.Invoke( FormatExceptionForUsers(ex), - currentDreamMakerOutput); + currentDreamMakerOutput!); throw; } @@ -423,13 +421,13 @@ namespace Tgstation.Server.Host.Components.Deployment var previousCompileJobs = await databaseContext .CompileJobs .AsQueryable() - .Where(x => x.Job.Instance.Id == metadata.Id) + .Where(x => x.Job.Instance!.Id == metadata.Id) .OrderByDescending(x => x.Job.StoppedAt) .Take(10) .Select(x => new { - x.Job.StoppedAt, - x.Job.StartedAt, + StoppedAt = x.Job.StoppedAt!.Value, + StartedAt = x.Job.StartedAt!.Value, }) .ToListAsync(cancellationToken); @@ -438,7 +436,7 @@ namespace Tgstation.Server.Host.Components.Deployment { var totalSpan = TimeSpan.Zero; foreach (var previousCompileJob in previousCompileJobs) - totalSpan += previousCompileJob.StoppedAt.Value - previousCompileJob.StartedAt.Value; + totalSpan += previousCompileJob.StoppedAt - previousCompileJob.StartedAt; averageSpan = totalSpan / previousCompileJobs.Count; } @@ -501,7 +499,7 @@ namespace Tgstation.Server.Host.Components.Deployment compileJob, cancellationToken); - logger.LogTrace("Deployment will timeout at {timeoutTime}", DateTimeOffset.UtcNow + dreamMakerSettings.Timeout.Value); + logger.LogTrace("Deployment will timeout at {timeoutTime}", DateTimeOffset.UtcNow + dreamMakerSettings.Timeout!.Value); using var timeoutTokenSource = new CancellationTokenSource(dreamMakerSettings.Timeout.Value); var timeoutToken = timeoutTokenSource.Token; using (timeoutToken.Register(() => logger.LogWarning("Deployment timed out!"))) @@ -563,7 +561,7 @@ namespace Tgstation.Server.Host.Components.Deployment IRemoteDeploymentManager remoteDeploymentManager, CancellationToken cancellationToken) { - var outputDirectory = job.DirectoryName.ToString(); + var outputDirectory = job.DirectoryName!.Value.ToString(); logger.LogTrace("Compile output GUID: {dirGuid}", outputDirectory); try @@ -647,13 +645,13 @@ namespace Tgstation.Server.Host.Components.Deployment progressReporter.StageName = "Validating DMAPI"; await VerifyApi( - launchParameters.StartupTimeout.Value, - dreamMakerSettings.ApiValidationSecurityLevel.Value, + launchParameters.StartupTimeout!.Value, + dreamMakerSettings.ApiValidationSecurityLevel!.Value, job, engineLock, - dreamMakerSettings.ApiValidationPort.Value, - dreamMakerSettings.RequireDMApiValidation.Value, - launchParameters.LogOutput.Value, + dreamMakerSettings.ApiValidationPort!.Value, + dreamMakerSettings.RequireDMApiValidation!.Value, + launchParameters.LogOutput!.Value, cancellationToken); } catch (JobException) @@ -799,7 +797,7 @@ namespace Tgstation.Server.Host.Components.Deployment ApiValidationStatus validationStatus; await using (var provider = new TemporaryDmbProvider( - ioManager.ResolvePath(job.DirectoryName.ToString()), + ioManager.ResolvePath(job.DirectoryName!.Value.ToString()), job, engineLock.Version)) await using (var controller = await sessionControllerFactory.LaunchNew(provider, engineLock, launchParameters, true, cancellationToken)) @@ -859,7 +857,7 @@ namespace Tgstation.Server.Host.Components.Deployment await using var dm = processExecutor.LaunchProcess( engineLock.CompilerExePath, ioManager.ResolvePath( - job.DirectoryName.ToString()), + job.DirectoryName!.Value.ToString()), arguments, readStandardHandles: true, noShellExecute: true); @@ -889,14 +887,15 @@ namespace Tgstation.Server.Host.Components.Deployment async ValueTask ModifyDme(Models.CompileJob job, CancellationToken cancellationToken) { var dmeFileName = String.Join('.', job.DmeName, DmeExtension); - var dmePath = ioManager.ConcatPath(job.DirectoryName.ToString(), dmeFileName); + var stringDirectoryName = job.DirectoryName!.Value.ToString(); + var dmePath = ioManager.ConcatPath(stringDirectoryName, dmeFileName); var dmeReadTask = ioManager.ReadAllBytes(dmePath, cancellationToken); var dmeModificationsTask = configuration.CopyDMFilesTo( dmeFileName, ioManager.ResolvePath( ioManager.ConcatPath( - job.DirectoryName.ToString(), + stringDirectoryName, ioManager.GetDirectoryName(dmeFileName))), cancellationToken); @@ -955,7 +954,7 @@ namespace Tgstation.Server.Host.Components.Deployment async ValueTask CleanDir() { logger.LogTrace("Cleaning compile directory..."); - var jobPath = job.DirectoryName.ToString(); + var jobPath = job.DirectoryName!.Value.ToString(); try { // DCT: None available diff --git a/src/Tgstation.Server.Host/Components/Deployment/Remote/BaseRemoteDeploymentManager.cs b/src/Tgstation.Server.Host/Components/Deployment/Remote/BaseRemoteDeploymentManager.cs index a2aea1401c..0f8c86732f 100644 --- a/src/Tgstation.Server.Host/Components/Deployment/Remote/BaseRemoteDeploymentManager.cs +++ b/src/Tgstation.Server.Host/Components/Deployment/Remote/BaseRemoteDeploymentManager.cs @@ -52,13 +52,18 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote /// public async ValueTask PostDeploymentComments( CompileJob compileJob, - RevisionInformation previousRevisionInformation, + RevisionInformation? previousRevisionInformation, RepositorySettings repositorySettings, - string repoOwner, - string repoName, + string? repoOwner, + string? repoName, CancellationToken cancellationToken) { - if (repositorySettings?.AccessToken == null) + ArgumentNullException.ThrowIfNull(compileJob); + ArgumentNullException.ThrowIfNull(repositorySettings); + ArgumentNullException.ThrowIfNull(repoOwner); + ArgumentNullException.ThrowIfNull(repoName); + + if (repositorySettings.AccessToken == null) return; var deployedRevisionInformation = compileJob.RevisionInformation; diff --git a/src/Tgstation.Server.Host/Components/Deployment/Remote/IRemoteDeploymentManager.cs b/src/Tgstation.Server.Host/Components/Deployment/Remote/IRemoteDeploymentManager.cs index e73f6a1063..d8017a6686 100644 --- a/src/Tgstation.Server.Host/Components/Deployment/Remote/IRemoteDeploymentManager.cs +++ b/src/Tgstation.Server.Host/Components/Deployment/Remote/IRemoteDeploymentManager.cs @@ -66,7 +66,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote /// Post deployment comments to the test merge ticket. /// /// The deployed . - /// The of the previous deployment. + /// The optional of the previous deployment. /// The . /// The remote repostiory owner. /// The remote repostiory name. @@ -74,10 +74,10 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote /// A representing the running operation. ValueTask PostDeploymentComments( CompileJob compileJob, - RevisionInformation previousRevisionInformation, + RevisionInformation? previousRevisionInformation, RepositorySettings repositorySettings, - string repoOwner, - string repoName, + string? repoOwner, + string? repoName, CancellationToken cancellationToken); ///