aboutsummaryrefslogtreecommitdiff
path: root/buildSrc/src/main/kotlin/neubs/versioning.kt
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-09-12 16:12:37 +0200
committernea <romangraef@gmail.com>2022-09-12 16:12:37 +0200
commit460fbe0001754116fa7407eb6c7345ca22b23704 (patch)
treefeb691f44535ce301807e7eded3aba2fdbfab18e /buildSrc/src/main/kotlin/neubs/versioning.kt
parent2b4b31cc8938e4a5c41e4e9dc59433cd1883116f (diff)
downloadNotEnoughUpdates-460fbe0001754116fa7407eb6c7345ca22b23704.tar.gz
NotEnoughUpdates-460fbe0001754116fa7407eb6c7345ca22b23704.tar.bz2
NotEnoughUpdates-460fbe0001754116fa7407eb6c7345ca22b23704.zip
Clean up buildscript
Diffstat (limited to 'buildSrc/src/main/kotlin/neubs/versioning.kt')
-rw-r--r--buildSrc/src/main/kotlin/neubs/versioning.kt54
1 files changed, 54 insertions, 0 deletions
diff --git a/buildSrc/src/main/kotlin/neubs/versioning.kt b/buildSrc/src/main/kotlin/neubs/versioning.kt
new file mode 100644
index 00000000..254e0012
--- /dev/null
+++ b/buildSrc/src/main/kotlin/neubs/versioning.kt
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package neubs
+
+import org.gradle.api.Project
+import java.io.ByteArrayOutputStream
+
+fun Project.setVersionFromEnvironment(baseVersion: String) {
+ val buildExtra = mutableListOf<String>()
+ val buildVersion = properties["BUILD_VERSION"] as? String
+ if (buildVersion != null) buildExtra.add(buildVersion)
+ if (System.getenv("CI") == "true") buildExtra.add("ci")
+
+ val stdout = ByteArrayOutputStream()
+ val execResult = exec {
+ commandLine("git", "describe", "--always", "--first-parent", "--abbrev=7")
+ standardOutput = stdout
+ isIgnoreExitValue = true
+ }
+ if (execResult.exitValue == 0) {
+ buildExtra.add(String(stdout.toByteArray()).trim())
+ }
+
+ val gitDiffStdout = ByteArrayOutputStream()
+ val gitDiffResult = exec {
+ commandLine("git", "status", "--porcelain")
+ standardOutput = gitDiffStdout
+ isIgnoreExitValue = true
+ }
+ if (gitDiffStdout.toByteArray().isNotEmpty()) {
+ buildExtra.add("dirty")
+ }
+
+ version = baseVersion + (if (buildExtra.isEmpty()) "" else buildExtra.joinToString(prefix = "+", separator = "."))
+
+}
+