Skip to content

Instantly share code, notes, and snippets.

@ericnormand
Created March 6, 2014 17:46
Show Gist options
  • Save ericnormand/9395390 to your computer and use it in GitHub Desktop.
Save ericnormand/9395390 to your computer and use it in GitHub Desktop.
Insert a version string into ClojureScript output
(def ts (time/formatters :date-time-no-ms))
(defn git-hash []
(let [p (.exec (Runtime/getRuntime) (into-array String ["/bin/sh" "-c"
"git rev-list --format=format:'%ct' --max-count=1 `git rev-parse HEAD`"]))]
(.waitFor p)
(let [s (-> (.getInputStream p)
slurp
string/trim)
_ (prn s)
[ch ts] (string/split s #"\n")
ts (* 1000 (Long. ts)) ;; convert seconds to ms
[_ ch] (re-matches #"commit (.+)" ch)]
{:commit-hash ch
:timestamp (tc/from-long ts)})))
(defmacro insert-version []
(let [{:keys [commit-hash timestamp]} (git-hash)]
(str (time/unparse ts timestamp) " | " commit-hash)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment