Skip to content

Commit

Permalink
Actually prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Ampflower committed Jan 16, 2024
1 parent c1fc620 commit 71e63fc
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 3 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
java
alias(libs.plugins.loom)
alias(libs.plugins.minotaur)
id("gay.ampflower.BuildPlugin")
}

Expand All @@ -10,6 +11,7 @@ val modrinthId: String by project
allprojects {
apply(plugin = "java")
apply(plugin = "gay.ampflower.BuildPlugin")
apply(plugin = rootProject.libs.plugins.minotaur.get().pluginId)
apply(plugin = rootProject.libs.plugins.loom.get().pluginId)

version = meta.globalVersion
Expand Down
9 changes: 8 additions & 1 deletion buildSrc/src/main/java/gay/ampflower/BuildPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import org.gradle.api.Project;
import org.gradle.api.artifacts.MinimalExternalModuleDependency;
import org.gradle.api.artifacts.VersionCatalogsExtension;
import org.gradle.api.artifacts.VersionConstraint;
import org.gradle.api.internal.catalog.AbstractExternalDependencyFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
* @author Ampflower
* @since 0.0.0
Expand Down Expand Up @@ -41,7 +44,11 @@ public void apply(final Project target) {
extensions.add("meta", new Meta(
version,
Util.mkVersion(version + "+mc." + minecraftVersion),
Util.mkChangelog(Properties.str(target, "github"))
Util.getVersionType(version),
Util.mkChangelog(Properties.str(target, "github")),
Util.getCompatibleVersions(libs, target)
));

logger.info("Got {}", extensions.findByName("meta"));
}
}
6 changes: 5 additions & 1 deletion buildSrc/src/main/java/gay/ampflower/Meta.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package gay.ampflower;

import java.util.List;

