diff init50-git.gradle @ 331:7bc7c6c79d7c

check for current release and hotfix branches when looking for latest snapshot
author Marc Davis <davis@ssdt-ohio.org>
date Mon, 06 Mar 2023 13:37:28 -0500
parents 729ee03ee479
children 64a8d53c6d98
line wrap: on
line diff
--- a/init50-git.gradle	Fri Mar 03 22:02:56 2023 -0500
+++ b/init50-git.gradle	Mon Mar 06 13:37:28 2023 -0500
@@ -797,9 +797,28 @@
             def versions = "git tag".execute().text.split("\n")
                     .findAll { it != null || it != "" }
                     .collect { it.replace("v", "") }
-                    .collect { new Version(*it.split('\\.')*.toInteger()) }
+                    .collect {
+                        Version v = null
+                        try {
+                            v = new Version(*it.split('\\.')*.toInteger())
+                            return v
+                        } catch (ignored) {
+                            //non semver tag found, ignoring
+                        }
+                    }
                     .sort { v1, v2 -> v2 <=> v1 }
-            return versions ? versions.first().nextSnapshot() : new Version().nextSnapshot()
+
+            def branches = "git branch --remote".execute().text.split("\n")
+                    .findAll { it.contains('release') || it.contains('hotfix') }
+                    .collect { it.replaceAll('\\s+', ' ').split(' ')[1].split('/')[2] - 'v' }
+                    .collect { new Version(*it.split('\\.')*.toInteger()) }
+
+            def results = (branches + versions).sort { v1, v2 -> v2 <=> v1 }
+            if (results.isEmpty()) {
+                return new Version().nextSnapshot()
+            } else {
+                return results.first().nextSnapshot()
+            }
         } catch (ex) {
             println ex
             return new Version().nextSnapshot()