From e4a2ea0cef31d0b502f22ef6dfed04cb70f0522d Mon Sep 17 00:00:00 2001 From: duncte123 Date: Fri, 29 Jan 2021 17:00:58 +0100 Subject: [PATCH] Fix version when releasing --- .github/workflows/2-release-bot.yml | 1 + Dockerfile | 7 ++++ build.gradle.kts | 10 +++--- docker-compose.yml | 3 ++ .../commands/essentials/eval/EvalCommand.kt | 33 +++++++++---------- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/workflows/2-release-bot.yml b/.github/workflows/2-release-bot.yml index 8f1502096..1f399cdd0 100644 --- a/.github/workflows/2-release-bot.yml +++ b/.github/workflows/2-release-bot.yml @@ -54,3 +54,4 @@ jobs: registry: docker.pkg.github.com repository: dunctebot/skybot/skybot tags: latest + build_args: is_ci=true,git_sha=${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index 8df9a602a..c7e859607 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,13 @@ FROM adoptopenjdk:15-jdk-hotspot AS builder WORKDIR /skybot + +# setup CI flag +ARG is_ci +ARG git_sha +ENV CI=$is_ci +ENV GIT_HASH=$git_sha + COPY gradle ./gradle COPY gradlew build.gradle.kts settings.gradle.kts ./ RUN ./gradlew --no-daemon dependencies diff --git a/build.gradle.kts b/build.gradle.kts index 08b5b0781..2cc2047ab 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -43,7 +43,7 @@ plugins { pmd } -val numberVersion = "3.101.0" +val numberVersion = "3.101.1" project.group = "ml.duncte123.skybot" project.version = "${numberVersion}_${getGitHash()}" @@ -93,7 +93,7 @@ dependencies { implementation(group = "me.duncte123", name = "botCommons", version = "2.0.122") // JDA (java discord api) - implementation(group = "net.dv8tion", name = "JDA", version = "4.2.0_224") { + implementation(group = "net.dv8tion", name = "JDA", version = "4.2.0_227") { exclude(module = "opus-java") } @@ -327,8 +327,10 @@ fun getGitHash(): String { stdout.toString().trim() } catch (ignored: Throwable) { - // Probably ramidzkh"s problem - "DEV" + // Ugly hacks 101 :D + val hash = System.getenv("GIT_HASH") ?: "dev" + + return hash.substring(0, Math.min(8, hash.length)) } } diff --git a/docker-compose.yml b/docker-compose.yml index 10d2034cc..4d6710c48 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,9 @@ services: container_name: skybot build: context: . + args: + - is_ci=true + - git_sha=DEV environment: # Bot settings - BOT_ADMINS=191231307290771456,311769499995209728 diff --git a/src/main/kotlin/ml/duncte123/skybot/commands/essentials/eval/EvalCommand.kt b/src/main/kotlin/ml/duncte123/skybot/commands/essentials/eval/EvalCommand.kt index 51eef6a1f..e7c4a42d0 100644 --- a/src/main/kotlin/ml/duncte123/skybot/commands/essentials/eval/EvalCommand.kt +++ b/src/main/kotlin/ml/duncte123/skybot/commands/essentials/eval/EvalCommand.kt @@ -19,7 +19,6 @@ package ml.duncte123.skybot.commands.essentials.eval import com.github.natanbc.reliqua.request.PendingRequest -import groovy.lang.GroovyShell import kotlinx.coroutines.* import me.duncte123.botcommons.StringUtils import me.duncte123.botcommons.messaging.MessageUtils.* @@ -39,6 +38,8 @@ import ml.duncte123.skybot.utils.JSONMessageErrorsHelper.sendErrorJSON import net.dv8tion.jda.api.requests.RestAction import java.io.PrintWriter import java.io.StringWriter +import javax.script.ScriptEngine +import javax.script.ScriptEngineManager import kotlin.system.measureTimeMillis @Authors( @@ -49,7 +50,7 @@ import kotlin.system.measureTimeMillis ] ) class EvalCommand : Command() { - private val engine: GroovyShell + private val engine: ScriptEngine by lazy { ScriptEngineManager().getEngineByName("groovy") } private val importString: String init { @@ -59,8 +60,6 @@ class EvalCommand : Command() { this.help = "Evaluate groovy/java code on the bot" this.usage = "" - engine = GroovyShell() - val packageImports = listOf( "java.io", "java.lang", @@ -121,19 +120,19 @@ class EvalCommand : Command() { val script = importString + userIn - engine.setVariable("commandManager", ctx.commandManager) - engine.setVariable("message", ctx.message) - engine.setVariable("channel", ctx.message.textChannel) - engine.setVariable("guild", ctx.guild) - engine.setVariable("member", ctx.member) - engine.setVariable("author", ctx.author) - engine.setVariable("jda", ctx.jda) - engine.setVariable("shardManager", ctx.jda.shardManager) - engine.setVariable("event", ctx.event) + engine.put("commandManager", ctx.commandManager) + engine.put("message", ctx.message) + engine.put("channel", ctx.message.textChannel) + engine.put("guild", ctx.guild) + engine.put("member", ctx.member) + engine.put("author", ctx.author) + engine.put("jda", ctx.jda) + engine.put("shardManager", ctx.jda.shardManager) + engine.put("event", ctx.event) - engine.setVariable("args", ctx.args) - engine.setVariable("ctx", ctx) - engine.setVariable("variables", ctx.variables) + engine.put("args", ctx.args) + engine.put("ctx", ctx) + engine.put("variables", ctx.variables) @SinceSkybot("3.58.0") GlobalScope.launch( @@ -149,7 +148,7 @@ class EvalCommand : Command() { val time = measureTimeMillis { val out = withTimeoutOrNull(60000L /* = 60 seconds */) { try { - engine.evaluate(script) + engine.eval(script) } catch (ex: Throwable) { ex }