/**
* @author Ampflower
* @since 0.0.0
**/
public record Meta(
String projectVersion,
String globalVersion,
String changelog
String releaseType,
String changelog,
List<String> minecraftCompatible
) {
}
1 change: 1 addition & 0 deletions buildSrc/src/main/java/gay/ampflower/internal/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public final class Env {
public static final @Nullable String RunNumber = env("GITHUB_RUN_NUMBER");
public static final @Nullable String Reference = env("GITHUB_REF");
public static final @Nullable String Changelog = env("CHANGELOG");
public static final @Nullable String ReleaseOverride = env("RELEASE_OVERRIDE");

private Env() {}

Expand Down
71 changes: 71 additions & 0 deletions buildSrc/src/main/java/gay/ampflower/internal/Util.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
package gay.ampflower.internal;

import org.gradle.api.Project;
import org.gradle.api.artifacts.VersionCatalog;
import org.gradle.api.artifacts.VersionConstraint;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;

/**
* @author Ampflower
* @since 0.0.0
**/
public class Util {
private static final Logger logger = LoggerFactory.getLogger(Util.class);
public static String urlEncode(String str) {
return URLEncoder.encode(str, StandardCharsets.UTF_8);
}

public static String mkChangelog(String git) {
if(!isBlank(Env.Changelog)) {
logger.debug("Changelog found, returning {}", Env.Changelog);
return Env.Changelog;
}

if(git == null) {
logger.warn("Git repository not defined. Returning null.");
return null;
}

if(startsWith(Env.Reference, "refs/tags/")) {
final var host = VcsHost.find(git);

logger.warn("Changelog not found but tag reference was, returning link to {}{}{}",
git, host.release, urlEncode(Env.getTag()));

return "You may view the changelog at " + git + host.release + urlEncode(Env.getTag());
}

logger.warn("Changelog and reference not found, returning link to {}", git);
return "No changelog is available. Perhaps poke at " + git + " for a changelog?";
}

Expand All @@ -52,6 +67,62 @@ private static String getBranchForVersion() {
return ref.replace('/', '.');
}

public static List<String> getCompatibleVersions(VersionCatalog catalog, Project module) {
Optional<VersionConstraint> version;
switch (module.getName().toLowerCase()) {
case "neoforge":
version = catalog.findVersion("minecraft-neoforge-compatible");
logger.info("Testing Neoforge: {}", version);
if(version.isPresent()) break;
case "forge":
version = catalog.findVersion("minecraft-forge-compatible");
logger.info("Testing Forge: {}", version);
if(version.isPresent()) break;
case "quilt":
version = catalog.findVersion("minecraft-quilt-compatible");
logger.info("Testing Quilt: {}", version);
if(version.isPresent()) break;
case "fabric":
version = catalog.findVersion("minecraft-fabric-compatible");
logger.info("Testing Fabric: {}", version);
if(version.isPresent()) break;
default:
version = catalog.findVersion("minecraft-compatible");
logger.info("Testing default: {}", version);
}

if(version.isEmpty()) {
final var minecraft = catalog.findLibrary("minecraft").map(provider -> provider.get().getVersion());

if(minecraft.isPresent()) {
logger.warn("No marked compatible versions available for {}; compatible version will be marked as {}.",
module, minecraft.get());
return List.of(minecraft.get());
}

logger.warn("No marked compatible versions available for {}; compatible versions will not be marked.", module);
return List.of();
}

return List.of(version.get().getRequiredVersion().split(","));
}

public static String getVersionType(String version) {
if(!Util.isBlank(Env.ReleaseOverride)) {
return Env.ReleaseOverride;
}

if(version.contains("alpha")) {
return "alpha";
}

if(!Env.Release || version.indexOf('-') >= 0) {
return "beta";
}

return "release";
}

public static boolean isBlank(@Nullable String str) {
if(str == null) {
return true;
Expand Down
20 changes: 20 additions & 0 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
val xplat = project(":xplat")
val xplatMain = xplat.sourceSets.main.get()

val modrinthId: String by project

dependencies {
modImplementation(libs.bundles.fabric)
compileOnly(xplat)

// Probably will be replaced at some point with something better
val fapi = libs.versions.fabric.api.get()
include(fabricApi.module("fabric-api-base", fapi))
include(fabricApi.module("fabric-registry-sync-v0", fapi))
include(fabricApi.module("fabric-networking-api-v1", fapi))
}

tasks {
Expand All @@ -14,3 +22,15 @@ tasks {
from(xplatMain.resources)
}
}

modrinth {
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set(modrinthId)
versionType.set(meta.releaseType)
versionName.set("${meta.projectVersion} - Fabric ${libs.versions.minecraft.version.get()}")
versionNumber.set("${project.version}-fabric")
changelog.set(meta.changelog)
uploadFile.set(tasks.remapJar)
gameVersions.set(meta.minecraftCompatible)
loaders.addAll("fabric", "quilt")
}
14 changes: 14 additions & 0 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
val xplat = project(":xplat")
val xplatMain = xplat.sourceSets.main.get()

val modrinthId: String by project

dependencies {
forge(libs.forge.loader)
compileOnly(xplat)
Expand All @@ -14,3 +16,15 @@ tasks {
from(xplatMain.resources)
}
}

modrinth {
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set(modrinthId)
versionType.set(meta.releaseType)
versionName.set("${meta.projectVersion} - Forge ${libs.versions.minecraft.version.get()}")
versionNumber.set("${project.version}-Forge")
changelog.set(meta.changelog)
uploadFile.set(tasks.remapJar)
gameVersions.set(meta.minecraftCompatible)
loaders.addAll("forge", "neoforge")
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.0.0
version=0.0.0-rc.2

# Distribution
modrinthId=bSA7rnCt
Expand Down
2 changes: 2 additions & 0 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Minecraft
minecraft-version = "1.20.1"
minecraft-required = ">=1.20"
minecraft-forge-compatible = "1.20,1.20.1"
minecraft-fabric-compatible = "1.20,1.20.1"

yarn = "1.20.1+build.10"

Expand Down

0 comments on commit 71e63fc

Please sign in to comment.