Skip to content

Commit 54c85cf

Browse files
committed
Add MS Teams webhook for failed builds and new stable releases
1 parent c27a1bb commit 54c85cf

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

build/Build.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using static Nuke.Common.Tools.Slack.SlackTasks;
2020
using Nuke.Common.Tools.Slack;
2121
using System.IO;
22+
using Nuke.Common.Tools.Teams;
2223

2324
[UnsetVisualStudioEnvironmentVariables]
2425
class Build : NukeBuild
@@ -53,8 +54,32 @@ class Build : NukeBuild
5354
[KeyVaultSecret("AntlrCalculatorDemo-WebDeployUsername")] string WebDeployUsername;
5455
[KeyVaultSecret("AntlrCalculatorDemo-WebDeployPassword")] string WebDeployPassword;
5556
[KeyVaultSecret] string GitHubAuthenticationToken;
57+
[KeyVaultSecret] readonly string DanglCiCdTeamsWebhookUrl;
5658
[Parameter] string AppServiceName = "antlr-calculator-demo";
5759

60+
protected override void OnTargetFailed(string target)
61+
{
62+
if (IsServerBuild)
63+
{
64+
SendTeamsMessage("Build Failed", $"Target {target} failed for Dangl.Calculator, " +
65+
$"Branch: {GitRepository.Branch}", true);
66+
}
67+
}
68+
69+
void SendTeamsMessage(string title, string message, bool isError)
70+
{
71+
if (!string.IsNullOrWhiteSpace(DanglCiCdTeamsWebhookUrl))
72+
{
73+
var themeColor = isError ? "f44336" : "00acc1";
74+
TeamsTasks
75+
.SendTeamsMessage(m => m
76+
.SetTitle(title)
77+
.SetText(message)
78+
.SetThemeColor(themeColor),
79+
DanglCiCdTeamsWebhookUrl);
80+
}
81+
}
82+
5883
Target Clean => _ => _
5984
.Executes(() =>
6085
{
@@ -93,6 +118,12 @@ class Build : NukeBuild
93118
: "next";
94119

95120
Npm($"publish --tag={npmTag}", distDirectory);
121+
122+
if (npmTag == "latest")
123+
{
124+
SendTeamsMessage("New Release", $"New release available for antlr-calculator: {GitVersion.NuGetVersion}", false);
125+
}
126+
96127
});
97128

98129
Target DeployDemo => _ => _

0 commit comments

Comments
 (0)