Created
July 11, 2018 15:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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