Created
March 6, 2014 17:46
-
-
Save ericnormand/9395390 to your computer and use it in GitHub Desktop.
Insert a version string into ClojureScript output
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
(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