Skip to content

Commit ad4b450

Browse files
deployment: Add discord webhook notification
1 parent 993cd17 commit ad4b450

11 files changed

Lines changed: 82 additions & 1 deletion

File tree

plugins/fancyholograms-v2/release_deployment_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"project_name": "FancyHolograms",
23
"project_id": "5QNgOj66",
34
"plugin_jar_path": "../../../../plugins/fancyholograms-v2/build/libs/FancyHolograms-%VERSION%.jar",
45
"changelog_path": "../../../../plugins/fancyholograms-v2/CHANGELOG.md",

plugins/fancyholograms-v2/snapshot_deployment_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"project_name": "FancyHolograms",
23
"project_id": "5QNgOj66",
34
"plugin_jar_path": "../../../../plugins/fancyholograms-v2/build/libs/FancyHolograms-%VERSION%.jar",
45
"changelog_path": "../../../../plugins/fancyholograms-v2/CHANGELOG-SNAPSHOT.md",

plugins/fancyholograms/release_deployment_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"project_name": "FancyHolograms",
23
"project_id": "5QNgOj66",
34
"plugin_jar_path": "../../../../plugins/fancyholograms/build/libs/FancyHolograms-%VERSION%.jar",
45
"changelog_path": "../../../../plugins/fancyholograms/CHANGELOG.md",

plugins/fancyholograms/snapshot_deployment_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"project_name": "FancyHolograms",
23
"project_id": "5QNgOj66",
34
"plugin_jar_path": "../../../../plugins/fancyholograms/build/libs/FancyHolograms-%VERSION%.jar",
45
"changelog_path": "../../../../plugins/fancyholograms/CHANGELOG-SNAPSHOT.md",

plugins/fancynpcs/release_deployment_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"project_name": "FancyNpcs",
23
"project_id": "EeyAn23L",
34
"plugin_jar_path": "../../../../plugins/fancynpcs/build/libs/FancyNpcs-%VERSION%.jar",
45
"changelog_path": "../../../../plugins/fancynpcs/CHANGELOG.md",

plugins/fancynpcs/snapshot_deployment_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"project_name": "FancyNpcs",
23
"project_id": "EeyAn23L",
34
"plugin_jar_path": "../../../../plugins/fancynpcs/build/libs/FancyNpcs-%VERSION%.jar",
45
"changelog_path": "../../../../plugins/fancynpcs/CHANGELOG-SNAPSHOT.md",

tools/deployment/example-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"project_name": "FancyHolograms",
23
"project_id": "fancyholograms",
34
"plugin_jar_path": "../../../plugins/fancyholograms/build/libs/FancyHolograms-*.jar",
45
"changelog_path": "../../../plugins/fancyholograms/CHANGELOG.md",

tools/deployment/src/main/java/de/oliver/deployment/Configuration.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import com.google.gson.annotations.SerializedName;
44

5+
import java.io.IOException;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
59
public record Configuration(
10+
@SerializedName("project_name") String projectName,
611
@SerializedName("project_id") String projectID,
712
@SerializedName("plugin_jar_path") String pluginJarPath,
813
@SerializedName("changelog_path") String changeLogPath,
@@ -12,4 +17,13 @@ public record Configuration(
1217
@SerializedName("loaders") String[] loaders,
1318
boolean featured
1419
) {
20+
21+
public String readVersion() {
22+
try {
23+
return Files.readString(Path.of(versionPath));
24+
} catch (IOException e) {
25+
return "unknown";
26+
}
27+
}
28+
1529
}

tools/deployment/src/main/java/de/oliver/deployment/Main.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package de.oliver.deployment;
22

33
import com.google.gson.Gson;
4+
import de.oliver.deployment.git.GitService;
45
import de.oliver.deployment.modrinth.ModrinthService;
6+
import de.oliver.deployment.notification.DiscordWebhook;
57

68
import java.io.IOException;
79
import java.nio.file.Files;
810
import java.nio.file.Path;
11+
import java.util.List;
912

1013
public class Main {
1114

@@ -24,6 +27,28 @@ public static void main(String[] args) throws IOException {
2427
e.printStackTrace();
2528
}
2629

30+
String discordWebhookUrl = System.getenv("DISCORD_WEBHOOK_URL");
31+
if (discordWebhookUrl != null) {
32+
DiscordWebhook.Data data = new DiscordWebhook.Data("Deployment completed", List.of(
33+
new DiscordWebhook.Data.Embed(
34+
"New version of "+configuration.projectName(),
35+
"""
36+
**Version:** %s
37+
**Commit:** %s
38+
**Download:** %s
39+
""".formatted(
40+
configuration.readVersion(),
41+
GitService.getCommitHash(),
42+
"https://modrinth.com/plugin/"+configuration.projectName()+"/versions/"+configuration.readVersion()),
43+
0x00FF00
44+
)
45+
));
46+
DiscordWebhook discordWebhook = new DiscordWebhook();
47+
discordWebhook.sendWebhook(discordWebhookUrl, data);
48+
} else {
49+
System.out.println("Discord webhook URL not set. Skipping notification.");
50+
}
51+
2752
}
2853

2954
}

tools/deployment/src/main/java/de/oliver/deployment/modrinth/ModrinthService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void deployPlugin(Configuration config) throws IOException {
3636
changelog = changelog.replaceAll("%COMMIT_HASH%", GitService.getCommitHash());
3737
changelog = changelog.replaceAll("%COMMIT_MESSAGE%", GitService.getCommitMessage());
3838

39-
String version = Files.readString(Path.of(config.versionPath()));
39+
String version = config.readVersion();
4040

4141
String pluginJarPath = config.pluginJarPath().replace("%VERSION%", version);
4242
File pluginFile = new File(pluginJarPath);

0 commit comments

Comments
 (0)