Skip to content

Commit

Permalink
Automatic publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Jan 19, 2023
1 parent a88e9c9 commit 60623ae
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 8 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Expand Up @@ -35,10 +35,14 @@ jobs:
run: |
./gradlew clean build --stacktrace
# - name: Run FOSSA
# uses: fossa-contrib/fossa-action@v1
# with:
# fossa-api-key: 46711dc8ef0a8d57d06010c8148bb6ea
- name: upload to modrinth and curseforge
run: ./gradlew modrinth curseforge
if: github.ref == 'refs/heads/ver/1.18'
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_UPLOAD_TOKEN }}
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_API_TOKEN }}
GITHUB_EVENT_RAW_PATH: ${{ github.event_path }}
continue-on-error: true

- name: Upload Artifact
uses: actions/upload-artifact@v2
Expand Down
40 changes: 40 additions & 0 deletions build.gradle
Expand Up @@ -3,6 +3,8 @@ plugins {
id 'fabric-loom' version '0.11-SNAPSHOT' apply false
id 'io.github.juuxel.loom-quiltflower' version '1.6.0' apply false
id "me.champeau.jmh" version "0.6.6"
id 'com.modrinth.minotaur' version '2.+' apply false
id 'com.matthewprenger.cursegradle' version '1.4.0'
}

@SuppressWarnings('unused')
Expand Down Expand Up @@ -146,6 +148,7 @@ subprojects {

afterEvaluate {
logger.lifecycle("Version String: ${version}")
logger.lifecycle(com.ishland.c2me.gradle.ParseGItHubActionChangelog.getChangelog())
}

dependencies {
Expand All @@ -165,6 +168,43 @@ dependencies {
}
}

apply plugin: 'com.modrinth.minotaur'
modrinth {
token = System.getenv("MODRINTH_TOKEN") // This is the default. Remember to have the MODRINTH_TOKEN environment variable set or else this will fail, or set it to whatever you want - just make sure it stays private!
projectId = "c2me-fabric" // This can be the project ID or the slug. Either will work!
versionNumber = project.version + "+" + project.minecraft_version // You don't need to set this manually. Will fail if Modrinth has this version already
versionName = project.version + " devbuild for " + project.minecraft_version
versionType = "alpha" // This is the default -- can also be `beta` or `alpha`
uploadFile = remapJar // With Loom, this MUST be set to `remapJar` instead of `jar`!
gameVersions = [project.minecraft_version] // Must be an array, even with only one version
loaders = ["fabric"] // Must also be an array - no need to specify this if you're using Loom or ForgeGradle
changelog = com.ishland.c2me.gradle.ParseGItHubActionChangelog.getChangelog()
}

apply plugin: 'com.matthewprenger.cursegradle'
if (System.getenv("CURSEFORGE_TOKEN")) {
curseforge {
apiKey = System.getenv("CURSEFORGE_TOKEN")
project {
id = '533097'
changelogType = "markdown"
changelog = com.ishland.c2me.gradle.ParseGItHubActionChangelog.getChangelog()
releaseType = 'alpha'

addGameVersion project.minecraft_version
addGameVersion "Fabric"
addGameVersion "Java 17"

mainArtifact(remapJar) {
displayName = project.version + " devbuild for " + project.minecraft_version
}
}
options {
forgeGradleIntegration = false
}
}
}

loom {
runs {
server {
Expand Down
5 changes: 2 additions & 3 deletions buildSrc/build.gradle
Expand Up @@ -32,10 +32,9 @@ dependencies {
api "net.fabricmc:fabric-loader:0.11.6"
api 'net.fabricmc:access-widener:2.1.0'
api "org.apache.logging.log4j:log4j-core:2.14.1"
}

test {
useJUnitPlatform()
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation 'com.google.code.gson:gson:2.9.0'
}

gradlePlugin {
Expand Down
@@ -0,0 +1,40 @@
package com.ishland.c2me.gradle;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import java.nio.file.Files;
import java.nio.file.Path;

public class ParseGItHubActionChangelog {

public static String getChangelog() throws Throwable {
final String path = System.getenv("GITHUB_EVENT_RAW_PATH");
if (path == null || path.isBlank()) return "No changelog was specified. ";
final JsonObject jsonObject = new Gson().fromJson(Files.readString(Path.of(path)), JsonObject.class);

StringBuilder builder = new StringBuilder();
builder.append("This version is uploaded automatically by GitHub Actions. \n\n")
.append("Changelog: \n");
final JsonArray commits = jsonObject.getAsJsonArray("commits");
if (commits.isEmpty()) {
builder.append("No changes detected. \n");
} else {
for (JsonElement commit : commits) {
JsonObject object = commit.getAsJsonObject();
builder.append("- ");
builder.append('[').append(object.get("id").getAsString(), 0, 8).append(']')
.append('(').append(object.get("url").getAsString()).append(')');
builder.append(' ');
builder.append(object.get("message").getAsString().split("\n")[0]);
builder.append(" — ");
builder.append(object.get("author").getAsJsonObject().get("name").getAsString());
builder.append(" ").append('\n');
}
}
return builder.toString();
}

}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 60623ae

Please sign in to comment.