Skip to content

Instantly share code, notes, and snippets.

@mpenet
Created July 11, 2018 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpenet/a8e7bdad6e76f49d29e3a20123c33d61 to your computer and use it in GitHub Desktop.
Save mpenet/a8e7bdad6e76f49d29e3a20123c33d61 to your computer and use it in GitHub Desktop.
just a hack to use deps.edn dependencies in lein/boot projects without having to rely on half working plugins + versioning from git tags
(require
'[clojure.java.shell :as sh]
'[clojure.edn :as edn])
(set! *warn-on-reflection* true)
(defn next-version [version]
(when version
(let [[a b] (next (re-matches #"(.*?)([\d]+)" version))]
(when (and a b)
(str a (inc (Long/parseLong b)))))))
(defn deduce-version-from-git
"Avoid another decade of pointless, unnecessary and error-prone
fiddling with version labels in source code."
[]
(let [[version commits hash dirty?]
(next (re-matches #"(.*?)-(.*?)-(.*?)(-dirty)?\n"
(:out (sh/sh "git" "describe" "--dirty" "--long" "--tags" "--match" "[0-9]*.*"))))]
(cond
dirty? (str (next-version version) "-" hash "-dirty")
(pos? (Long/parseLong commits)) (str (next-version version) "-" hash)
:otherwise version)))
(defonce tools-deps (delay (edn/read-string (slurp "deps.edn"))))
(defn deps
[]
(some->> @tools-deps
:deps
(map (fn [[coord {:as props
:keys [mvn/version exclusions]}]]
[coord version :exclusions exclusions]))))
(defn repositories []
(:mvn/repos @tools-deps))
(load-file ".scaffolding.clj")
(defproject cc.qbits/foo (deduce-version-from-git)
:dependencies ~(deps))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment