mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-10-25 20:22:22 +00:00
Ignore additional tags when deriving the mod version (#2219)
This commit is contained in:
1 parent
12857006c6
commit
b49d37d827
7 files changed
+89
-11
No files matched your search
@@ -6,6 +6,8 @@ plugins {
|
||||
id("com.gtnewhorizons.gtnhconvention")
|
||||
}
|
||||
|
||||
apply(from = "gradle/mod-version.gradle.kts")
|
||||
|
||||
val lwjglDebug = false
|
||||
val gpuHud = false
|
||||
val renderdoc = false
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
# LOCAL to test local config updates.
|
||||
gtnh.settings.blowdryerTag = 0.2.2
|
||||
|
||||
# See mod-version-gradle.kts
|
||||
gtnh.modules.gitVersion = false
|
||||
|
||||
# Human-readable mod name, available for mcmod.info population.
|
||||
modName = Angelica
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// Replaces GTNHGradle's GitVersionModule (gtnh.modules.gitVersion = false): same version format, but only
|
||||
// x.y.z[-suffix] tags count, so additional tags (moltenvk-v*, tracy-v*) on master never become the mod version.
|
||||
|
||||
fun git(vararg args: String): String? = try {
|
||||
val exec = providers.exec {
|
||||
commandLine("git", *args)
|
||||
workingDir = rootDir
|
||||
isIgnoreExitValue = true
|
||||
}
|
||||
if (exec.result.get().exitValue == 0) exec.standardOutput.asText.get().trim() else null
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
fun gitVersion(): String {
|
||||
val described = git("describe", "--tags", "--long", "--first-parent", "--abbrev=7", "--match=[0-9]*.[0-9]*.[0-9]*", "HEAD")
|
||||
val match = described?.let { Regex("(.*)-([0-9]+)-g[0-9a-f]+").matchEntire(it) }
|
||||
val tag = match?.groupValues?.get(1)
|
||||
val distance = match?.groupValues?.get(2)?.toInt() ?: 0
|
||||
val hash = git("rev-parse", "HEAD")?.take(10)?.ifEmpty { null }
|
||||
val base = tag ?: hash
|
||||
if (base == null) {
|
||||
logger.error("No git repository found; set the VERSION environment variable to version this build.")
|
||||
return "NO-GIT-TAG-SET"
|
||||
}
|
||||
val dirty = !git("status", "--porcelain").isNullOrEmpty()
|
||||
val branch = (git("branch", "--show-current")?.ifEmpty { null } ?: System.getenv("GIT_BRANCH") ?: "git")
|
||||
.removePrefix("origin/")
|
||||
.replace(Regex("[^a-zA-Z0-9-]+"), "-")
|
||||
return when {
|
||||
distance > 0 -> "$base-$branch.$distance+$hash${if (dirty) "-dirty" else ""}"
|
||||
dirty -> "$base-$branch+$hash-dirty"
|
||||
else -> base
|
||||
}
|
||||
}
|
||||
|
||||
extra["modVersion"] = providers.environmentVariable("VERSION").orNull ?: gitVersion()
|
||||
@@ -31,6 +31,8 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class StandardMacros {
|
||||
@@ -42,21 +44,24 @@ public class StandardMacros {
|
||||
defines.add(new StringPair(key, value));
|
||||
}
|
||||
|
||||
private static final Pattern ANGELICA_VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)(?:-(?:alpha|beta|pre|rc)(\\d{1,3}))?");
|
||||
|
||||
private static String makeAngelicaVersion()
|
||||
{
|
||||
String[] parts = Tags.VERSION.split("[.-]");
|
||||
int major = Integer.parseInt(parts[0]);
|
||||
int minor = Integer.parseInt(parts[1]);
|
||||
int patch = Integer.parseInt(parts[2]);
|
||||
int sub = 0;
|
||||
return formatAngelicaVersion(Tags.VERSION);
|
||||
}
|
||||
|
||||
// Handle optional prerelease (like beta62)
|
||||
if (parts.length > 3) {
|
||||
String pre = parts[3];
|
||||
String num = pre.replaceAll("\\D+", ""); // remove all non-digits
|
||||
if (!num.isEmpty())
|
||||
sub = Integer.parseInt(num);
|
||||
static String formatAngelicaVersion(String raw)
|
||||
{
|
||||
final Matcher matcher = ANGELICA_VERSION_PATTERN.matcher(raw);
|
||||
if (!matcher.find()) {
|
||||
Iris.logger.warn("Could not parse Angelica version \"{}\"; defining ANGELICA_VERSION as 99999999", raw);
|
||||
return "99999999";
|
||||
}
|
||||
final int major = Integer.parseInt(matcher.group(1));
|
||||
final int minor = Integer.parseInt(matcher.group(2));
|
||||
final int patch = Integer.parseInt(matcher.group(3));
|
||||
final int sub = matcher.group(4) == null ? 0 : Integer.parseInt(matcher.group(4));
|
||||
return String.format("%d%02d%02d%03d", major, minor, patch, sub);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.coderbot.iris.gl.shader;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class StandardMacrosVersionTest {
|
||||
@Test
|
||||
void releaseAndPrereleaseTags() {
|
||||
assertEquals("20228000", StandardMacros.formatAngelicaVersion("2.2.28"));
|
||||
assertEquals("20000008", StandardMacros.formatAngelicaVersion("2.0.0-alpha8"));
|
||||
assertEquals("10000078", StandardMacros.formatAngelicaVersion("1.0.0-beta78-pre"));
|
||||
assertEquals("20228000", StandardMacros.formatAngelicaVersion("2.2.28-pre"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void devBuildsIgnoreBranchAndHashDigits() {
|
||||
assertEquals("20228000", StandardMacros.formatAngelicaVersion("2.2.28-master.7+12857006ab-dirty"));
|
||||
assertEquals("20228000", StandardMacros.formatAngelicaVersion("2.2.28-fix2117.3+12857006ab"));
|
||||
assertEquals("20000012", StandardMacros.formatAngelicaVersion("2.0.0-alpha12-master.3+12857006ab"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unparseableVersionsReportNewest() {
|
||||
assertEquals("99999999", StandardMacros.formatAngelicaVersion("moltenvk-v3.4.2-master.1+38af64f10c-dirty"));
|
||||
assertEquals("99999999", StandardMacros.formatAngelicaVersion("NO-GIT-TAG-SET"));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ plugins {
|
||||
id("com.gtnewhorizons.gtnhconvention")
|
||||
}
|
||||
|
||||
apply(from = "../gradle/mod-version.gradle.kts")
|
||||
|
||||
minecraft {
|
||||
extraRunJvmArguments.add("-Dumbra.dumpClass=true")
|
||||
extraRunJvmArguments.add("-Dangelica.sdlgpu.enable=true")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
gtnh.settings.blowdryerTag = 0.2.2
|
||||
gtnh.modules.gitVersion = false
|
||||
|
||||
modName = Umbra
|
||||
modId = umbra
|
||||
|
||||
Reference in new issue
Block a user