From 347a61abb62105d7539086964e2d55302df69c24 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Mon, 24 Apr 2023 19:23:17 -0400 Subject: [PATCH 1/4] Add changelog generation --- .gitignore | 3 +++ build.gradle | 21 ++++++++++++++++++++- gradle/changelog.mustache | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gradle/changelog.mustache diff --git a/.gitignore b/.gitignore index a3951e7f..c4d1b6c5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ libs media classes/ +# Changelog +CHANGELOG.md + # Created by https://www.gitignore.io/api/gradle,intellij,eclipse,windows,osx,linux ### Gradle ### diff --git a/build.gradle b/build.gradle index 807e3777..32a683c6 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id "maven-publish" id 'com.matthewprenger.cursegradle' version '1.4.0' id 'com.palantir.git-version' version '1.0.0' + id 'se.bjurr.gitchangelog.git-changelog-gradle-plugin' version '1.79.0' } sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 @@ -120,6 +121,22 @@ tasks.withType(JavaCompile) { */ } +task generateChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) { + def details = versionDetails(); + if(details.commitDistance > 0) { + fromRef = details.lastTag; + } else { + def secondLastTagCmd = "git describe --abbrev=0 " + details.lastTag + "^" + def secondLastTag = secondLastTagCmd.execute().text.trim() + fromRef = secondLastTag; + } + + file = new File("CHANGELOG.md"); + def otherTemplateContent = new File('gradle/changelog.mustache').getText('UTF-8'); + templateContent = "## Changes since " + fromRef + "\n" + otherTemplateContent; + toCommit = "HEAD"; +} + java { // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task // if it is present. @@ -165,7 +182,7 @@ curseforge { apiKey = System.getenv("CURSEFORGE_TOKEN") project { id = "790626" - changelog = '[Changelog is not currently available]' + changelog = file('./CHANGELOG.md') changelogType = "markdown" releaseType = "release" addGameVersion "Forge" @@ -174,3 +191,5 @@ curseforge { } } } + +tasks.curseforge.dependsOn(":generateChangelog") diff --git a/gradle/changelog.mustache b/gradle/changelog.mustache new file mode 100644 index 00000000..5f0337f1 --- /dev/null +++ b/gradle/changelog.mustache @@ -0,0 +1,3 @@ +{{#commits}} + * [{{{messageTitle}}}](https://github.com/embeddedt/ModernFix/commit/{{hashFull}}) - {{{authorName}}} +{{/commits}} \ No newline at end of file From f0323d409a3740b5835d701077e36224863a761c Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Mon, 24 Apr 2023 19:34:27 -0400 Subject: [PATCH 2/4] Add Modrinth uploading logic --- build.gradle | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/build.gradle b/build.gradle index 32a683c6..a32eb100 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,7 @@ plugins { id 'com.matthewprenger.cursegradle' version '1.4.0' id 'com.palantir.git-version' version '1.0.0' id 'se.bjurr.gitchangelog.git-changelog-gradle-plugin' version '1.79.0' + id "com.modrinth.minotaur" version "2.+" } sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 @@ -192,4 +193,24 @@ curseforge { } } +modrinth { + token = System.getenv("MODRINTH_TOKEN") + projectId = "modernfix" // This can be the project ID or the slug. Either will work! + versionType = "release" // This is the default -- can also be `beta` or `alpha` + uploadFile = remapJar + gameVersions = [minecraft_version] + loaders = ["forge"] + File changelogFile = new File("./CHANGELOG.md") + if (changelogFile.exists()) + changelog = changelogFile.getText('UTF-8') + else + changelog = "No changelog was provided." +} + tasks.curseforge.dependsOn(":generateChangelog") +tasks.modrinth.dependsOn(":generateChangelog") + +task publishToModSites { + publishToModSites.dependsOn modrinth + publishToModSites.dependsOn curseforge +} \ No newline at end of file From 3922e54b11b9a6e5e024f79d71cdc1c24557ac5a Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Mon, 24 Apr 2023 19:53:58 -0400 Subject: [PATCH 3/4] Tweak changelog gen logic --- build.gradle | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index a32eb100..c4d6480f 100644 --- a/build.gradle +++ b/build.gradle @@ -200,17 +200,24 @@ modrinth { uploadFile = remapJar gameVersions = [minecraft_version] loaders = ["forge"] - File changelogFile = new File("./CHANGELOG.md") - if (changelogFile.exists()) - changelog = changelogFile.getText('UTF-8') - else - changelog = "No changelog was provided." + changelog.set(provider { file("./CHANGELOG.md").getText('UTF-8') }) } +tasks.register('checkCleanTag') { + doLast { + def details = versionDetails() + if (!details.isCleanTag || versionDetails().commitDistance != 0) { + throw new GradleException('Not a clean tree.') + } + } +} + +tasks.curseforge.dependsOn(":checkCleanTag") tasks.curseforge.dependsOn(":generateChangelog") +tasks.modrinth.dependsOn(":checkCleanTag") tasks.modrinth.dependsOn(":generateChangelog") -task publishToModSites { - publishToModSites.dependsOn modrinth - publishToModSites.dependsOn curseforge +tasks.register('publishToModSites') { + publishToModSites.dependsOn(tasks.modrinth) + publishToModSites.dependsOn(tasks.curseforge) } \ No newline at end of file From 35c0c760f006bda6d165b04985862569a34ec25b Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Mon, 24 Apr 2023 19:59:02 -0400 Subject: [PATCH 4/4] Exclude merge commits from changelog --- gradle/changelog.mustache | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gradle/changelog.mustache b/gradle/changelog.mustache index 5f0337f1..b3175640 100644 --- a/gradle/changelog.mustache +++ b/gradle/changelog.mustache @@ -1,3 +1,5 @@ {{#commits}} +{{#ifMatches messageTitle "^(?!Merge).*"}} * [{{{messageTitle}}}](https://github.com/embeddedt/ModernFix/commit/{{hashFull}}) - {{{authorName}}} +{{/ifMatches}} {{/commits}} \ No newline at end of file