Merge remote-tracking branch 'upstream/develop' into lread-issue-290

Adapt to build changes.

* upstream/develop:
  Switch to build-clj lib
This commit is contained in:
lread 2021-08-28 17:04:36 -04:00
commit 4eb9eca147
2 changed files with 29 additions and 80 deletions

View file

@ -9,49 +9,17 @@
For more information, run: For more information, run:
clojure -A:deps -T:build help/doc" clojure -A:deps -T:build help/doc"
(:require [babashka.fs :as fs] (:require [babashka.fs :as fs]
[clojure.tools.build.api :as b] [clojure.tools.build.api :as b]
[clojure.tools.deps.alpha :as t] [org.corfield.build :as bb]
[deps-deploy.deps-deploy :as dd]
[lread.test-doc-blocks :as tdb])) [lread.test-doc-blocks :as tdb]))
(def lib 'com.github.seancorfield/honeysql) (def lib 'com.github.seancorfield/honeysql)
(def version (format "2.0.%s" (b/git-count-revs nil))) (def version (format "2.0.%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." [_] (defn eastwood "Run Eastwood." [opts]
(println "\nCleaning target...") (-> opts (bb/run-task [:eastwood])))
(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-task
[aliases]
(println "\nRunning task for:" aliases)
(let [basis (b/create-basis {:aliases aliases})
combined (t/combine-aliases basis aliases)
cmds (b/java-command {:basis basis
:java-opts (:jvm-opts combined)
:main 'clojure.main
:main-args (:main-opts combined)})
{:keys [exit]} (b/process cmds)]
(when-not (zero? exit)
(throw (ex-info (str "Task failed for: " aliases) {})))))
(defn gen-doc-tests "Generate tests from doc code blocks" [opts] (defn gen-doc-tests "Generate tests from doc code blocks" [opts]
(let [docs ["README.md" (let [docs ["README.md"
@ -70,39 +38,26 @@
(println "gen-doc-tests: Tests already generated"))) (println "gen-doc-tests: Tests already generated")))
opts) opts)
(defn eastwood "Run Eastwood." [opts] (run-task [:eastwood]) opts)
(defn run-tests
"Run regular tests.
Optionally specify :aliases:
[:1.9] -- test against Clojure 1.9 (the default)
[:1.10] -- test against Clojure 1.10.3
[:master] -- test against Clojure 1.11 master snapshot
[:cljs] -- test against ClojureScript"
[{:keys [aliases] :as opts}]
(run-task (into [:test] aliases))
opts)
(defn run-doc-tests (defn run-doc-tests
"Run generated doc tests. "Generate and run doc tests.
Optionally specify :platform: Optionally specify :plaftorm:
:1.9 -- test against Clojure 1.9 (the default) :1.9 -- test against Clojure 1.9 (the default)
:1.10 -- test against Clojure 1.10.3 :1.10 -- test against Clojure 1.10.3
:master -- test against Clojure 1.11 master snapshot :master -- test against Clojure 1.11 master snapshot
:cljs -- test against ClojureScript" :cljs -- test against ClojureScript"
[{:keys [platform] :or {platform :1.9} :as opts}] [{:keys [platform] :or {platform :1.9} :as opts}]
(gen-doc-tests opts) (gen-doc-tests opts)
(let [aliases (case platform (bb/run-tests (assoc opts :aliases
:cljs [platform :test-doc :test-doc-cljs] (conj [:test-doc platform]
[platform :runner :test-doc :test-doc-clj])] (if (= :cljs platform)
(run-task aliases)) :test-doc-cljs
opts) :test-doc-clj)))))
(defn ci "Run the CI pipeline of tests (and build the JAR)." [opts] (defn ci "Run the CI pipeline of tests (and build the JAR)." [opts]
(-> opts (-> opts
(clean) (bb/clean)
(assoc :lib lib :version version)
(as-> opts (as-> opts
(reduce (fn [opts platform] (reduce (fn [opts platform]
(run-doc-tests (assoc opts :platform platform))) (run-doc-tests (assoc opts :platform platform)))
@ -111,15 +66,13 @@
(eastwood) (eastwood)
(as-> opts (as-> opts
(reduce (fn [opts alias] (reduce (fn [opts alias]
(run-tests (assoc opts :aliases (cond-> [alias] (bb/run-tests (assoc opts :aliases [alias])))
(not= :cljs alias)
(conj :runner)))))
opts opts
[:cljs :1.9 :1.10 :master])) [:cljs :1.9 :1.10 :master]))
(clean) (bb/clean)
(jar))) (bb/jar)))
(defn deploy "Deploy the JAR to Clojars." [opts] (defn deploy "Deploy the JAR to Clojars." [opts]
(dd/deploy (merge {:installer :remote :artifact jar-file (-> opts
:pom-file (b/pom-path {:lib lib :class-dir class-dir})} (assoc :lib lib :version version)
opts))) (bb/deploy)))

View file

@ -5,8 +5,7 @@
{;; for help: clojure -A:deps -T:build help/doc {;; for help: clojure -A:deps -T:build help/doc
:build {:deps {babashka/fs {:mvn/version "0.0.5"} :build {:deps {babashka/fs {:mvn/version "0.0.5"}
com.github.lread/test-doc-blocks {:mvn/version "1.0.137-alpha"} com.github.lread/test-doc-blocks {:mvn/version "1.0.137-alpha"}
io.github.clojure/tools.build {:git/tag "v0.1.9" :git/sha "6736c83"} io.github.seancorfield/build-clj {:git/tag "v0.1.0" :git/sha "fe2d586"}}
io.github.slipset/deps-deploy {:sha "b4359c5d67ca002d9ed0c4b41b710d7e5a82e3bf"}}
:ns-default build} :ns-default build}
;; versions to test against: ;; versions to test against:
@ -15,20 +14,17 @@
:master {:override-deps {org.clojure/clojure {:mvn/version "1.11.1-master-SNAPSHOT"}}} :master {:override-deps {org.clojure/clojure {:mvn/version "1.11.1-master-SNAPSHOT"}}}
;; running tests/checks of various kinds: ;; running tests/checks of various kinds:
:test
:test {:extra-paths ["test"]} {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner
:runner ; can also run clojure -X:test
{:extra-deps {io.github.cognitect-labs/test-runner
{:git/tag "v0.4.0" :git/sha "334f2e2"}} {:git/tag "v0.4.0" :git/sha "334f2e2"}}
:main-opts ["-m" "cognitect.test-runner"]
:exec-fn cognitect.test-runner.api/test} :exec-fn cognitect.test-runner.api/test}
;; various "runners" for tests/CI: ;; various "runners" for tests/CI:
:cljs {:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}} :cljs {:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}}
:main-opts ["-m" "cljs-test-runner.main"]} :main-opts ["-m" "cljs-test-runner.main"]}
:test-doc {:extra-paths ["target/test-doc-blocks/test"]} :test-doc {:replace-paths ["src" "target/test-doc-blocks/test"]}
:test-doc-clj {:main-opts ["-m" "cognitect.test-runner" :test-doc-clj {:main-opts ["-m" "cognitect.test-runner"
"-d" "target/test-doc-blocks/test"]} "-d" "target/test-doc-blocks/test"]}
:test-doc-cljs {:main-opts ["-m" "cljs-test-runner.main" :test-doc-cljs {:main-opts ["-m" "cljs-test-runner.main"