From 43701102a859e82e9b04a970fe556e211f1e2c79 Mon Sep 17 00:00:00 2001
From: Cam Saul <1455846+camsaul@users.noreply.github.com>
Date: Thu, 13 May 2021 13:29:50 -0700
Subject: [PATCH] ./bin/build should give EE a snapshot version starting with 1
 (#16050)

---
 bin/build-mb/src/build.clj                    | 35 ++++++++++---------
 bin/build-mb/src/build/version_info.clj       | 17 ++++-----
 bin/build-mb/test/build/version_info_test.clj | 31 ++++++++++------
 3 files changed, 47 insertions(+), 36 deletions(-)

diff --git a/bin/build-mb/src/build.clj b/bin/build-mb/src/build.clj
index ebbba32cb3b..c49a318caa1 100644
--- a/bin/build-mb/src/build.clj
+++ b/bin/build-mb/src/build.clj
@@ -56,8 +56,8 @@
 
 (def all-steps
   (ordered-map/ordered-map
-   :version      (fn [{:keys [version]}]
-                   (version-info/generate-version-info-file! version))
+   :version      (fn [{:keys [edition version]}]
+                   (version-info/generate-version-info-file! edition version))
    :translations (fn [_]
                    (i18n/create-all-artifacts!))
    :frontend     (fn [{:keys [edition]}]
@@ -72,22 +72,23 @@
    (build! nil))
 
   ([{:keys [version edition steps]
-     :or   {version (version-info/current-snapshot-version)
-            edition :oss
+     :or   {edition :oss
             steps   (keys all-steps)}}]
-   (u/step (format "Running build steps for %s version %s: %s"
-                   (case edition
-                     :oss "Community (OSS) Edition"
-                     :ee "Enterprise Edition")
-                   version
-                   (str/join ", " (map name steps)))
-     (doseq [step-name steps
-             :let      [step-fn (or (get all-steps (keyword step-name))
-                                    (throw (ex-info (format "Invalid step: %s" step-name)
-                                                    {:step        step-name
-                                                     :valid-steps (keys all-steps)})))]]
-       (step-fn {:version version, :edition edition}))
-     (u/announce "All build steps finished."))))
+   (let [version (or version
+                     (version-info/current-snapshot-version edition))]
+     (u/step (format "Running build steps for %s version %s: %s"
+                     (case edition
+                       :oss "Community (OSS) Edition"
+                       :ee  "Enterprise Edition")
+                     version
+                     (str/join ", " (map name steps)))
+       (doseq [step-name steps
+               :let      [step-fn (or (get all-steps (keyword step-name))
+                                      (throw (ex-info (format "Invalid step: %s" step-name)
+                                                      {:step        step-name
+                                                       :valid-steps (keys all-steps)})))]]
+         (step-fn {:version version, :edition edition}))
+       (u/announce "All build steps finished.")))))
 
 (defn -main [& steps]
   (u/exit-when-finished-nonzero-on-exception
diff --git a/bin/build-mb/src/build/version_info.clj b/bin/build-mb/src/build/version_info.clj
index e490dff4b5c..d5897d1bc66 100644
--- a/bin/build-mb/src/build/version_info.clj
+++ b/bin/build-mb/src/build/version_info.clj
@@ -55,13 +55,14 @@
   For builds from `master`, increment the minor version instead e.g.
 
     v0.37.1 -> v0.38.0-SNAPSHOT"
-  ([]
-   (current-snapshot-version (git-branch) (most-recent-tag)))
+  ([edition]
+   (current-snapshot-version edition (git-branch) (most-recent-tag)))
 
-  ([branch tag]
+  ([edition branch tag]
+   {:pre [(#{:oss :ee} edition)]}
    (if-let [tag-parts (not-empty (tag-parts tag))]
-     (let [[major minor patch] tag-parts
-           major               (or major 0)
+     (let [[_ minor patch] tag-parts
+           major               (case edition :oss 0 :ee 1)
            [minor patch]       (if (= branch "master")
                                  [(inc (or minor 0)) 0]
                                  [(or minor 0) (inc (or patch 0))])]
@@ -70,10 +71,10 @@
 
 (defn generate-version-info-file!
   "Generate version.properties file"
-  ([]
-   (generate-version-info-file! (current-snapshot-version)))
+  ([edition]
+   (generate-version-info-file! edition (current-snapshot-version edition)))
 
-  ([version]
+  ([edition version]
    (u/delete-file-if-exists! version-properties-filename)
    (u/step (format "Generate version.properties file for version %s" version)
      (spit version-properties-filename (version-properties version))
diff --git a/bin/build-mb/test/build/version_info_test.clj b/bin/build-mb/test/build/version_info_test.clj
index f4e64185b01..1409f024179 100644
--- a/bin/build-mb/test/build/version_info_test.clj
+++ b/bin/build-mb/test/build/version_info_test.clj
@@ -13,15 +13,24 @@
              (#'version-info/tag-parts tag))))))
 
 (deftest current-snapshot-version-test
-  (doseq [[branch tag->expected] {"release-x.37.x" {nil          "UNKNOWN"
-                                                    "0.37.0"     "v0.37.1-SNAPSHOT"
-                                                    "0.37.0.1"   "v0.37.1-SNAPSHOT"
-                                                    "0.37.1-rc2" "v0.37.2-SNAPSHOT"}
-                                  "master"         {nil          "UNKNOWN"
-                                                    "0.37.0"     "v0.38.0-SNAPSHOT"
-                                                    "0.37.0.1"   "v0.38.0-SNAPSHOT"
-                                                    "0.37.1-rc2" "v0.38.0-SNAPSHOT"}}
-          [tag expected]         tag->expected]
-    (testing (str (pr-str (list 'current-snapshot-version branch tag)) " => " (pr-str expected))
+  (doseq [[branch edition->tag->expected] {"release-x.37.x" {:oss {nil          "UNKNOWN"
+                                                                   "0.37.0"     "v0.37.1-SNAPSHOT"
+                                                                   "0.37.0.1"   "v0.37.1-SNAPSHOT"
+                                                                   "0.37.1-rc2" "v0.37.2-SNAPSHOT"}
+                                                             :ee  {nil          "UNKNOWN"
+                                                                   "0.37.0"     "v1.37.1-SNAPSHOT"
+                                                                   "0.37.0.1"   "v1.37.1-SNAPSHOT"
+                                                                   "0.37.1-rc2" "v1.37.2-SNAPSHOT"}}
+                                           "master"         {:oss {nil          "UNKNOWN"
+                                                                   "0.37.0"     "v0.38.0-SNAPSHOT"
+                                                                   "0.37.0.1"   "v0.38.0-SNAPSHOT"
+                                                                   "0.37.1-rc2" "v0.38.0-SNAPSHOT"}
+                                                             :ee  {nil          "UNKNOWN"
+                                                                   "0.37.0"     "v1.38.0-SNAPSHOT"
+                                                                   "0.37.0.1"   "v1.38.0-SNAPSHOT"
+                                                                   "0.37.1-rc2" "v1.38.0-SNAPSHOT"}}}
+          [edition tag->expected]         edition->tag->expected
+          [tag expected]                  tag->expected]
+    (testing (str (pr-str (list 'current-snapshot-version edition branch tag)) " => " (pr-str expected))
       (is (= expected
-             (version-info/current-snapshot-version branch tag))))))
+             (version-info/current-snapshot-version edition branch tag))))))
-- 
GitLab