feat: build info
i have this plan for quite a while now, finally i am able to do this
This commit is contained in:
parent
d8c8a9750d
commit
975199bf4f
4 changed files with 91 additions and 4 deletions
1
build-number.txt
Normal file
1
build-number.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
1107
|
47
build.gradle
47
build.gradle
|
@ -1,3 +1,5 @@
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'application'
|
id 'application'
|
||||||
|
@ -57,6 +59,51 @@ dependencies {
|
||||||
implementation 'org.concentus:Concentus:1.0-SNAPSHOT'
|
implementation 'org.concentus:Concentus:1.0-SNAPSHOT'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static def getGitCommitHash() {
|
||||||
|
try {
|
||||||
|
return 'git rev-parse --short HEAD'.execute().text.trim()
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace()
|
||||||
|
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static def getGitCommitCount() {
|
||||||
|
try {
|
||||||
|
return 'git rev-list --count HEAD'.execute().text.trim()
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace()
|
||||||
|
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def buildNumberFile = file("build-number.txt")
|
||||||
|
def buildNumber = 0
|
||||||
|
|
||||||
|
if (buildNumberFile.exists()) {
|
||||||
|
buildNumber = buildNumberFile.text.trim().toInteger() + 1
|
||||||
|
} else {
|
||||||
|
buildNumber = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
buildNumberFile.text = buildNumber
|
||||||
|
|
||||||
|
ext.buildInfo = [
|
||||||
|
gitCommitCount: getGitCommitCount(),
|
||||||
|
compileDate: new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(new Date()),
|
||||||
|
gitCommitHash: getGitCommitHash(),
|
||||||
|
buildNumber: buildNumber,
|
||||||
|
]
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
inputs.property("buildInfo", buildInfo)
|
||||||
|
filesMatching("application.properties") {
|
||||||
|
expand(buildInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
mainClass = 'me.chayapak1.chomens_bot.Main'
|
mainClass = 'me.chayapak1.chomens_bot.Main'
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import net.kyori.adventure.text.format.TextColor;
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.lang.management.MemoryUsage;
|
import java.lang.management.MemoryUsage;
|
||||||
|
@ -29,15 +30,20 @@ import java.time.Instant;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class InfoCommand extends Command {
|
public class InfoCommand extends Command {
|
||||||
public static final String ORIGINAL_REPOSITORY_URL = "https://code.chipmunk.land/ChomeNS/chomens-bot-java";
|
public static final String ORIGINAL_REPOSITORY_URL = "https://code.chipmunk.land/ChomeNS/chomens-bot-java";
|
||||||
|
|
||||||
|
public static final Properties BUILD_INFO = new Properties();
|
||||||
|
|
||||||
|
static {
|
||||||
|
try (final InputStream input = ClassLoader.getSystemClassLoader().getResourceAsStream("application.properties")) {
|
||||||
|
BUILD_INFO.load(input);
|
||||||
|
} catch (IOException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
public InfoCommand () {
|
public InfoCommand () {
|
||||||
super(
|
super(
|
||||||
"info",
|
"info",
|
||||||
|
@ -261,6 +267,35 @@ public class InfoCommand extends Command {
|
||||||
.clickEvent(
|
.clickEvent(
|
||||||
ClickEvent.openUrl(ORIGINAL_REPOSITORY_URL)
|
ClickEvent.openUrl(ORIGINAL_REPOSITORY_URL)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
.append(Component.newline())
|
||||||
|
.append(Component.text("Compiled at "))
|
||||||
|
.append(
|
||||||
|
Component
|
||||||
|
.text(BUILD_INFO.getProperty("build.date", "unknown"))
|
||||||
|
.color(ColorUtilities.getColorByString(bot.config.colorPalette.string))
|
||||||
|
)
|
||||||
|
.append(
|
||||||
|
Component
|
||||||
|
.translatable(
|
||||||
|
", Git commit %s (%s)",
|
||||||
|
Component
|
||||||
|
.text(BUILD_INFO.getProperty("build.git.commit.hash", "unknown"))
|
||||||
|
.color(ColorUtilities.getColorByString(bot.config.colorPalette.string)),
|
||||||
|
Component
|
||||||
|
.text(BUILD_INFO.getProperty("build.git.commit.count", "unknown"))
|
||||||
|
.color(ColorUtilities.getColorByString(bot.config.colorPalette.number))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.append(Component.newline())
|
||||||
|
.append(
|
||||||
|
Component
|
||||||
|
.translatable(
|
||||||
|
"Build %s",
|
||||||
|
Component
|
||||||
|
.text(BUILD_INFO.getProperty("build.number", "unknown"))
|
||||||
|
.color(ColorUtilities.getColorByString(bot.config.colorPalette.number))
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
src/main/resources/application.properties
Normal file
4
src/main/resources/application.properties
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
build.date=${compileDate}
|
||||||
|
build.git.commit.count=${gitCommitCount}
|
||||||
|
build.git.commit.hash=${gitCommitHash}
|
||||||
|
build.number=${buildNumber}
|
Loading…
Reference in a new issue