Skip to content

Instantly share code, notes, and snippets.

@rdgd
Last active April 2, 2021 22:16
Show Gist options
  • Save rdgd/d61b87ed4f622329df3ad1e52811289d to your computer and use it in GitHub Desktop.
Save rdgd/d61b87ed4f622329df3ad1e52811289d to your computer and use it in GitHub Desktop.
Babashka version bump utility. Will increment semantic version in pom.xml and added a new structured changelog map to changelog file. File extension added for syntax highlighting, can remove.
#!/usr/bin/env bb
(defn inc-ver
[ver mode]
(let [[major minor bugfix] (map #(Integer. %) (clojure.string/split ver #"\."))
new-ver (case mode
:major [(inc major) 0 0]
:minor [major (inc minor) 0]
:bugfix [major minor (inc bugfix)])]
(clojure.string/join "." new-ver)))
(defn add-entry
[changelog mode]
(conj
changelog
{:version (-> changelog
first
:version
(or "0.0.0")
(inc-ver mode))
:date (str (java.time.LocalDate/now))
:messages []}))
(defn update-changelog!
[mode]
(spit "./CHANGELOG.edn" (-> (slurp "./CHANGELOG.edn")
(clojure.edn/read-string)
(add-entry mode))))
(defn update-pom!
[mode]
(spit "./pom.xml" (-> (clojure.java.io/reader (clojure.java.io/file "./pom.xml"))
(xml/parse)
(update :content #(map
(fn [{:keys [tag content attrs] :as el}]
(if (= tag :xmlns.http%3A%2F%2Fmaven.apache.org%2FPOM%2F4.0.0/version)
(xml/element tag attrs (inc-ver (first content) mode))
el)) %))
(xml/emit-str))))
(defn bump-vers!
[[mode]]
(update-changelog! (keyword mode))
(update-pom! (keyword mode))
(println "Changelog and pom updated!"))
(bump-vers! *command-line-args*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment