mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2025-12-19 14:59:20 +00:00
Fixed GitHub Action run numbers and updated download url
This commit is contained in:
@@ -40,7 +40,7 @@ fun Project.lastCommitHash(): String? =
|
||||
the<IndraGitExtension>().commit()?.name?.substring(0, 7)
|
||||
|
||||
fun Project.branchName(): String =
|
||||
the<IndraGitExtension>().branchName() ?: System.getenv("BRANCH_NAME") ?: "local/dev"
|
||||
the<IndraGitExtension>().branchName() ?: jenkinsBranchName() ?: "local/dev"
|
||||
|
||||
fun Project.shouldAddBranchName(): Boolean =
|
||||
System.getenv("IGNORE_BRANCH")?.toBoolean() ?: (branchName() !in arrayOf("master", "local/dev"))
|
||||
@@ -49,7 +49,7 @@ fun Project.versionWithBranchName(): String =
|
||||
branchName().replace(Regex("[^0-9A-Za-z-_]"), "-") + '-' + version
|
||||
|
||||
fun buildNumber(): Int =
|
||||
System.getenv("BUILD_NUMBER")?.let { Integer.parseInt(it) } ?: -1
|
||||
(System.getenv("GITHUB_RUN_NUMBER") ?: jenkinsBuildNumber())?.let { Integer.parseInt(it) } ?: -1
|
||||
|
||||
fun buildNumberAsString(): String =
|
||||
buildNumber().takeIf { it != -1 }?.toString() ?: "??"
|
||||
@@ -79,3 +79,7 @@ fun Project.relocate(pattern: String) =
|
||||
|
||||
private fun calcExclusion(section: String, bit: Int, excludedOn: Int): String =
|
||||
if (excludedOn and bit > 0) section else ""
|
||||
|
||||
// todo remove these when we're not using Jenkins anymore
|
||||
private fun jenkinsBranchName(): String? = System.getenv("BRANCH_NAME")
|
||||
private fun jenkinsBuildNumber(): String? = System.getenv("BUILD_NUMBER")
|
||||
@@ -28,8 +28,9 @@ package org.geysermc.floodgate.command.main;
|
||||
import static org.geysermc.floodgate.util.Constants.COLOR_CHAR;
|
||||
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.name.Named;
|
||||
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||
import org.geysermc.floodgate.command.WhitelistCommand.Message;
|
||||
import org.geysermc.floodgate.command.util.Permission;
|
||||
@@ -45,6 +46,10 @@ public class VersionSubcommand extends FloodgateSubCommand {
|
||||
@Inject
|
||||
private FloodgateLogger logger;
|
||||
|
||||
@Inject
|
||||
@Named("implementationName")
|
||||
private String implementationName;
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "version";
|
||||
@@ -70,14 +75,19 @@ public class VersionSubcommand extends FloodgateSubCommand {
|
||||
Constants.VERSION, Constants.GIT_BRANCH
|
||||
));
|
||||
|
||||
String baseUrl = String.format(
|
||||
"https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/%s/lastSuccessfulBuild/",
|
||||
Constants.GIT_BRANCH
|
||||
);
|
||||
//noinspection ConstantValue
|
||||
if (!Constants.GIT_MAIN_BRANCH.equals(Constants.GIT_BRANCH)) {
|
||||
sender.sendMessage(String.format(
|
||||
COLOR_CHAR + "7Detected that you aren't on the %s branch, " +
|
||||
"so we can't fetch the latest version.",
|
||||
Constants.GIT_MAIN_BRANCH
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
httpClient.asyncGet(
|
||||
baseUrl + "buildNumber",
|
||||
JsonElement.class
|
||||
String.format(Constants.LATEST_VERSION_URL, Constants.PROJECT_NAME),
|
||||
JsonObject.class
|
||||
).whenComplete((result, error) -> {
|
||||
if (error != null) {
|
||||
sender.sendMessage(COLOR_CHAR + "cCould not retrieve latest version info!");
|
||||
@@ -85,10 +95,9 @@ public class VersionSubcommand extends FloodgateSubCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
JsonElement response = result.getResponse();
|
||||
JsonObject response = result.getResponse();
|
||||
|
||||
logger.info(String.valueOf(response));
|
||||
logger.info("{}", result.getHttpCode());
|
||||
logger.debug("code: {}, response: ", result.getHttpCode(), String.valueOf(response));
|
||||
|
||||
if (result.getHttpCode() == 404) {
|
||||
sender.sendMessage(
|
||||
@@ -102,20 +111,21 @@ public class VersionSubcommand extends FloodgateSubCommand {
|
||||
//todo make it more generic instead of using a Whitelist command strings
|
||||
logger.error(
|
||||
"Got an error from requesting the latest Floodgate version: {}",
|
||||
response.toString()
|
||||
String.valueOf(response)
|
||||
);
|
||||
sender.sendMessage(Message.UNEXPECTED_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
int buildNumber = response.getAsInt();
|
||||
int buildNumber = response.get("build").getAsInt();
|
||||
|
||||
if (buildNumber > Constants.BUILD_NUMBER) {
|
||||
sender.sendMessage(String.format(
|
||||
COLOR_CHAR + "7There is a newer version of Floodgate available!\n" +
|
||||
COLOR_CHAR + "7You are " + COLOR_CHAR + "e%s " + COLOR_CHAR + "7builds behind.\n" +
|
||||
COLOR_CHAR + "7Download the latest Floodgate version here: " + COLOR_CHAR + "b%s",
|
||||
buildNumber - Constants.BUILD_NUMBER, baseUrl
|
||||
buildNumber - Constants.BUILD_NUMBER,
|
||||
String.format(Constants.LATEST_DOWNLOAD_URL, implementationName)
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class NewsChecker {
|
||||
|
||||
private void checkNews() {
|
||||
HttpResponse<JsonArray> response = httpClient.getSilent(
|
||||
Constants.NEWS_OVERVIEW_URL + Constants.NEWS_PROJECT_NAME,
|
||||
Constants.NEWS_OVERVIEW_URL + Constants.PROJECT_NAME,
|
||||
JsonArray.class
|
||||
);
|
||||
|
||||
@@ -173,7 +173,7 @@ public class NewsChecker {
|
||||
|
||||
switch (item.getType()) {
|
||||
case ANNOUNCEMENT:
|
||||
if (!item.getDataAs(AnnouncementData.class).isAffected(Constants.NEWS_PROJECT_NAME)) {
|
||||
if (!item.getDataAs(AnnouncementData.class).isAffected(Constants.PROJECT_NAME)) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -29,6 +29,7 @@ public final class Constants {
|
||||
public static final String VERSION = "@floodgateVersion@";
|
||||
public static final int BUILD_NUMBER = Integer.parseInt("@buildNumber@");
|
||||
public static final String GIT_BRANCH = "@branch@";
|
||||
public static final String GIT_MAIN_BRANCH = "master";
|
||||
public static final int METRICS_ID = 14649;
|
||||
|
||||
public static final char COLOR_CHAR = '\u00A7';
|
||||
@@ -48,9 +49,12 @@ public final class Constants {
|
||||
public static final String NEWS_OVERVIEW_URL = "http" + API_BASE_URL + "/v2/news/";
|
||||
public static final String GET_BEDROCK_LINK = "http" + API_BASE_URL + "/v2/link/bedrock/";
|
||||
|
||||
public static final String PROJECT_NAME = "floodgate";
|
||||
public static final String LINK_INFO_URL = "https://link.geysermc.org/";
|
||||
|
||||
public static final String NEWS_PROJECT_NAME = "floodgate";
|
||||
public static final String LATEST_DOWNLOAD_URL =
|
||||
"https://geysermc.org/download#%s";
|
||||
public static final String LATEST_VERSION_URL =
|
||||
"https://download.geysermc.org/v2/projects/%s/versions/latest/builds/latest";
|
||||
|
||||
|
||||
public static final String NTP_SERVER = "time.cloudflare.com";
|
||||
|
||||
Reference in New Issue
Block a user