From 5191abaa6c7cc59da9c1baeecef0a4bfb542063d Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Thu, 12 Aug 2021 19:20:02 -0700 Subject: [PATCH] switch to tools.build --- .circleci/config.yml | 4 +- .github/workflows/test.yml | 2 +- CHANGELOG.md | 2 +- build.clj | 78 ++++++++++++++++++++++++++++++++++++++ deps.edn | 31 +++++++++------ pom.xml | 3 +- run-tests.sh | 26 ------------- 7 files changed, 102 insertions(+), 44 deletions(-) create mode 100644 build.clj delete mode 100755 run-tests.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 0d6ece1..a60521e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,7 +17,7 @@ jobs: - run: name: Download Dependencies # 1.9 is the default so we need to ask for 1.10 (1.11 is a snapshot we don't cache): - command: clojure -P -M:test:cljs-runner:eastwood:readme && clojure -P -M:1.10 + command: clojure -P -M:test:cljs:eastwood:readme && clojure -P -M:1.10 - save_cache: paths: - ~/.m2 @@ -26,4 +26,4 @@ jobs: key: honeysql-{{ checksum "deps.edn" }} - run: name: Run all the tests - command: sh run-tests.sh all + command: clojure -T:build ci diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 931b0ea..70382a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,6 @@ jobs: with: tools-deps: '1.10.3.933' - name: Run Tests - run: sh run-tests.sh all + run: clojure -T:build ci - name: Check cljdoc.edn run: curl -fsSL https://raw.githubusercontent.com/cljdoc/cljdoc/master/script/verify-cljdoc-edn | bash -s doc/cljdoc.edn diff --git a/CHANGELOG.md b/CHANGELOG.md index b67c800..9e30817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ * Fixes #340 by making hyphen to space logic more general so _operators_ containing `-` should retain the hyphen without special cases. * Documentation improvements: `:fetch`, `:lift`, `:limit`, `:offset`, `:param`, `:select`; also around JSON/PostgreSQL. * Link to the [HoneySQL web app](https://www.john-shaffer.com/honeysql/) in both the README and **Getting Started**. - * Update `depstar` and `test-runner`. + * Switch to `tools.build` for running tests and JAR building etc. * 2.0.0-rc5 (for testing; 2021-07-17) * Fix #338 by producing `OFFSET n ROWS` (or `ROW` if `n` is 1) if `:fetch` is present or `:sqlserver` dialect is specified; and by producing `FETCH NEXT n ROWS ONLY` (or `ROW` is `n` is 1; or `FIRST` instead of `NEXT` if `:offset` is not present). diff --git a/build.clj b/build.clj new file mode 100644 index 0000000..7a15ca1 --- /dev/null +++ b/build.clj @@ -0,0 +1,78 @@ +(ns build + "HoneySQL's build script. + + clojure -T:build run-tests + clojure -T:build run-tests :aliases '[:master]' + + 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])) + +(def lib 'com.github.seancorfield/honeysql) +(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." [_] + (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 + :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 readme "Run the README tests." [opts] (run-task [:readme]) 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 ci "Run the CI pipeline of tests (and build the JAR)." [opts] + (-> opts + (readme) + (eastwood) + (as-> opts + (reduce (fn [opts alias] + (run-tests (assoc opts :aliases [alias]))) + opts + [:cljs-runner :1.9 :1.10 :master])) + (clean) + (jar))) diff --git a/deps.edn b/deps.edn index e573b7d..d6f1b41 100644 --- a/deps.edn +++ b/deps.edn @@ -2,26 +2,33 @@ :paths ["src"] :deps {org.clojure/clojure {:mvn/version "1.9.0"}} :aliases - {:1.9 {:override-deps {org.clojure/clojure {:mvn/version "1.9.0"}}} + {;; for help: clojure -A:deps -T:build help/doc + :build {:deps {io.github.clojure/tools.build {:git/tag "v0.1.7" :git/sha "8a3abc2"}} + :ns-default build} + + ;; versions to test against: + :1.9 {:override-deps {org.clojure/clojure {:mvn/version "1.9.0"}}} :1.10 {:override-deps {org.clojure/clojure {:mvn/version "1.10.3"}}} :master {:override-deps {org.clojure/clojure {:mvn/version "1.11.1-master-SNAPSHOT"}}} - :test + + ;; running tests/checks of various kinds: + :test ; can also run clojure -X:test {:extra-paths ["test"] :extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.4.0" :git/sha "334f2e2"}} - :exec-fn cognitect.test-runner.api/test} - :cljs-runner {:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}} - :main-opts ["-m" "cljs-test-runner.main"]} + ;; so we can run both ways: + :exec-fn cognitect.test-runner.api/test + :main-opts ["-m" "cognitect.test-runner"]} + :cljs {:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}} + :main-opts ["-m" "cljs-test-runner.main"]} :readme {:extra-deps {seancorfield/readme {:mvn/version "1.0.16"}} :main-opts ["-m" "seancorfield.readme"]} :eastwood {:extra-deps {jonase/eastwood {:mvn/version "0.5.1"}} :main-opts ["-m" "eastwood.lint" "{:source-paths,[\"src\"]}"]} - :jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.278"}} - :exec-fn hf.depstar/jar - :exec-args {:jar "honeysql.jar" :sync-pom true}} - :install {:replace-deps {slipset/deps-deploy {:mvn/version "0.1.5"}} - :exec-fn deps-deploy.deps-deploy/deploy - :exec-args {:installer :local :artifact "honeysql.jar"}} + + ;; first run: clojure -T:build ci + ;; then: clojure -X:deploy target/h :deploy {:replace-deps {slipset/deps-deploy {:mvn/version "0.1.5"}} :exec-fn deps-deploy.deps-deploy/deploy - :exec-args {:installer :remote :artifact "honeysql.jar"}}}} + :exec-args {:installer :remote + :pom-file "target/classes/META-INF/maven/com.github.seancorfield/honeysql/pom.xml"}}}} diff --git a/pom.xml b/pom.xml index f25bd30..06153d6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.github.seancorfield honeysql - 2.0.0-rc5 + VERSION honeysql SQL as Clojure data structures. https://github.com/seancorfield/honeysql @@ -25,7 +25,6 @@ https://github.com/seancorfield/honeysql scm:git:git://github.com/seancorfield/honeysql.git scm:git:ssh://git@github.com/seancorfield/honeysql.git - v2.0.0-rc5 diff --git a/run-tests.sh b/run-tests.sh deleted file mode 100755 index 10606cf..0000000 --- a/run-tests.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -echo ==== Test README.md ==== && clojure -M:readme && \ - echo ==== Lint Source ==== && clojure -M:eastwood && \ - echo ==== Test ClojureScript ==== && clojure -M:test:cljs-runner - -if test $? -eq 0 -then - if test "$1" = "all" - then - for v in 1.9 1.10 master - do - echo ==== Test Clojure $v ==== - clojure -X:test:$v - if test $? -ne 0 - then - exit 1 - fi - done - else - echo ==== Test Clojure ==== - clojure -X:test - fi -else - exit 1 -fi