aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-07-13 15:20:11 +0200
committermakamys <makamys@outlook.com>2022-07-13 15:20:11 +0200
commit2f9da90753a299bd0966efa0cb6f8a12e7a4e37a (patch)
treee470558ce6744e7613b80e3f304165f605460d09
parent722b63430a4b9bf4257aec5ac1876228f434e15b (diff)
downloadNeodymium-2f9da90753a299bd0966efa0cb6f8a12e7a4e37a.tar.gz
Neodymium-2f9da90753a299bd0966efa0cb6f8a12e7a4e37a.tar.bz2
Neodymium-2f9da90753a299bd0966efa0cb6f8a12e7a4e37a.zip
buildscript: Compute version from git tag if version.txt is absent
-rw-r--r--.github/workflows/gradle.yml2
-rw-r--r--buildscript/forge-1.7.gradle21
-rw-r--r--publish/build.gradle20
-rw-r--r--publish/get_version.py14
-rw-r--r--publish/update_updatejson.py2
5 files changed, 56 insertions, 3 deletions
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index 2858775..21ef39e 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -12,6 +12,8 @@ jobs:
steps:
- uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
diff --git a/buildscript/forge-1.7.gradle b/buildscript/forge-1.7.gradle
index 67fd4c7..f094cbb 100644
--- a/buildscript/forge-1.7.gradle
+++ b/buildscript/forge-1.7.gradle
@@ -2,8 +2,27 @@
apply plugin: 'forge'
+ext.publishDir = project.multiproject_structure.toBoolean() ? "${projectDir}/../publish" : "${projectDir}/publish"
-project.version = new File(project.multiproject_structure.toBoolean() ? "${projectDir}/../version.txt" : "${projectDir}/publish/version.txt").getText('UTF-8').trim()
+def getCommitVersion(){
+ try {
+ def commitHashProc = "python3 ${ext.publishDir}/get_version.py".execute()
+ commitHashProc.waitFor()
+ if(commitHashProc.exitValue() == 0){
+ def commitHash = commitHashProc.text.trim()
+
+ return commitHash
+ } else {
+ println commitHashProc.err.text
+ throw new Exception("get_version.py exited with non-zero return value")
+ }
+ } catch(Exception e){
+ println "Failed to run get_version.py: " + e.getMessage()
+ }
+ return "UNKNOWN" // fallback
+}
+
+project.version = getCommitVersion()
group = project.group
archivesBaseName = "${project.archives_base}-${project.minecraft_version}"
diff --git a/publish/build.gradle b/publish/build.gradle
index 16bc7fc..9cf7c6e 100644
--- a/publish/build.gradle
+++ b/publish/build.gradle
@@ -9,7 +9,25 @@ import groovy.json.JsonSlurper
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit
-def buildVersion = new File("${projectDir}/version.txt").getText('UTF-8').trim()
+def getCommitVersion(){
+ try {
+ def commitHashProc = "python3 ${projectDir}/get_version.py".execute()
+ commitHashProc.waitFor()
+ if(commitHashProc.exitValue() == 0){
+ def commitHash = commitHashProc.text.trim()
+
+ return commitHash
+ } else {
+ println commitHashProc.err.text
+ throw new Exception("get_version.py exited with non-zero return value")
+ }
+ } catch(Exception e){
+ println "Failed to run get_version.py: " + e.getMessage()
+ }
+ return "UNKNOWN" // fallback
+}
+
+def buildVersion = getCommitVersion()
def changeLog = new File("${projectDir}/changelog.md").getText('UTF-8')
def gameVersionsMap = new JsonSlurper().parseText(file("gameVersions.json").getText('UTF-8'))
ext.gameVersions = gameVersionsMap.keySet()
diff --git a/publish/get_version.py b/publish/get_version.py
new file mode 100644
index 0000000..0c19c2d
--- /dev/null
+++ b/publish/get_version.py
@@ -0,0 +1,14 @@
+import subprocess
+import sys
+import os
+
+ver = None
+
+versionPath = os.path.dirname(sys.argv[0]) + "/version.txt"
+if os.path.exists(versionPath):
+ with open(versionPath, "r", encoding="utf8") as fp:
+ ver = fp.read()
+else:
+ ver = subprocess.run("git describe --tags --dirty", capture_output=True, text=True).stdout or "UNKNOWN-" + subprocess.run("git describe --always --dirty", capture_output=True, text=True).stdout or "UNKNOWN"
+
+print(ver.strip())
diff --git a/publish/update_updatejson.py b/publish/update_updatejson.py
index 8d751e5..b381729 100644
--- a/publish/update_updatejson.py
+++ b/publish/update_updatejson.py
@@ -7,7 +7,7 @@ jsonPath = "../updatejson/update.json"
fullFormat = "updateJsonFullVersionFormat=true" in open("gradle.properties", "r", encoding="utf8").read()
data = json.load(open(jsonPath, "r", encoding="utf8"))
-ver = open("version.txt", "r").read().strip()
+ver = subprocess.run("python3 get_version.py", capture_output=True, text=True).stdout.strip()
for gameVer in json.load(open("gameVersions.json", "r")).keys():
modVer = "{}".format(ver) if not fullFormat else "{}-{}".format(gameVer, ver)