diff --git a/src/Tgstation.Server.Api/Models/ErrorCode.cs b/src/Tgstation.Server.Api/Models/ErrorCode.cs
index 7b34459278..1f8141301d 100644
--- a/src/Tgstation.Server.Api/Models/ErrorCode.cs
+++ b/src/Tgstation.Server.Api/Models/ErrorCode.cs
@@ -483,5 +483,11 @@ namespace Tgstation.Server.Api.Models
///
[Description("Could not bind to requested DreamDaemon port! Is there another service running on that port?")]
DreamDaemonPortInUse,
+
+ ///
+ /// Failed to post GitHub comments, send chat message, or send TGS event.
+ ///
+ [Description("The deployment succeeded but one or more notification events failed!")]
+ PostDeployFailure,
}
}
\ No newline at end of file
diff --git a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs
index a4d858cf1c..a10d0cb2ef 100644
--- a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs
+++ b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs
@@ -651,6 +651,7 @@ namespace Tgstation.Server.Host.Components.Deployment
cancellationToken)
.ConfigureAwait(false);
+ var activeCompileJob = compileJobConsumer.LatestCompileJob();
try
{
await databaseContextFactory.UseContext(
@@ -691,19 +692,30 @@ namespace Tgstation.Server.Host.Components.Deployment
throw;
}
- // set the compile job revinfo back to the full tree, so that it may be used by this call
- compileJob.RevisionInformation = revInfo;
- await PostDeploymentComments(compileJob, repositorySettings, repoOwner, repoName).ConfigureAwait(false);
+ var commentsTask = PostDeploymentComments(
+ revInfo,
+ activeCompileJob?.RevisionInformation,
+ repositorySettings,
+ repoOwner,
+ repoName);
- await eventConsumer.HandleEvent(EventType.DeploymentComplete, null, cancellationToken).ConfigureAwait(false);
+ var eventTask = eventConsumer.HandleEvent(EventType.DeploymentComplete, null, cancellationToken);
- await chatManager.SendUpdateMessage(
+ var chatTask = chatManager.SendUpdateMessage(
String.Format(
CultureInfo.InvariantCulture,
"Deployment complete! Changes will be applied when DreamDaemon {0}.",
watchdog.Running ? "reboots" : "is launched"),
- cancellationToken)
- .ConfigureAwait(false);
+ cancellationToken);
+
+ try
+ {
+ await Task.WhenAll(commentsTask, eventTask, chatTask).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ throw new JobException(ErrorCode.PostDeployFailure, ex);
+ }
}
#pragma warning restore CA1506
@@ -785,13 +797,15 @@ namespace Tgstation.Server.Host.Components.Deployment
///
/// Post deployment GitHub comments.
///
- /// The deployed .
+ /// The deployed .
+ /// The of the previous deployment.
/// The .
/// The GitHub repostiory owner.
/// The GitHub repostiory name.
/// A representing the running operation.
async Task PostDeploymentComments(
- Models.CompileJob compileJob,
+ Models.RevisionInformation deployedRevisionInformation,
+ Models.RevisionInformation previousRevisionInformation,
Models.RepositorySettings repositorySettings,
string repoOwner,
string repoName)
@@ -799,18 +813,13 @@ namespace Tgstation.Server.Host.Components.Deployment
if (repositorySettings?.AccessToken == null)
return;
- // potential for commenting on a test merge change
- var outgoingCompileJob = compileJobConsumer.LatestCompileJob();
-
- if ((outgoingCompileJob != null && outgoingCompileJob.RevisionInformation.CommitSha == compileJob.RevisionInformation.CommitSha) || !repositorySettings.PostTestMergeComment.Value)
+ if ((previousRevisionInformation != null && previousRevisionInformation.CommitSha == previousRevisionInformation.CommitSha)
+ || !repositorySettings.PostTestMergeComment.Value)
return;
- outgoingCompileJob ??= new Models.CompileJob
+ previousRevisionInformation = new Models.RevisionInformation
{
- RevisionInformation = new Models.RevisionInformation
- {
- ActiveTestMerges = new List()
- }
+ ActiveTestMerges = new List()
};
var gitHubClient = gitHubClientFactory.CreateClient(repositorySettings.AccessToken);
@@ -836,38 +845,32 @@ namespace Tgstation.Server.Host.Components.Deployment
testMerge.Comment != null ? String.Format(CultureInfo.InvariantCulture, "{0}{0}##### Comment{0}{1}", Environment.NewLine, testMerge.Comment) : String.Empty,
updated ? "Updated" : "Deployed",
metadata.Name,
- compileJob.RevisionInformation.OriginCommitSha,
- compileJob.RevisionInformation.CommitSha);
+ deployedRevisionInformation.OriginCommitSha,
+ deployedRevisionInformation.CommitSha);
// added prs
- foreach (var I in compileJob
- .RevisionInformation
+ foreach (var I in deployedRevisionInformation
.ActiveTestMerges
.Select(x => x.TestMerge)
- .Where(x => !outgoingCompileJob
- .RevisionInformation
+ .Where(x => !previousRevisionInformation
.ActiveTestMerges
.Any(y => y.TestMerge.Number == x.Number)))
tasks.Add(CommentOnPR(I.Number, FormatTestMerge(I, false)));
// removed prs
- foreach (var I in outgoingCompileJob
- .RevisionInformation
+ foreach (var I in previousRevisionInformation
.ActiveTestMerges
.Select(x => x.TestMerge)
- .Where(x => !compileJob
- .RevisionInformation
+ .Where(x => !deployedRevisionInformation
.ActiveTestMerges
.Any(y => y.TestMerge.Number == x.Number)))
tasks.Add(CommentOnPR(I.Number, "#### Test Merge Removed"));
// updated prs
- foreach (var I in compileJob
- .RevisionInformation
+ foreach (var I in deployedRevisionInformation
.ActiveTestMerges
.Select(x => x.TestMerge)
- .Where(x => outgoingCompileJob
- .RevisionInformation
+ .Where(x => previousRevisionInformation
.ActiveTestMerges
.Any(y => y.TestMerge.Number == x.Number)))
tasks.Add(CommentOnPR(I.Number, FormatTestMerge(I, true)));