From d0e254488381f020058d4501417bc30f2eefc1d5 Mon Sep 17 00:00:00 2001 From: mingjun97 Date: Wed, 18 May 2022 18:17:24 -0700 Subject: [PATCH] Auto inject version and git hash --- .gitignore | 2 ++ gc-plugin/build.gradle | 18 ++++++++++++++++++ .../{plugin.json => plugin.json.tmpl} | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) rename gc-plugin/src/main/resources/{plugin.json => plugin.json.tmpl} (85%) diff --git a/.gitignore b/.gitignore index 8a58a3c..b20eda0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ build # Ignore lib gc-plugin/lib/ + +gc-plugin/src/main/resources/plugin.json \ No newline at end of file diff --git a/gc-plugin/build.gradle b/gc-plugin/build.gradle index f92dfa6..9883469 100644 --- a/gc-plugin/build.gradle +++ b/gc-plugin/build.gradle @@ -19,6 +19,8 @@ plugins { sourceCompatibility = 17 targetCompatibility = 17 +def version_tag = "dev-1.1.2" + repositories { mavenCentral() } @@ -50,8 +52,24 @@ dependencies { } + +task injectGitHash { + def gitCommitHash = { + try { + return 'git rev-parse --verify --short HEAD'.execute().text.trim() + } catch (e) { + return "GIT_NOT_FOUND" + } + } + def pluginJson = { + return new File(projectDir, "src/main/resources/plugin.json.tmpl").text.replace("{{VERSION}}", "${version_tag}-${gitCommitHash()}") + } + new File(projectDir, "src/main/resources/plugin.json").text = pluginJson() +} + jar { jar.baseName = 'mojoconsole' destinationDir = file(".") } + diff --git a/gc-plugin/src/main/resources/plugin.json b/gc-plugin/src/main/resources/plugin.json.tmpl similarity index 85% rename from gc-plugin/src/main/resources/plugin.json rename to gc-plugin/src/main/resources/plugin.json.tmpl index 43ad582..cc29ee6 100644 --- a/gc-plugin/src/main/resources/plugin.json +++ b/gc-plugin/src/main/resources/plugin.json.tmpl @@ -1,7 +1,7 @@ { "name": "mojoconsole-plus", "description": "Grasscutter In Game Web Based Console", - "version": "dev-1.1.2", + "version": "{{VERSION}}", "mainClass": "com.mojo.consoleplus.ConsolePlus", "authors": ["mingjun97"]