From 49ea66c29304c3d0271049b2a101161f259f0e04 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Tue, 10 Dec 2024 04:04:10 +0000 Subject: [PATCH] chore: release files extra fixes --- build.gradle | 53 +++++++++++++++++++++++++++++++++++++++++++ changelog-util.gradle | 5 ++++ discord.gradle | 29 ++++++++++------------- gradle.properties | 1 + settings.gradle | 1 + 5 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 changelog-util.gradle diff --git a/build.gradle b/build.gradle index 943ce577..f5945e60 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ buildscript { plugins { + id "com.modrinth.minotaur" version "2.+" id 'dev.s7a.gradle.minecraft.server' version '1.1.0' id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7' } @@ -51,6 +52,7 @@ allprojects { apply from: 'env-variables.gradle' +apply from: 'changelog-util.gradle' println("Branch ${ext.branch}${ext.shaRef} isRelease: '${ext.isRelease}'") @@ -195,5 +197,56 @@ idea { } } +modrinth { + token = System.getenv("MODRINTH_TOKEN") + projectId = project.modrinth_slug + versionType = "release" + uploadFile = jar + loaders = ["spigot"] + gameVersions = [ + "1.13", + "1.13.1", + "1.13.2", + "1.14", + "1.14.1", + "1.14.2", + "1.14.3", + "1.14.4", + "1.15", + "1.15.1", + "1.15.2", + "1.16", + "1.16.1", + "1.16.2", + "1.16.3", + "1.16.4", + "1.16.5", + "1.17", + "1.17.1", + "1.18", + "1.18.1", + "1.18.2", + "1.19", + "1.19.1", + "1.19.2", + "1.19.3", + "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" + ] + changelog = getReleaseChangelog() +} + + apply from: 'curse.gradle' apply from: 'discord.gradle' diff --git a/changelog-util.gradle b/changelog-util.gradle new file mode 100644 index 00000000..873a14af --- /dev/null +++ b/changelog-util.gradle @@ -0,0 +1,5 @@ +ext.getReleaseChangelog = { + def changelogFile = file('CHANGELOG.md') + def changelog = "## [${changelogFile.text.split('\n## \\[')[1]}\n\n" // ${project.github}/blob/${branch}/CHANGELOG.md + return changelog +} \ No newline at end of file diff --git a/discord.gradle b/discord.gradle index d4d9deb0..6e7e6168 100644 --- a/discord.gradle +++ b/discord.gradle @@ -16,22 +16,16 @@ buildscript { } apply from: 'env-variables.gradle' - -def getReleaseChangelog() { - def changelogFile = file('CHANGELOG.md') - def changelog = "## [${changelogFile.text.split('\n## \\[')[1]}\n\n"// ${project.github}/blob/${branch}/CHANGELOG.md - return changelog; -} +apply from: 'changelog-util.gradle' task discordupload { dependsOn(jar) doLast { - String discordWebhook = System.getenv("DISCORD_WEBHOOK") + String discordWebhook = isRelease ? System.getenv("DISCORD_RELEASE_WEBHOOK") : System.getenv("DISCORD_WEBHOOK") if(discordWebhook != null) { - println("Logging Into Discord") CloseableHttpClient httpClient = HttpClients.createDefault() HttpPost uploadFile = new HttpPost(discordWebhook) @@ -43,19 +37,16 @@ task discordupload { def maxLength = 2000 def content = "New release build\n" + - "```markdown\n" + - "${getReleaseChangelog()}\n" + - "```" + "${getReleaseChangelog()}\n" if (content.length() > maxLength) { - def trimmedChangelog = getReleaseChangelog().take(maxLength - 15) // Reserve space for ending message - content = "New release build\n" + - "```markdown\n" + - "${trimmedChangelog}\n" + - "``` [Truncated]" + def afterMessage = "[See more on GitHub]" + content = "${content.take(maxLength - afterMessage.length() - 1)}\n" + + "${afterMessage}" + } - builder.addTextBody("content", content) + builder.addTextBody("content", content, ContentType.create("text/plain", "UTF-8")) } builder.addBinaryBody("file", file(jar.archiveFile).newInputStream(), ContentType.APPLICATION_OCTET_STREAM, jar.archiveName) @@ -66,6 +57,10 @@ task discordupload { CloseableHttpResponse response = httpClient.execute(uploadFile) response.getEntity() + if(response.getStatusLine().getStatusCode() != 200) { + throw new RuntimeException("Failed to post build to discord") + } + println("Posted build") } else { diff --git a/gradle.properties b/gradle.properties index f88c8660..52313959 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,3 +5,4 @@ version=1.0.0 github=https://github.com/sekwah41/Advanced-Portals curse_project_id=86001 +modrinth_slug=advanced-portals diff --git a/settings.gradle b/settings.gradle index 4a36b19d..e9656cff 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,3 +10,4 @@ include 'spigot' // Proxies include 'velocity' include 'bungee' +