From 3ed5c4a68573f6b0b996bbe7f881743f0e54b6c2 Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 29 Nov 2023 23:44:05 +0100 Subject: [PATCH] builds --- .github/workflows/publish.yml | 36 +++++++++++++++++++ src/main/java/tsp/headdb/HeadDB.java | 2 +- src/main/java/tsp/headdb/Metrics.java | 3 +- .../tsp/headdb/core/command/CommandInfo.java | 3 +- .../java/tsp/headdb/core/storage/Storage.java | 1 - src/main/java/tsp/headdb/core/util/Utils.java | 22 ++++++++++++ .../implementation/requester/Requester.java | 2 +- 7 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..6217667 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,36 @@ +name: Publish build + +on: + push: + branches: + - master + - release + +jobs: + publish: + name: Upload build + runs-on: ubuntu-latest + if: contains(github.event.head_commit.message, '[ci skip]') == false + + steps: + - uses: actions/checkout@v2 + + - name: Set up JDK 17 + uses: actions/setup-java@v3.13.0 + with: + distribution: 'adopt' + java-version: '17' + java-package: jdk + architecture: x64 + + - name: Build with Maven + run: mvn -B package + + - name: Upload to Blob Builds + uses: WalshyDev/blob-builds/gh-action@main + with: + project: Slimefun4 + releaseChannel: ${{ github.ref == 'refs/heads/release' && 'Release' || 'Dev' }} + apiToken: ${{ secrets.BUILDS_API_TOKEN }} + file: './target/HeadDB.jar' + releaseNotes: ${{ github.event.head_commit.message }} \ No newline at end of file diff --git a/src/main/java/tsp/headdb/HeadDB.java b/src/main/java/tsp/headdb/HeadDB.java index c4bb72e..2c85c22 100644 --- a/src/main/java/tsp/headdb/HeadDB.java +++ b/src/main/java/tsp/headdb/HeadDB.java @@ -19,7 +19,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; @@ -71,6 +70,7 @@ public class HeadDB extends NexusPlugin { File langFile = new File(getDataFolder(), "langs.data"); if (!langFile.exists()) { try { + //noinspection ResultOfMethodCallIgnored langFile.createNewFile(); localization.saveLanguages(langFile); } catch (IOException ex) { diff --git a/src/main/java/tsp/headdb/Metrics.java b/src/main/java/tsp/headdb/Metrics.java index 2dd9e47..f1cbf8a 100644 --- a/src/main/java/tsp/headdb/Metrics.java +++ b/src/main/java/tsp/headdb/Metrics.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import tsp.headdb.core.util.Utils; import javax.net.ssl.HttpsURLConnection; import java.io.*; @@ -107,7 +108,7 @@ class Metrics { } private void appendServiceData(JsonObjectBuilder builder) { - builder.appendField("pluginVersion", plugin.getDescription().getVersion()); + builder.appendField("pluginVersion", Utils.getVersion().orElse("Unknown")); } private int getPlayerAmount() { diff --git a/src/main/java/tsp/headdb/core/command/CommandInfo.java b/src/main/java/tsp/headdb/core/command/CommandInfo.java index 64ac2db..8c22bff 100644 --- a/src/main/java/tsp/headdb/core/command/CommandInfo.java +++ b/src/main/java/tsp/headdb/core/command/CommandInfo.java @@ -2,6 +2,7 @@ package tsp.headdb.core.command; import org.bukkit.command.CommandSender; import tsp.headdb.HeadDB; +import tsp.headdb.core.util.Utils; import tsp.nexuslib.player.PlayerUtils; public class CommandInfo extends SubCommand { @@ -13,7 +14,7 @@ public class CommandInfo extends SubCommand { @Override public void handle(CommandSender sender, String[] args) { if (HeadDB.getInstance().getConfig().getBoolean("showAdvancedPluginInfo")) { - PlayerUtils.sendMessage(sender, "&7Running &6HeadDB - " + HeadDB.getInstance().getDescription().getVersion()); + PlayerUtils.sendMessage(sender, "&7Running &6HeadDB - " + Utils.getVersion().orElse(HeadDB.getInstance().getDescription().getVersion() + " &7(&4UNKNOWN SEMVER&7)")); PlayerUtils.sendMessage(sender, "&7GitHub: &6https://github.com/TheSilentPro/HeadDB"); } else { PlayerUtils.sendMessage(sender, "&7Running &6HeadDB &7by &6TheSilentPro (Silent)"); diff --git a/src/main/java/tsp/headdb/core/storage/Storage.java b/src/main/java/tsp/headdb/core/storage/Storage.java index 719be00..91d4349 100644 --- a/src/main/java/tsp/headdb/core/storage/Storage.java +++ b/src/main/java/tsp/headdb/core/storage/Storage.java @@ -5,7 +5,6 @@ import tsp.helperlite.Schedulers; import java.io.File; import java.util.concurrent.Executor; -import java.util.concurrent.Executors; public class Storage { diff --git a/src/main/java/tsp/headdb/core/util/Utils.java b/src/main/java/tsp/headdb/core/util/Utils.java index a742922..7772d03 100644 --- a/src/main/java/tsp/headdb/core/util/Utils.java +++ b/src/main/java/tsp/headdb/core/util/Utils.java @@ -32,6 +32,8 @@ import tsp.nexuslib.util.Validate; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Field; import java.math.BigDecimal; import java.net.MalformedURLException; @@ -41,6 +43,26 @@ import java.util.*; public class Utils { private static final HeadDB instance = HeadDB.getInstance(); + private static Properties properties = null; + + public static Optional getVersion() { + if (properties == null) { + InputStream is = instance.getResource("build.properties"); + if (is == null) { + return Optional.empty(); + } + + try { + properties = new Properties(); + properties.load(is); + } catch (IOException ex) { + instance.getLog().debug("Failed to load build properties: " + ex.getMessage()); + return Optional.empty(); + } + } + + return Optional.ofNullable(properties.getProperty("version")); + } public static String toString(Collection set) { String[] array = set.toArray(new String[0]); diff --git a/src/main/java/tsp/headdb/implementation/requester/Requester.java b/src/main/java/tsp/headdb/implementation/requester/Requester.java index a8ad096..a38d65c 100644 --- a/src/main/java/tsp/headdb/implementation/requester/Requester.java +++ b/src/main/java/tsp/headdb/implementation/requester/Requester.java @@ -85,7 +85,7 @@ public class Requester { HttpURLConnection connection = (HttpURLConnection) new URL(provider.getFormattedUrl(category)).openConnection(); connection.setConnectTimeout(5000); connection.setRequestMethod("GET"); - connection.setRequestProperty("User-Agent", plugin.getName() + "/" + plugin.getDescription().getVersion()); + connection.setRequestProperty("User-Agent", plugin.getName() + "/" + Utils.getVersion().orElse(plugin.getDescription().getVersion())); connection.setRequestProperty("Accept", "application/json"); try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {