From c446dced0e05c86e7e800a14c5879ba551e0aef1 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Wed, 25 Dec 2019 16:32:43 +0100 Subject: [PATCH] Version bump --- resources/BABASHKA_RELEASED_VERSION | 2 +- resources/BABASHKA_VERSION | 2 +- script/bump_version.clj | 42 +++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/resources/BABASHKA_RELEASED_VERSION b/resources/BABASHKA_RELEASED_VERSION index f55b2502..789511e7 100644 --- a/resources/BABASHKA_RELEASED_VERSION +++ b/resources/BABASHKA_RELEASED_VERSION @@ -1 +1 @@ -0.0.49 \ No newline at end of file +0.0.50 \ No newline at end of file diff --git a/resources/BABASHKA_VERSION b/resources/BABASHKA_VERSION index 789511e7..38c0191e 100644 --- a/resources/BABASHKA_VERSION +++ b/resources/BABASHKA_VERSION @@ -1 +1 @@ -0.0.50 \ No newline at end of file +0.0.51-SNAPSHOT \ No newline at end of file diff --git a/script/bump_version.clj b/script/bump_version.clj index 5addd96f..6a3591bd 100755 --- a/script/bump_version.clj +++ b/script/bump_version.clj @@ -2,8 +2,39 @@ (ns bump-version (:require [clojure.java.io :as io] - [clojure.string :as str] - [clojure.java.shell :refer [sh]])) + [clojure.string :as str])) + +(import '[java.lang ProcessBuilder$Redirect]) + +(defn shell-command + "Executes shell command. Exits script when the shell-command has a non-zero exit code, propagating it. + Accepts the following options: + `:input`: instead of reading from stdin, read from this string. + `:to-string?`: instead of writing to stdoud, write to a string and + return it." + ([args] (shell-command args nil)) + ([args {:keys [:input :to-string?]}] + (let [args (mapv str args) + pb (cond-> (-> (ProcessBuilder. ^java.util.List args) + (.redirectError ProcessBuilder$Redirect/INHERIT)) + (not to-string?) (.redirectOutput ProcessBuilder$Redirect/INHERIT) + (not input) (.redirectInput ProcessBuilder$Redirect/INHERIT)) + proc (.start pb)] + (when input + (with-open [w (io/writer (.getOutputStream proc))] + (binding [*out* w] + (print input) + (flush)))) + (let [string-out + (when to-string? + (let [sw (java.io.StringWriter.)] + (with-open [w (io/reader (.getInputStream proc))] + (io/copy w sw)) + (str sw))) + exit-code (.waitFor proc)] + (when-not (zero? exit-code) + (System/exit exit-code)) + string-out)))) (def version-file (io/file "resources" "BABASHKA_VERSION")) (def released-version-file (io/file "resources" "BABASHKA_RELEASED_VERSION")) @@ -14,8 +45,8 @@ patch (str/replace patch "-SNAPSHOT" "") new-version (str/join "." [major minor patch])] (spit version-file new-version) - (sh "git" "commit" "-a" "-m" (str "v" new-version)) - (println (:out (sh "git" "diff" "HEAD^" "HEAD")))) + (shell-command ["git" "commit" "-a" "-m" (str "v" new-version)]) + (shell-command ["git" "diff" "HEAD^" "HEAD"])) "post-release" (do (io/copy version-file released-version-file) (let [version-string (str/trim (slurp version-file)) @@ -24,5 +55,6 @@ patch (str (inc patch) "-SNAPSHOT") new-version (str/join "." [major minor patch])] (spit version-file new-version) - (sh "git" "commit" "-a" "-m" "Version bump"))) + (shell-command ["git" "commit" "-a" "-m" "Version bump"]) + (shell-command ["git" "diff" "HEAD^" "HEAD"]))) (println "Expected: release | post-release."))