|
| 1 | +(ns update-docs-for-branchname |
| 2 | + (:require |
| 3 | + [babashka.process :as p] |
| 4 | + [bling.core :refer [bling callout]] |
| 5 | + [clj-yaml.core :as yaml] |
| 6 | + [util :as u])) |
| 7 | + |
| 8 | +;; TODO: add test that docs_version is always parsable |
| 9 | + |
| 10 | +(defn config-docs-version |
| 11 | + "Get the latest docs version number from the _config.yml file." |
| 12 | + [] |
| 13 | + (let [[_ version-num] (re-matches #"v0.(\d+)" (:docs_version (yaml/parse-string (slurp "_config.yml"))))] |
| 14 | + (Integer/parseInt version-num))) |
| 15 | + |
| 16 | +(defn update? [config-docs-version release-num] |
| 17 | + (cond |
| 18 | + (> release-num config-docs-version) |
| 19 | + (do |
| 20 | + (callout {:type :warning |
| 21 | + :label "Newer version detected"} |
| 22 | + (format "Release number from branch (%s) is newer than docs_version from config.yml (%s).\nContinuing build." |
| 23 | + release-num |
| 24 | + config-docs-version)) |
| 25 | + false) |
| 26 | + |
| 27 | + (= release-num config-docs-version) |
| 28 | + true |
| 29 | + |
| 30 | + :else false)) |
| 31 | + |
| 32 | +(defn usage [] |
| 33 | + (println "Usage: script/update_docs_for_branchname.clj branchname") |
| 34 | + (System/exit 1)) |
| 35 | + |
| 36 | +(defn -main [& args] |
| 37 | + (let [branchname (first args) |
| 38 | + dry-run? (contains? (set args) "--dry-run") |
| 39 | + _ (when (nil? branchname) |
| 40 | + (println (callout {:type :error} (bling [:red "No branchname provided."]))) |
| 41 | + (usage)) |
| 42 | + [category release-num] (u/categorize-branchname branchname) |
| 43 | + command (case category |
| 44 | + :master "./script/docs master --set-version master" |
| 45 | + :release (format "./script/docs release-x.%s.x --set-version v0.%s %s" |
| 46 | + release-num |
| 47 | + release-num |
| 48 | + (if (update? (config-docs-version) release-num) |
| 49 | + "--update" |
| 50 | + "")) |
| 51 | + :test (format "./script/docs %s --set-version %s" branchname branchname) |
| 52 | + (do (println "Unpublishable branchname: " branchname) |
| 53 | + (System/exit 1)))] |
| 54 | + (callout {:type :info :label "Command To Run"} (bling [:green command])) |
| 55 | + (when-not dry-run? (p/shell command)))) |
| 56 | + |
| 57 | +(when (= *file* (System/getProperty "babashka.file")) |
| 58 | + (apply -main *command-line-args*)) |
0 commit comments