next-jdbc/build.clj
2021-08-22 19:30:15 -07:00

57 lines
1.9 KiB
Clojure

(ns build
"next.jdbc's build script.
clojure -T:build run-tests
clojure -T:build ci
For more information, run:
clojure -A:deps -T:build help/doc"
(:require [clojure.tools.build.api :as b]
[clojure.tools.deps.alpha :as t]
[deps-deploy.deps-deploy :as dd]))
(def lib 'com.github.seancorfield/next.jdbc)
(def version (format "1.2.%s" (b/git-count-revs nil)))
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "target/%s-%s.jar" (name lib) version))
(defn clean "Remove the target folder." [_]
(println "\nCleaning target...")
(b/delete {:path "target"}))
(defn jar "Build the library JAR file." [_]
(println "\nWriting pom.xml...")
(b/write-pom {:class-dir class-dir
:lib lib
:version version
:scm {:tag (str "v" version)}
:basis basis
:src-dirs ["src"]})
(println "Copying src...")
(b/copy-dir {:src-dirs ["src"]
:target-dir class-dir})
(println (str "Building jar " jar-file "..."))
(b/jar {:class-dir class-dir
:jar-file jar-file}))
(defn run-tests "Run regular tests." [_]
(let [basis (b/create-basis {:aliases [:test]})
combined (t/combine-aliases basis [:test])
cmds (b/java-command {:basis basis
:java-opts (:jvm-opts combined)
:main 'clojure.main
:main-args ["-m" "cognitect.test-runner"]})
{:keys [exit]} (b/process cmds)]
(when-not (zero? exit)
(throw (ex-info "Tests failed" {})))))
(defn ci "Run the CI pipeline of tests (and build the JAR)." [opts]
(-> opts (run-tests) (clean) (jar)))
(defn deploy "Deploy the JAR to Clojars." [opts]
(dd/deploy (merge {:installer :remote :artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}
opts)))