mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
ci: Use FancyVerteiler (#170)
* ci: Use FancyVerteiler for FD snapshot * Update configs * Revert some stuff * Use FancyVerteiler for all plugins * Fixes * Fix * Delete deployment tool
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("maven-publish")
|
||||
id("com.gradleup.shadow")
|
||||
}
|
||||
|
||||
group = "de.oliver"
|
||||
description = "Tool to deploy Minecraft plugins"
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://repo.fancyinnovations.com/releases")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("dev.masecla:Modrinth4J:2.2.0")
|
||||
|
||||
implementation("com.google.code.gson:gson:2.13.1")
|
||||
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||
implementation("org.jetbrains:annotations:26.0.2")
|
||||
|
||||
implementation("de.oliver.FancyAnalytics:java-sdk:0.0.5")
|
||||
implementation("de.oliver.FancyAnalytics:logger:0.0.8")
|
||||
}
|
||||
|
||||
tasks {
|
||||
jar {
|
||||
manifest {
|
||||
attributes["Main-Class"] = "de.oliver.deployment.Main"
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveClassifier.set("")
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
|
||||
|
||||
// Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable.
|
||||
// See https://openjdk.java.net/jeps/247 for more information.
|
||||
options.release.set(21)
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
|
||||
}
|
||||
processResources {
|
||||
filteringCharset = Charsets.UTF_8.name() // We want UTF-8 for everything
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"project_name": "FancyHolograms",
|
||||
"project_id": "fancyholograms",
|
||||
"plugin_jar_path": "../../../plugins/fancyholograms/build/libs/FancyHolograms-*.jar",
|
||||
"changelog_path": "../../../plugins/fancyholograms/CHANGELOG.md",
|
||||
"version": "3.0.0",
|
||||
"supported_versions":[
|
||||
"1.19.4",
|
||||
"1.20",
|
||||
"1.20.1",
|
||||
"1.20.2",
|
||||
"1.20.3",
|
||||
"1.20.4",
|
||||
"1.20.5",
|
||||
"1.20.6",
|
||||
"1.21",
|
||||
"1.21.1",
|
||||
"1.21.2",
|
||||
"1.21.3",
|
||||
"1.21.4"
|
||||
],
|
||||
"channel": "release",
|
||||
"loaders": [
|
||||
"paper",
|
||||
"folia"
|
||||
],
|
||||
"featured": true
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package de.oliver.deployment;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public record Configuration(
|
||||
@SerializedName("project_name") String projectName,
|
||||
@SerializedName("project_id") String projectID,
|
||||
@SerializedName("plugin_jar_path") String pluginJarPath,
|
||||
@SerializedName("changelog_path") String changeLogPath,
|
||||
@SerializedName("version_path") String versionPath,
|
||||
@SerializedName("supported_versions") String[] supportedVersions,
|
||||
String channel,
|
||||
@SerializedName("loaders") String[] loaders,
|
||||
boolean featured
|
||||
) {
|
||||
|
||||
public String readVersion() {
|
||||
try {
|
||||
return Files.readString(Path.of(versionPath));
|
||||
} catch (IOException e) {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package de.oliver.deployment;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import de.oliver.deployment.git.GitService;
|
||||
import de.oliver.deployment.modrinth.ModrinthService;
|
||||
import de.oliver.deployment.notification.DiscordWebhook;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length < 2) {
|
||||
System.err.println("Usage: java -jar deployment.jar <platform> <config_file path> [send_notification]");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
String platform = args[0];
|
||||
|
||||
String configFilePath = args[1];
|
||||
String configData = Files.readString(Path.of(configFilePath));
|
||||
Configuration configuration = GSON.fromJson(configData, Configuration.class);
|
||||
|
||||
boolean sendNotification = args.length > 2 && Boolean.parseBoolean(args[2]);
|
||||
|
||||
if (platform.equalsIgnoreCase("modrinth")) {
|
||||
deployToModrinth(configuration);
|
||||
}
|
||||
|
||||
if (sendNotification) {
|
||||
sendDiscordNotification(configuration);
|
||||
System.out.println("Deployment completed and notification sent.");
|
||||
} else {
|
||||
System.out.println("Deployment completed without sending notification.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void deployToModrinth(Configuration configuration) {
|
||||
String modrinthApiKey = System.getenv("MODRINTH_API_KEY");
|
||||
ModrinthService modrinthService = new ModrinthService(modrinthApiKey);
|
||||
try {
|
||||
modrinthService.deployPlugin(configuration);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendDiscordNotification(Configuration configuration) {
|
||||
String discordWebhookUrl = System.getenv("DISCORD_WEBHOOK_URL");
|
||||
if (discordWebhookUrl != null) {
|
||||
DiscordWebhook.Data data = new DiscordWebhook.Data("Deployment completed", List.of(
|
||||
new DiscordWebhook.Data.Embed(
|
||||
"New version of " + configuration.projectName(),
|
||||
"""
|
||||
**Version:** %s
|
||||
**Channel:** %s
|
||||
**Commit:** [%s](https://github.com/FancyMcPlugins/fancyplugins/commit/%s)
|
||||
**Download:** %s
|
||||
""".formatted(
|
||||
configuration.readVersion(),
|
||||
configuration.channel(),
|
||||
GitService.getCommitHash().substring(0, 7),
|
||||
GitService.getCommitHash(),
|
||||
"https://modrinth.com/plugin/" + configuration.projectName() + "/version/" + configuration.readVersion()),
|
||||
|
||||
0x00FF00
|
||||
)
|
||||
));
|
||||
DiscordWebhook discordWebhook = new DiscordWebhook();
|
||||
discordWebhook.sendWebhook(discordWebhookUrl, data);
|
||||
} else {
|
||||
System.out.println("Discord webhook URL not set. Skipping notification.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package de.oliver.deployment.git;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GitService {
|
||||
|
||||
public static String getCommitHash() {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("git", "rev-parse", "HEAD");
|
||||
processBuilder.redirectErrorStream(true);
|
||||
processBuilder.directory(new java.io.File("."));
|
||||
|
||||
try {
|
||||
Process process = processBuilder.start();
|
||||
return new String(process.getInputStream().readAllBytes()).trim();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
public static String getCommitMessage() {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("git", "log", "-1", "--pretty=%B");
|
||||
processBuilder.redirectErrorStream(true);
|
||||
processBuilder.directory(new java.io.File("."));
|
||||
|
||||
try {
|
||||
Process process = processBuilder.start();
|
||||
return new String(process.getInputStream().readAllBytes()).trim();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package de.oliver.deployment.modrinth;
|
||||
|
||||
import de.oliver.deployment.Configuration;
|
||||
import de.oliver.deployment.git.GitService;
|
||||
import masecla.modrinth4j.client.agent.UserAgent;
|
||||
import masecla.modrinth4j.endpoints.version.CreateVersion;
|
||||
import masecla.modrinth4j.main.ModrinthAPI;
|
||||
import masecla.modrinth4j.model.version.ProjectVersion;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ModrinthService {
|
||||
|
||||
private final ModrinthAPI api;
|
||||
|
||||
public ModrinthService(String apiKey) {
|
||||
this.api = ModrinthAPI.rateLimited(
|
||||
UserAgent.builder()
|
||||
.authorUsername("Oliver")
|
||||
.contact("oliver@fancyinnovations.com")
|
||||
.build(),
|
||||
apiKey
|
||||
);
|
||||
}
|
||||
|
||||
public void deployPlugin(Configuration config) throws IOException {
|
||||
String changelog = Files.readString(Path.of(config.changeLogPath()));
|
||||
changelog = changelog.replaceAll("%COMMIT_HASH%", GitService.getCommitHash());
|
||||
changelog = changelog.replaceAll("%COMMIT_MESSAGE%", GitService.getCommitMessage());
|
||||
|
||||
String version = config.readVersion();
|
||||
|
||||
String pluginJarPath = config.pluginJarPath().replace("%VERSION%", version);
|
||||
File pluginFile = new File(pluginJarPath);
|
||||
|
||||
InputStream pluginJarFileStream = Files.newInputStream(pluginFile.toPath());
|
||||
|
||||
CreateVersion.CreateVersionRequest request = new CreateVersion.CreateVersionRequest(
|
||||
version,
|
||||
version,
|
||||
changelog,
|
||||
new ArrayList<>(),
|
||||
Arrays.asList(config.supportedVersions()),
|
||||
ProjectVersion.VersionType.valueOf(config.channel()),
|
||||
Arrays.asList(config.loaders()),
|
||||
config.featured(),
|
||||
config.projectID(),
|
||||
pluginJarPath,
|
||||
List.of(pluginFile.getName()),
|
||||
List.of(pluginJarFileStream)
|
||||
);
|
||||
|
||||
System.out.println("Creating version: " + request);
|
||||
|
||||
CompletableFuture<ProjectVersion> resp = api.versions().createProjectVersion(request);
|
||||
ProjectVersion createdVersion = resp.join();
|
||||
|
||||
System.out.println("Version created: " + createdVersion);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package de.oliver.deployment.notification;
|
||||
|
||||
import de.oliver.fancyanalytics.sdk.utils.HttpRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordWebhook {
|
||||
|
||||
public void sendWebhook(String webhookUrl, Data data) {
|
||||
HttpRequest request = new HttpRequest(webhookUrl)
|
||||
.withMethod("POST")
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withBody(data);
|
||||
|
||||
try {
|
||||
HttpResponse<String> resp = request.send();
|
||||
if (resp.statusCode() != 204) {
|
||||
System.out.println("Failed to send message with discord webhook: " + resp.body());
|
||||
}
|
||||
} catch (URISyntaxException | IOException | InterruptedException e) {
|
||||
System.out.println("Failed to send webhook");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public record Data(String content, List<Embed> embeds) {
|
||||
|
||||
public record Embed(String title, String description, int color) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user