From 87e0afda372b6423cce009992e723d94bf1a38c3 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 3 Dec 2023 00:25:17 +0000 Subject: [PATCH] Add modrinth and github publishing to buildscript --- .gitignore | 2 ++ build.gradle | 27 +++++++++++++++++++++++++-- gradle.properties | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d1064dd86..05961ed81 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ bin/ run/ logs/ + +/changelog.txt diff --git a/build.gradle b/build.gradle index c8f4fdc2b..aa7c0d138 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'fabric-loom' version '1.4-SNAPSHOT' id 'maven-publish' id 'com.modrinth.minotaur' version '2.+' + id 'com.github.breadmoirai.github-release' version '2.4.1' } sourceCompatibility = JavaVersion.VERSION_17 @@ -86,16 +87,38 @@ jar { from "LICENSE" } +// read the changelog from the changelog.txt file, make sure the changelog is recent to avoid accidentally using the previous version's changelog. +def changelogFile = file('changelog.txt') +def changelogText = changelogFile.exists() && System.currentTimeMillis() - changelogFile.lastModified() <= 1000 * 60 * 60 ? + changelogFile.readLines('UTF-8').join('\n') : '' + modrinth { token = project.hasProperty('modrinthKey') ? project.modrinthKey : System.getenv("MODRINTH_TOKEN") projectId = 'clientcommands' // This can be the project ID or the slug. Either will work! uploadFile = remapJar - gameVersions = project.minecraft_version_list.split('\\s*,\\s*').toList() - loaders = ['fabric', 'quilt'] + gameVersions.set(project.minecraft_version_list.split('\\s*,\\s*').toList()) + loaders.set(['fabric', 'quilt']) + changelog = changelogText dependencies { required.project 'fabric-api' } } +tasks.modrinth.onlyIf { + !changelogText.isBlank() +} + +githubRelease { + token(project.hasProperty('githubKey') ? project.githubKey : System.getenv("GITHUB_TOKEN")) + owner 'Earthcomputer' + repo "clientcommands" + targetCommitish 'fabric' + releaseName "Version ${project.version} for Minecraft ${project.minecraft_version_list_presentable}" + body changelogText + releaseAssets remapJar.outputs +} +tasks.githubRelease.onlyIf { + !changelogText.isBlank() +} publishing { publications { diff --git a/gradle.properties b/gradle.properties index 8edbee7e4..2cb5ac234 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,7 @@ org.gradle.jvmargs=-Xmx2G minecraft_version=1.20.2 minecraft_version_dependency=1.20.2 minecraft_version_list=1.20.2 + minecraft_version_list_presentable=1.20.2 yarn_mappings=1.20.2+build.4 loader_version=0.15.0