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
This commit is contained in:
chris 2024-06-22 20:32:29 +02:00 committed by GitHub
parent e6bf3ffdf0
commit 55e90b6f57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 60 additions and 31 deletions

View file

@ -75,7 +75,7 @@ tasks.processResources {
expand( expand(
"branch" to info.branch, "branch" to info.branch,
"buildNumber" to info.buildNumber, "buildNumber" to info.buildNumber,
"projectVersion" to project.version, "projectVersion" to info.version,
"commit" to info.commit, "commit" to info.commit,
"commitAbbrev" to info.commitAbbrev, "commitAbbrev" to info.commitAbbrev,
"commitMessage" to info.commitMessage, "commitMessage" to info.commitMessage,
@ -89,20 +89,25 @@ sourceSets {
blossom { blossom {
val info = GitInfo() val info = GitInfo()
javaSources { javaSources {
property("version", "${project.version} (${info.gitVersion})") property("version", "${info.version} (${info.gitVersion})")
property("gitVersion", info.gitVersion) property("gitVersion", info.gitVersion)
property("buildNumber", info.buildNumber.toString()) property("buildNumber", info.buildNumber.toString())
property("branch", info.branch) property("branch", info.branch)
property("commit", info.commit) property("commit", info.commit)
property("repository", info.repository) 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 (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 { inner class GitInfo {
val branch: String val branch: String
val commit: String val commit: String
@ -115,22 +120,25 @@ inner class GitInfo {
val commitMessage: String val commitMessage: String
val repository: String val repository: String
val isDev: Boolean
init { init {
// On Jenkins, a detached head is checked out, so indra cannot determine the branch. branch = indraGit.branchName() ?: "DEV"
// Fortunately, this environment variable is available.
branch = indraGit.branchName() ?: System.getenv("BRANCH_NAME") ?: "DEV"
val commit = indraGit.commit() val commit = indraGit.commit()
this.commit = commit?.name ?: "0".repeat(40) this.commit = commit?.name ?: "0".repeat(40)
commitAbbrev = commit?.name?.substring(0, 7) ?: "0".repeat(7) commitAbbrev = commit?.name?.substring(0, 7) ?: "0".repeat(7)
gitVersion = "git-${branch}-${commitAbbrev}" gitVersion = "git-${branch}-${commitAbbrev}"
version = "${project.version} ($gitVersion)"
buildNumber = buildNumber()
val git = indraGit.git() val git = indraGit.git()
commitMessage = git?.commit()?.message ?: "" commitMessage = git?.commit()?.message ?: ""
repository = git?.repository?.config?.getString("remote", "origin", "url") ?: "" 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)"
} }
} }

View file

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

View file

@ -122,6 +122,7 @@ public class GeyserImpl implements GeyserApi {
public static final String BRANCH = BuildData.BRANCH; public static final String BRANCH = BuildData.BRANCH;
public static final String COMMIT = BuildData.COMMIT; public static final String COMMIT = BuildData.COMMIT;
public static final String REPOSITORY = BuildData.REPOSITORY; public static final String REPOSITORY = BuildData.REPOSITORY;
public static final boolean IS_DEV = BuildData.isDevBuild();
/** /**
* Oauth client ID for Microsoft authentication * Oauth client ID for Microsoft authentication
@ -207,6 +208,12 @@ public class GeyserImpl implements GeyserApi {
logger.info(""); logger.info("");
logger.info(GeyserLocale.getLocaleStringLog("geyser.core.load", NAME, VERSION)); logger.info(GeyserLocale.getLocaleStringLog("geyser.core.load", NAME, VERSION));
logger.info(""); 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("******************************************"); logger.info("******************************************");
/* Initialize registries */ /* Initialize registries */
@ -684,6 +691,7 @@ public class GeyserImpl implements GeyserApi {
* *
* @return true if the version number is not 'DEV'. * @return true if the version number is not 'DEV'.
*/ */
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isProductionEnvironment() { public boolean isProductionEnvironment() {
// First is if Blossom runs, second is if Blossom doesn't run // First is if Blossom runs, second is if Blossom doesn't run
//noinspection ConstantConditions,MismatchedStringCase - changes in production //noinspection ConstantConditions,MismatchedStringCase - changes in production

View file

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