From 238a4fae06ccba6dab8d952bfc157d646363f617 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 09:11:36 +0900 Subject: [PATCH 01/12] migrate: leiningen -> tools.deps, build.edn, kaocha - Drop Clojure 1.8 support: kaocha only supported 1.9+ - Remove `antq` clojure alias: use global installed antq - Remove `cloverage` make target: kaocha is configured to analyze code coverage by default - Use build.clj file instead of project.clj file for testing --- .github/workflows/lint-and-test.yml | 6 +-- Makefile | 20 ++++----- build.clj | 32 ++++++++++++++ deps.edn | 32 ++++++++++++++ .../test/tarayo/integration/send_test.clj | 4 +- project.clj | 43 ------------------- test/tarayo/mail/mime/multipart/body_test.clj | 22 +++++----- test/tarayo/mail/mime/multipart_test.clj | 4 +- tests.edn | 14 ++++++ 9 files changed, 104 insertions(+), 73 deletions(-) create mode 100644 build.clj create mode 100644 deps.edn delete mode 100644 project.clj create mode 100644 tests.edn diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 6e67a5f..92695e6 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -44,26 +44,22 @@ jobs: architecture: x64 - uses: DeLaGuardo/setup-clojure@master - with: - lein: '2.11.2' - name: Show versions run: | java -version - lein version - name: Cache dependencies uses: actions/cache@v4 with: path: | ~/.m2 - ~/.lein key: clj-cache-test-${{ hashFiles('project.clj') }} restore-keys: | clj-cache-test- - name: Run tests - run: lein test-integration + run: make test-integration - name: Run cloverage run: | diff --git a/Makefile b/Makefile index 66404d6..06cd1b1 100644 --- a/Makefile +++ b/Makefile @@ -11,23 +11,23 @@ lint: .PHONY: install install: - lein install + clojure -T:build install .PHONY: test test: - lein test-all + clojure -M:dev:test unit + clojure -M:dev:1.9:test unit + clojure -M:dev:1.10:test unit .PHONY: test-integration test-integration: - lein test-integration + clojure -M:dev:test it + clojure -M:dev:1.9:test it + clojure -M:dev:1.10:test it .PHONY: outdated outdated: - lein antq - -.PHONY: coverage -coverage: - lein cloverage + clojure -Tantq outdated .PHONY: benchmark benchmark: @@ -36,8 +36,8 @@ benchmark: .PHONY: deploy deploy: - lein deploy clojars + clojure -T:build deploy .PHONY: clean clean: - lein clean + rm -rf target diff --git a/build.clj b/build.clj new file mode 100644 index 0000000..95f030d --- /dev/null +++ b/build.clj @@ -0,0 +1,32 @@ +(ns build + (:require + [clojure.string :as str] + [build-edn.main])) + +(def ^:private config + {:lib 'toyokumo/tarayo + :version (str/trim (slurp "resources/VERSION")) + :description "SMTP client library for Clojure. That’s it." + :url "https://github.com/toyokumo/tarayo" + :licenses [{:name "Apache, Version 2.0" + :url "http://www.apache.org/licenses/LICENSE-2.0"}]}) + +(defmacro defwrapper [fn] + `(defn ~fn [m#] + (~(symbol (str "build-edn.main/" fn)) (merge config m#)))) + +(defwrapper pom) +(defwrapper jar) +(defwrapper java-compile) +(defwrapper uberjar) +(defwrapper install) +(defwrapper deploy) +(defwrapper update-documents) +(defwrapper lint) +(defwrapper bump-patch-version) +(defwrapper bump-minor-version) +(defwrapper bump-major-version) +(defwrapper add-snapshot) +(defwrapper remove-snapshot) +(defwrapper execute) +(defwrapper help) diff --git a/deps.edn b/deps.edn new file mode 100644 index 0000000..ee2994b --- /dev/null +++ b/deps.edn @@ -0,0 +1,32 @@ +{:paths ["src" "resources"] + + :deps + {org.clojure/clojure {:mvn/version "1.11.1"} + camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"} + org.eclipse.angus/angus-mail {:mvn/version "2.0.3"} + commons-codec/commons-codec {:mvn/version "1.16.1"} + jakarta.mail/jakarta.mail-api {:mvn/version "2.1.3"} + nano-id/nano-id {:mvn/version "1.1.0"} + org.apache.tika/tika-core {:mvn/version "2.9.1"}} + + :aliases + {:1.9 {:override-deps {org.clojure/clojure {:mvn/version "1.9.0"}}} + :1.10 {:override-deps {org.clojure/clojure {:mvn/version "1.10.3"}}} + + :dev {:extra-deps {com.github.kirviq/dumbster {:mvn/version "1.7.1"} + testdoc/testdoc {:mvn/version "1.4.1"} + ;; for stubbing + com.gearswithingears/shrubbery {:mvn/version "0.4.1"} + lambdaisland/kaocha {:mvn/version "1.91.1392"} + lambdaisland/kaocha-cloverage {:mvn/version "1.1.89"} + lambdaisland/deep-diff2 {:mvn/version "2.11.216"} + ;; for integration test + org.clojure/data.json {:mvn/version "2.5.0"} + http-kit/http-kit {:mvn/version "2.7.0"}} + :extra-paths ["test" "dev/src" "dev/resources"] + :global-vars {*warn-on-reflection* true}} + + :test {:main-opts ["-m" "kaocha.runner"]} + + :build {:deps {com.github.liquidz/build.edn {:mvn/version "0.11.266"}} + :ns-default build}}} diff --git a/integration/test/tarayo/integration/send_test.clj b/integration/test/tarayo/integration/send_test.clj index 96b1aac..ff433b8 100644 --- a/integration/test/tarayo/integration/send_test.clj +++ b/integration/test/tarayo/integration/send_test.clj @@ -85,7 +85,7 @@ (with-open [conn (core/connect mailhog-server)] (core/send! conn {:from from :to "alice@example.com" :subject "hello" :body [{:content-type "text/plain" :content "world"} - {:content (io/file "project.clj")}]})) + {:content (io/file "build.clj")}]})) (let [resp (find-mail-by-from from) item (get-in resp [:items 0]) mime-parts (->> (get-in item [:mime :parts]) @@ -104,7 +104,7 @@ (let [{:keys [headers body]} (second mime-parts)] (t/is (= ["text/x-clojure"] (:content-type headers))) - (t/is (= ["attachment; filename=project.clj"] (:content-disposition headers))) + (t/is (= ["attachment; filename=build.clj"] (:content-disposition headers))) (t/is (and (string? body) (not (str/blank? body)))))))) (t/deftest send-multipart-alternative-mail-test diff --git a/project.clj b/project.clj deleted file mode 100644 index ea020d7..0000000 --- a/project.clj +++ /dev/null @@ -1,43 +0,0 @@ -(defproject toyokumo/tarayo - #=(clojure.string/trim #=(slurp "resources/VERSION")) - :description "SMTP client library for Clojure. That’s it." - :url "https://github.com/toyokumo/tarayo" - :license {:name "Apache, Version 2.0" - :url "http://www.apache.org/licenses/LICENSE-2.0"} - - :repositories [["clojars" {:url "https://clojars.org/repo" - :sign-releases false}]] - - :dependencies [[camel-snake-kebab "0.4.3"] - [org.eclipse.angus/angus-mail "2.0.3"] - [commons-codec "1.16.1"] - [jakarta.mail/jakarta.mail-api "2.1.3"] - [nano-id "1.1.0"] - [org.apache.tika/tika-core "2.9.1"]] - - :profiles - {:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]} - :1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]} - :1.10 {:dependencies [[org.clojure/clojure "1.10.3"]]} - - :dev {:dependencies [[org.clojure/clojure "1.11.1"] - [com.github.kirviq/dumbster "1.7.1"] - [testdoc "1.4.1"] - ;; for stubbing - [com.gearswithingears/shrubbery "0.4.1"]] - :source-paths ["dev/src" "src"] - :resource-paths ["dev/resources"] - :global-vars {*warn-on-reflection* true}} - - :it {:dependencies [[org.clojure/data.json "2.5.0"] - [http-kit "2.7.0"]] - :test-paths ["integration/test"]} - - :antq {:dependencies [[com.github.liquidz/antq "RELEASE"]]}} - :aliases - {"test-all" ["with-profile" "1.8,dev:1.9,dev:1.10,dev:dev" "test"] - "test-integration" ["with-profile" "1.9,dev,it:1.10,dev,it" "test"] - "antq" ["with-profile" "+antq" "run" "-m" "antq.core"]} - - :plugins [[lein-cloverage "1.2.4"]] - :cloverage {:ns-exclude-regex [#"benchmark"]}) diff --git a/test/tarayo/mail/mime/multipart/body_test.clj b/test/tarayo/mail/mime/multipart/body_test.clj index 2348d86..429920e 100644 --- a/test/tarayo/mail/mime/multipart/body_test.clj +++ b/test/tarayo/mail/mime/multipart/body_test.clj @@ -27,15 +27,15 @@ (t/deftest make-bodypart-test (t/testing "inline" - (let [part {:content (io/file "project.clj") :id (str (gensym))} + (let [part {:content (io/file "build.clj") :id (str (gensym))} bp (sut/make-bodypart part "UTF-8")] (t/is (instance? MimeBodyPart bp)) (t/is (= ["text/x-clojure"] (seq (.getHeader bp "Content-Type")))) - (t/is (= "project.clj" (.getFileName bp))) + (t/is (= "build.clj" (.getFileName bp))) (t/is (= "inline" (.getDisposition bp))))) (t/testing "specify content-type" - (let [part {:content (io/file "project.clj") + (let [part {:content (io/file "build.clj") :content-type "text/plain"} bp (sut/make-bodypart part "UTF-8")] (t/is (instance? MimeBodyPart bp)) @@ -43,23 +43,23 @@ (seq (.getHeader bp "Content-Type")))))) (t/testing "attachment" - (let [part {:content (io/file "project.clj")} + (let [part {:content (io/file "build.clj")} bp (sut/make-bodypart part "UTF-8")] (t/is (instance? MimeBodyPart bp)) (t/is (= ["text/x-clojure"] (seq (.getHeader bp "Content-Type")))) - (t/is (= "project.clj" (.getFileName bp))) + (t/is (= "build.clj" (.getFileName bp))) (t/is (= "attachment" (.getDisposition bp))))) (t/testing "attachment by path string" - (let [part {:content (io/file "project.clj")} + (let [part {:content (io/file "build.clj")} bp (sut/make-bodypart part "UTF-8")] (t/is (instance? MimeBodyPart bp)) (t/is (= ["text/x-clojure"] (seq (.getHeader bp "Content-Type")))) - (t/is (= "project.clj" (.getFileName bp))) + (t/is (= "build.clj" (.getFileName bp))) (t/is (= "attachment" (.getDisposition bp))))) (t/testing "overwriting attachment filename" - (let [part {:content (io/file "project.clj") + (let [part {:content (io/file "build.clj") :filename "overwrite.clj"} bp (sut/make-bodypart part "UTF-8")] (t/is (instance? MimeBodyPart bp)) @@ -68,7 +68,7 @@ (t/is (= "attachment" (.getDisposition bp)))))) (t/deftest make-bodypart-with-content-id-test - (let [part {:content (io/file "project.clj") :id "foo-id"} + (let [part {:content (io/file "build.clj") :id "foo-id"} bp (sut/make-bodypart part "UTF-8")] (t/is (instance? MimeBodyPart bp)) (t/is (= "" (.getContentID bp))))) @@ -82,7 +82,7 @@ (.getFileName bp))))) (t/deftest make-bodypart-with-content-encoding-test - (let [part {:content (io/file "project.clj") + (let [part {:content (io/file "build.clj") :content-encoding "base64"} bp (sut/make-bodypart part "UTF-8")] (t/is (instance? MimeBodyPart bp)) @@ -90,7 +90,7 @@ (t/deftest make-bodypart-with-bytes-attachment-test (t/testing "positive" - (let [file (io/file "project.clj") + (let [file (io/file "build.clj") part {:content (Files/readAllBytes (.toPath file)) :content-type "text/x-clojure" :filename "foo.clj"} diff --git a/test/tarayo/mail/mime/multipart_test.clj b/test/tarayo/mail/mime/multipart_test.clj index cf0e2a6..94f1845 100644 --- a/test/tarayo/mail/mime/multipart_test.clj +++ b/test/tarayo/mail/mime/multipart_test.clj @@ -13,7 +13,7 @@ (t/deftest make-multipart-test (let [mp (sut/make-multipart "mixed" [{:content-type "text/html" :content "foo"} - {:content (io/file "project.clj")}] + {:content (io/file "build.clj")}] "UTF-8")] (t/is (instance? MimeMultipart mp)) (t/is (= 2 (.getCount mp))) @@ -28,7 +28,7 @@ (t/is (= "foo" (.getContent html))) (t/is (= "text/html; charset=UTF-8" (.getContentType html))) - (t/is (= "project.clj" (.getFileName attach))) + (t/is (= "build.clj" (.getFileName attach))) (t/is (= "text/x-clojure" (.getContentType attach)))))) (t/deftest make-multipart-alternative-test diff --git a/tests.edn b/tests.edn new file mode 100644 index 0000000..da0fd73 --- /dev/null +++ b/tests.edn @@ -0,0 +1,14 @@ +#kaocha/v1 +{:tests [{:id :unit + :test-paths ["test"]} + {:id :it + :test-paths ["integration/test"]}] + :fail-fast? true + :color? true + :reporter [kaocha.report/documentation] + :plugins [:kaocha.plugin/profiling + :kaocha.plugin/print-invocations + :kaocha.plugin/cloverage] + + :cloverage/opts {:src-ns-path ["src"] + :test-ns-path ["test"]}} From 661d04b8500133964061c650649942e5b9f5d83e Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 09:21:52 +0900 Subject: [PATCH 02/12] fix: update copyright year --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index b849e3b..add74fd 100644 --- a/README.adoc +++ b/README.adoc @@ -216,7 +216,7 @@ Example using https://github.com/bguthrie/shrubbery[shrubbery]. == License -Copyright 2020-2023 Toyokumo,Inc. +Copyright 2020-2024 Toyokumo,Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From e290691913464d6e4f81214e2d462abb0b7847a7 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 09:23:03 +0900 Subject: [PATCH 03/12] feat: bump version: v0.2.7 -> 0.2.8 --- resources/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/VERSION b/resources/VERSION index b003284..a45be46 100644 --- a/resources/VERSION +++ b/resources/VERSION @@ -1 +1 @@ -0.2.7 +0.2.8 From 56dd068479a0daf8ed468d548910afed44fc3a86 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 09:50:20 +0900 Subject: [PATCH 04/12] remove :global-vars; :global-vars is interpreted only for leiningen --- deps.edn | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deps.edn b/deps.edn index ee2994b..56d70e8 100644 --- a/deps.edn +++ b/deps.edn @@ -23,8 +23,7 @@ ;; for integration test org.clojure/data.json {:mvn/version "2.5.0"} http-kit/http-kit {:mvn/version "2.7.0"}} - :extra-paths ["test" "dev/src" "dev/resources"] - :global-vars {*warn-on-reflection* true}} + :extra-paths ["test" "dev/src" "dev/resources"]} :test {:main-opts ["-m" "kaocha.runner"]} From d1e5e1dd7efa5e9c785b8d681783125925c89151 Mon Sep 17 00:00:00 2001 From: liquidz Date: Wed, 7 Aug 2024 10:30:47 +0900 Subject: [PATCH 05/12] chore: Update dev alias to enable reflection warnings --- deps.edn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deps.edn b/deps.edn index 56d70e8..2cdee1c 100644 --- a/deps.edn +++ b/deps.edn @@ -25,7 +25,8 @@ http-kit/http-kit {:mvn/version "2.7.0"}} :extra-paths ["test" "dev/src" "dev/resources"]} - :test {:main-opts ["-m" "kaocha.runner"]} + :test {:main-opts ["-e" "(set! *warn-on-reflection* true)" + "-m" "kaocha.runner"]} :build {:deps {com.github.liquidz/build.edn {:mvn/version "0.11.266"}} :ns-default build}}} From 008f131626018076cdb817415c67f3433093bc84 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 10:54:23 +0900 Subject: [PATCH 06/12] fix: use deps.edn for cache key Co-authored-by: Iizuka Masashi --- .github/workflows/lint-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 92695e6..436efe8 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -54,7 +54,7 @@ jobs: with: path: | ~/.m2 - key: clj-cache-test-${{ hashFiles('project.clj') }} + key: clj-cache-test-${{ hashFiles('deps.edn') }} restore-keys: | clj-cache-test- From 5e679c43c1675672f40f766e8799509f8357e921 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 11:07:13 +0900 Subject: [PATCH 07/12] feat: use codecov-action instead of lein --- .github/workflows/lint-and-test.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 436efe8..5899d0a 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -61,7 +61,5 @@ jobs: - name: Run tests run: make test-integration - - name: Run cloverage - run: | - lein cloverage --codecov - bash <(curl -s https://codecov.io/bash) + - name: Upload reports + uses: codecov/codecov-action@v4 From 82597bb548759a019c7e277160c9ffd38a1716b0 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 11:08:35 +0900 Subject: [PATCH 08/12] feat: add `test` make target to test both, unit and integration --- .github/workflows/lint-and-test.yml | 2 +- Makefile | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 5899d0a..21cd1e9 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -59,7 +59,7 @@ jobs: clj-cache-test- - name: Run tests - run: make test-integration + run: make test - name: Upload reports uses: codecov/codecov-action@v4 diff --git a/Makefile b/Makefile index 06cd1b1..3a21457 100644 --- a/Makefile +++ b/Makefile @@ -15,15 +15,21 @@ install: .PHONY: test test: - clojure -M:dev:test unit + clojure -M:dev:1.9:test + clojure -M:dev:1.10:test + clojure -M:dev:test + +.PHONY: test-unit +test-unit: clojure -M:dev:1.9:test unit clojure -M:dev:1.10:test unit + clojure -M:dev:test unit .PHONY: test-integration test-integration: - clojure -M:dev:test it clojure -M:dev:1.9:test it clojure -M:dev:1.10:test it + clojure -M:dev:test it .PHONY: outdated outdated: From 08a7e2dc9159f156838d33add7d551c3267fe598 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 11:12:56 +0900 Subject: [PATCH 09/12] fix: clean .cpcache folder also --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3a21457..cdfa38a 100644 --- a/Makefile +++ b/Makefile @@ -46,4 +46,4 @@ deploy: .PHONY: clean clean: - rm -rf target + rm -rf target .cpcache From f0a6037318bd26ef9762ac93320ec085d84d4c63 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 13:06:09 +0900 Subject: [PATCH 10/12] chore: cljstyle --- build.clj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build.clj b/build.clj index 95f030d..20e2aaf 100644 --- a/build.clj +++ b/build.clj @@ -1,7 +1,7 @@ (ns build (:require - [clojure.string :as str] - [build-edn.main])) + [build-edn.main] + [clojure.string :as str])) (def ^:private config {:lib 'toyokumo/tarayo @@ -11,7 +11,8 @@ :licenses [{:name "Apache, Version 2.0" :url "http://www.apache.org/licenses/LICENSE-2.0"}]}) -(defmacro defwrapper [fn] +(defmacro defwrapper + [fn] `(defn ~fn [m#] (~(symbol (str "build-edn.main/" fn)) (merge config m#)))) From 1806f4b41d030e339b37431c370766e6c638ab3c Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 16:24:48 +0900 Subject: [PATCH 11/12] set `*warn-on-refrection*` in user.clj --- deps.edn | 3 +-- dev/src/user.clj | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 dev/src/user.clj diff --git a/deps.edn b/deps.edn index 2cdee1c..56d70e8 100644 --- a/deps.edn +++ b/deps.edn @@ -25,8 +25,7 @@ http-kit/http-kit {:mvn/version "2.7.0"}} :extra-paths ["test" "dev/src" "dev/resources"]} - :test {:main-opts ["-e" "(set! *warn-on-reflection* true)" - "-m" "kaocha.runner"]} + :test {:main-opts ["-m" "kaocha.runner"]} :build {:deps {com.github.liquidz/build.edn {:mvn/version "0.11.266"}} :ns-default build}}} diff --git a/dev/src/user.clj b/dev/src/user.clj new file mode 100644 index 0000000..0a6f5aa --- /dev/null +++ b/dev/src/user.clj @@ -0,0 +1,3 @@ +(ns user) + +(alter-var-root #'*warn-on-reflection* (constantly true)) From e188ee5075763e63e950329402f17471f96af794 Mon Sep 17 00:00:00 2001 From: Naoya Yamashita Date: Wed, 7 Aug 2024 16:35:41 +0900 Subject: [PATCH 12/12] chore: specify clojure cli version without this, I got `Error: You must specify at least one clojure tool.` --- .github/workflows/lint-and-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/lint-and-test.yml b/.github/workflows/lint-and-test.yml index 21cd1e9..50a8520 100644 --- a/.github/workflows/lint-and-test.yml +++ b/.github/workflows/lint-and-test.yml @@ -44,6 +44,8 @@ jobs: architecture: x64 - uses: DeLaGuardo/setup-clojure@master + with: + cli: 1.11.3.1463 - name: Show versions run: |