Welcome! Please see the About page for a little more info on how this works.

0 votes
in tools.build by
closed by

This is useful for deciding whether to issue a SNAPSHOT release or not.

Here's a working implementation if anyone wants it for their project now:

(ns build
  (:require [clojure.string :as str]
            [clojure.tools.build.api :as b]
            [clojure.tools.build.api.specs :as specs]))

(defn git-branch
  "Shells out to git and returns the current branch
    git branch --show-current
    :dir - dir to invoke this command from, by default current directory"
  [{:keys [dir] :or {dir "."} :as params}]
  (@#'b/assert-specs "git-branch" params :dir ::specs/path)
  (-> {:command-args ["git" "branch" "--show-current"]
       :dir (.getPath (b/resolve-path dir))
       :out :capture}

(def lib 'my-group/my-lib)

(def version
  (if (= "master" (git-branch nil))
    (format "1.0.%s" (b/git-count-revs nil))
    (format "1.0.%s-SNAPSHOT" (b/git-count-revs nil))))
closed with the note: Use git-process as of v0.6.5: (api/git-process {:git-args "branch --show-current"})

1 Answer

+1 vote
selected by