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)
|
the<IndraGitExtension>().commit()?.name?.substring(0, 7)
|
||||||
|
|
||||||
fun Project.branchName(): String =
|
fun Project.branchName(): String =
|
||||||
the<IndraGitExtension>().branchName() ?: System.getenv("BRANCH_NAME") ?: "local/dev"
|
the<IndraGitExtension>().branchName() ?: jenkinsBranchName() ?: "local/dev"
|
||||||
|
|
||||||
fun Project.shouldAddBranchName(): Boolean =
|
fun Project.shouldAddBranchName(): Boolean =
|
||||||
System.getenv("IGNORE_BRANCH")?.toBoolean() ?: (branchName() !in arrayOf("master", "local/dev"))
|
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
|
branchName().replace(Regex("[^0-9A-Za-z-_]"), "-") + '-' + version
|
||||||
|
|
||||||
fun buildNumber(): Int =
|
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 =
|
fun buildNumberAsString(): String =
|
||||||
buildNumber().takeIf { it != -1 }?.toString() ?: "??"
|
buildNumber().takeIf { it != -1 }?.toString() ?: "??"
|
||||||
@@ -78,4 +78,8 @@ fun Project.relocate(pattern: String) =
|
|||||||
.add(pattern)
|
.add(pattern)
|
||||||
|
|
||||||
private fun calcExclusion(section: String, bit: Int, excludedOn: Int): String =
|
private fun calcExclusion(section: String, bit: Int, excludedOn: Int): String =
|
||||||
if (excludedOn and bit > 0) section else ""
|
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 static org.geysermc.floodgate.util.Constants.COLOR_CHAR;
|
||||||
|
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.name.Named;
|
||||||
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||||
import org.geysermc.floodgate.command.WhitelistCommand.Message;
|
import org.geysermc.floodgate.command.WhitelistCommand.Message;
|
||||||
import org.geysermc.floodgate.command.util.Permission;
|
import org.geysermc.floodgate.command.util.Permission;
|
||||||
@@ -45,6 +46,10 @@ public class VersionSubcommand extends FloodgateSubCommand {
|
|||||||
@Inject
|
@Inject
|
||||||
private FloodgateLogger logger;
|
private FloodgateLogger logger;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Named("implementationName")
|
||||||
|
private String implementationName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String name() {
|
public String name() {
|
||||||
return "version";
|
return "version";
|
||||||
@@ -70,14 +75,19 @@ public class VersionSubcommand extends FloodgateSubCommand {
|
|||||||
Constants.VERSION, Constants.GIT_BRANCH
|
Constants.VERSION, Constants.GIT_BRANCH
|
||||||
));
|
));
|
||||||
|
|
||||||
String baseUrl = String.format(
|
//noinspection ConstantValue
|
||||||
"https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/%s/lastSuccessfulBuild/",
|
if (!Constants.GIT_MAIN_BRANCH.equals(Constants.GIT_BRANCH)) {
|
||||||
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(
|
httpClient.asyncGet(
|
||||||
baseUrl + "buildNumber",
|
String.format(Constants.LATEST_VERSION_URL, Constants.PROJECT_NAME),
|
||||||
JsonElement.class
|
JsonObject.class
|
||||||
).whenComplete((result, error) -> {
|
).whenComplete((result, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
sender.sendMessage(COLOR_CHAR + "cCould not retrieve latest version info!");
|
sender.sendMessage(COLOR_CHAR + "cCould not retrieve latest version info!");
|
||||||
@@ -85,10 +95,9 @@ public class VersionSubcommand extends FloodgateSubCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonElement response = result.getResponse();
|
JsonObject response = result.getResponse();
|
||||||
|
|
||||||
logger.info(String.valueOf(response));
|
logger.debug("code: {}, response: ", result.getHttpCode(), String.valueOf(response));
|
||||||
logger.info("{}", result.getHttpCode());
|
|
||||||
|
|
||||||
if (result.getHttpCode() == 404) {
|
if (result.getHttpCode() == 404) {
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
@@ -102,20 +111,21 @@ public class VersionSubcommand extends FloodgateSubCommand {
|
|||||||
//todo make it more generic instead of using a Whitelist command strings
|
//todo make it more generic instead of using a Whitelist command strings
|
||||||
logger.error(
|
logger.error(
|
||||||
"Got an error from requesting the latest Floodgate version: {}",
|
"Got an error from requesting the latest Floodgate version: {}",
|
||||||
response.toString()
|
String.valueOf(response)
|
||||||
);
|
);
|
||||||
sender.sendMessage(Message.UNEXPECTED_ERROR);
|
sender.sendMessage(Message.UNEXPECTED_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int buildNumber = response.getAsInt();
|
int buildNumber = response.get("build").getAsInt();
|
||||||
|
|
||||||
if (buildNumber > Constants.BUILD_NUMBER) {
|
if (buildNumber > Constants.BUILD_NUMBER) {
|
||||||
sender.sendMessage(String.format(
|
sender.sendMessage(String.format(
|
||||||
COLOR_CHAR + "7There is a newer version of Floodgate available!\n" +
|
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 + "7You are " + COLOR_CHAR + "e%s " + COLOR_CHAR + "7builds behind.\n" +
|
||||||
COLOR_CHAR + "7Download the latest Floodgate version here: " + COLOR_CHAR + "b%s",
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class NewsChecker {
|
|||||||
|
|
||||||
private void checkNews() {
|
private void checkNews() {
|
||||||
HttpResponse<JsonArray> response = httpClient.getSilent(
|
HttpResponse<JsonArray> response = httpClient.getSilent(
|
||||||
Constants.NEWS_OVERVIEW_URL + Constants.NEWS_PROJECT_NAME,
|
Constants.NEWS_OVERVIEW_URL + Constants.PROJECT_NAME,
|
||||||
JsonArray.class
|
JsonArray.class
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ public class NewsChecker {
|
|||||||
|
|
||||||
switch (item.getType()) {
|
switch (item.getType()) {
|
||||||
case ANNOUNCEMENT:
|
case ANNOUNCEMENT:
|
||||||
if (!item.getDataAs(AnnouncementData.class).isAffected(Constants.NEWS_PROJECT_NAME)) {
|
if (!item.getDataAs(AnnouncementData.class).isAffected(Constants.PROJECT_NAME)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public final class Constants {
|
|||||||
public static final String VERSION = "@floodgateVersion@";
|
public static final String VERSION = "@floodgateVersion@";
|
||||||
public static final int BUILD_NUMBER = Integer.parseInt("@buildNumber@");
|
public static final int BUILD_NUMBER = Integer.parseInt("@buildNumber@");
|
||||||
public static final String GIT_BRANCH = "@branch@";
|
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 int METRICS_ID = 14649;
|
||||||
|
|
||||||
public static final char COLOR_CHAR = '\u00A7';
|
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 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 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 LINK_INFO_URL = "https://link.geysermc.org/";
|
||||||
|
public static final String LATEST_DOWNLOAD_URL =
|
||||||
public static final String NEWS_PROJECT_NAME = "floodgate";
|
"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";
|
public static final String NTP_SERVER = "time.cloudflare.com";
|
||||||
|
|||||||
Reference in New Issue
Block a user