3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-07-01 19:08:07 +02:00

Show build number in startup log, fix Geyser version command(#4336)

* Version check command/startup log shows build number
* Add development build warning
* Fix `/geyser version` command
* Hack around outdated language module
Dieser Commit ist enthalten in:
chris 2024-06-22 20:32:29 +02:00 committet von GitHub
Ursprung e6bf3ffdf0
Commit 55e90b6f57
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
4 geänderte Dateien mit 60 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -75,7 +75,7 @@ tasks.processResources {
expand(
"branch" to info.branch,
"buildNumber" to info.buildNumber,
"projectVersion" to project.version,
"projectVersion" to info.version,
"commit" to info.commit,
"commitAbbrev" to info.commitAbbrev,
"commitMessage" to info.commitMessage,
@ -89,20 +89,25 @@ sourceSets {
blossom {
val info = GitInfo()
javaSources {
property("version", "${project.version} (${info.gitVersion})")
property("version", "${info.version} (${info.gitVersion})")
property("gitVersion", info.gitVersion)
property("buildNumber", info.buildNumber.toString())
property("branch", info.branch)
property("commit", info.commit)
property("repository", info.repository)
property("devVersion", info.isDev.toString())
}
}
}
}
fun Project.buildNumber(): Int =
fun buildNumber(): Int =
(System.getenv("BUILD_NUMBER"))?.let { Integer.parseInt(it) } ?: -1
fun isDevBuild(branch: String, repository: String): Boolean {
return branch != "master" || repository.equals("https://github.com/GeyserMC/Geyser", ignoreCase = true).not()
}
inner class GitInfo {
val branch: String
val commit: String
@ -115,22 +120,25 @@ inner class GitInfo {
val commitMessage: String
val repository: String
val isDev: Boolean
init {
// On Jenkins, a detached head is checked out, so indra cannot determine the branch.
// Fortunately, this environment variable is available.
branch = indraGit.branchName() ?: System.getenv("BRANCH_NAME") ?: "DEV"
branch = indraGit.branchName() ?: "DEV"
val commit = indraGit.commit()
this.commit = commit?.name ?: "0".repeat(40)
commitAbbrev = commit?.name?.substring(0, 7) ?: "0".repeat(7)
gitVersion = "git-${branch}-${commitAbbrev}"
version = "${project.version} ($gitVersion)"
buildNumber = buildNumber()
val git = indraGit.git()
commitMessage = git?.commit()?.message ?: ""
repository = git?.repository?.config?.getString("remote", "origin", "url") ?: ""
buildNumber = buildNumber()
isDev = isDevBuild(branch, repository)
val projectVersion = if (isDev) project.version else project.version.toString().replace("SNAPSHOT", "b${buildNumber}")
version = "$projectVersion ($gitVersion)"
}
}

Datei anzeigen

@ -34,4 +34,9 @@ public class BuildData {
public static final String BRANCH = "{{ branch }}";
public static final String COMMIT = "{{ commit }}";
public static final String REPOSITORY = "{{ repository }}";
private static final String DEV = "{{ devVersion }}";
public static boolean isDevBuild() {
return Boolean.parseBoolean(DEV);
}
}

Datei anzeigen

@ -122,6 +122,7 @@ public class GeyserImpl implements GeyserApi {
public static final String BRANCH = BuildData.BRANCH;
public static final String COMMIT = BuildData.COMMIT;
public static final String REPOSITORY = BuildData.REPOSITORY;
public static final boolean IS_DEV = BuildData.isDevBuild();
/**
* Oauth client ID for Microsoft authentication
@ -207,6 +208,12 @@ public class GeyserImpl implements GeyserApi {
logger.info("");
logger.info(GeyserLocale.getLocaleStringLog("geyser.core.load", NAME, VERSION));
logger.info("");
if (IS_DEV) {
// TODO cloud use language string
//logger.info(GeyserLocale.getLocaleStringLog("geyser.core.dev_build", "https://discord.gg/geysermc"));
logger.info("You are running a development build of Geyser! Please report any bugs you find on our Discord server: %s".formatted("https://discord.gg/geysermc"));
logger.info("");
}
logger.info("******************************************");
/* Initialize registries */
@ -684,6 +691,7 @@ public class GeyserImpl implements GeyserApi {
*
* @return true if the version number is not 'DEV'.
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isProductionEnvironment() {
// First is if Blossom runs, second is if Blossom doesn't run
//noinspection ConstantConditions,MismatchedStringCase - changes in production

Datei anzeigen

@ -25,8 +25,8 @@
package org.geysermc.geyser.command.defaults;
import com.fasterxml.jackson.databind.JsonNode;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
import org.geysermc.geyser.Constants;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.util.PlatformType;
import org.geysermc.geyser.command.GeyserCommand;
@ -37,8 +37,7 @@ import org.geysermc.geyser.text.ChatColor;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.WebUtils;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.io.IOException;
import java.util.List;
public class VersionCommand extends GeyserCommand {
@ -72,27 +71,36 @@ public class VersionCommand extends GeyserCommand {
GeyserImpl.NAME, GeyserImpl.VERSION, javaVersions, bedrockVersions));
// Disable update checking in dev mode and for players in Geyser Standalone
if (GeyserImpl.getInstance().isProductionEnvironment() && !(!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE)) {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.checking", sender.locale()));
try {
String buildXML = WebUtils.getBody("https://ci.opencollab.dev/job/GeyserMC/job/Geyser/job/" +
URLEncoder.encode(GeyserImpl.BRANCH, StandardCharsets.UTF_8) + "/lastSuccessfulBuild/api/xml?xpath=//buildNumber");
if (buildXML.startsWith("<buildNumber>")) {
int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?(/)?buildNumber>", "").trim());
int buildNum = this.geyser.buildNumber();
if (latestBuildNum == buildNum) {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.no_updates", sender.locale()));
} else {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.outdated",
sender.locale(), (latestBuildNum - buildNum), Constants.GEYSER_DOWNLOAD_LOCATION));
}
} else {
throw new AssertionError("buildNumber missing");
}
} catch (Exception e) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.version.failed"), e);
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.version.failed", sender.locale()));
if (!GeyserImpl.getInstance().isProductionEnvironment() || (!sender.isConsole() && geyser.getPlatformType() == PlatformType.STANDALONE)) {
return;
}
if (GeyserImpl.IS_DEV) {
// TODO cloud use language string
sender.sendMessage("You are running a development build of Geyser! Please report any bugs you find on our Discord server: %s"
.formatted("https://discord.gg/geysermc"));
//sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.core.dev_build", sender.locale(), "https://discord.gg/geysermc"));
return;
}
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.checking", sender.locale()));
try {
int buildNumber = this.geyser.buildNumber();
JsonNode response = WebUtils.getJson("https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest");
int latestBuildNumber = response.get("build").asInt();
if (latestBuildNumber == buildNumber) {
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.no_updates", sender.locale()));
return;
}
sender.sendMessage(GeyserLocale.getPlayerLocaleString(
"geyser.commands.version.outdated",
sender.locale(), (latestBuildNumber - buildNumber), "https://geysermc.org/download"
));
} catch (IOException e) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.version.failed"), e);
sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.version.failed", sender.locale()));
}
}