switch to tools.build

This commit is contained in:
Sean Corfield 2021-08-12 19:20:02 -07:00
parent dabb501e4b
commit 5191abaa6c
7 changed files with 102 additions and 44 deletions

View file

@ -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

View file

@ -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

View file

@ -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).

78
build.clj Normal file
View file

@ -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)))

View file

@ -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"}}
;; 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<TAB>
: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"}}}}

View file

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.seancorfield</groupId>
<artifactId>honeysql</artifactId>
<version>2.0.0-rc5</version>
<version>VERSION</version>
<name>honeysql</name>
<description>SQL as Clojure data structures.</description>
<url>https://github.com/seancorfield/honeysql</url>
@ -25,7 +25,6 @@
<url>https://github.com/seancorfield/honeysql</url>
<connection>scm:git:git://github.com/seancorfield/honeysql.git</connection>
<developerConnection>scm:git:ssh://git@github.com/seancorfield/honeysql.git</developerConnection>
<tag>v2.0.0-rc5</tag>
</scm>
<dependencies>
<dependency>

View file

@ -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