From 6e865b3c9b8d1e8d6c6ecc58b60101155f52a00d Mon Sep 17 00:00:00 2001 From: JMassa Date: Wed, 8 Mar 2023 15:03:10 +0100 Subject: [PATCH] port to deps.edn and common ci --- .circleci/config.yml | 47 ++++++++++++++++++++++++++ .clj-kondo/config.edn | 1 + .gitignore | 7 ++++ bin/kaocha | 3 ++ bin/run-cljstests | 9 +++++ bin/run-unittests | 3 ++ build.clj | 76 +++++++++++++++++++++++++++++++++++++++++++ deps.edn | 19 +++++++++++ project.clj | 7 ---- tests.edn | 11 +++++++ 10 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 .clj-kondo/config.edn create mode 100755 bin/kaocha create mode 100755 bin/run-cljstests create mode 100755 bin/run-unittests create mode 100644 build.clj create mode 100644 deps.edn delete mode 100644 project.clj create mode 100644 tests.edn diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..b6f2291 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,47 @@ +version: 2.1 + +orbs: + tools: replikativ/clj-tools@0 + +workflows: + build_test_and_deploy: + jobs: + - tools/setup: + context: dockerhub-deploy + - tools/unittest: + context: dockerhub-deploy + requires: + - tools/setup + #- tools/cljstest: + # context: docker-deploy + # requires: + # - tools/build + #- tools/format: + # context: dockerhub-deploy + # requires: + # - tools/setup + - tools/build: + context: dockerhub-deploy + requires: + - tools/setup + - tools/deploy: + context: + - dockerhub-deploy + - clojars-deploy + filters: + branches: + only: main + requires: + - tools/unittest + # - tools/cljstest + # - tools/format + - tools/build + - tools/release: + context: + - dockerhub-deploy + - github-token + filters: + branches: + only: main + requires: + - tools/deploy diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 0000000..1b5718c --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1 @@ +{:linters {:clojure-lsp/unused-public-var {:exclude [build]}}} \ No newline at end of file diff --git a/.gitignore b/.gitignore index d18f225..f69a8db 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,10 @@ pom.xml.asc /.nrepl-port .hgignore .hg/ +.cache +.cpcache +node_modules/ +package-lock.json +package.json +.cljs_node_repl/ +out/ diff --git a/bin/kaocha b/bin/kaocha new file mode 100755 index 0000000..9129d37 --- /dev/null +++ b/bin/kaocha @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +clojure -M:test "$@" diff --git a/bin/run-cljstests b/bin/run-cljstests new file mode 100755 index 0000000..fad3f42 --- /dev/null +++ b/bin/run-cljstests @@ -0,0 +1,9 @@ +set -o errexit +set -o pipefail + +echo "Running tests for node" +[ -d "node_modules/ws" ] || npm install ws +clojure -M:test --focus unit-node + +echo "Running tests for browser" +clojure -M:test --focus unit-browser diff --git a/bin/run-unittests b/bin/run-unittests new file mode 100755 index 0000000..e152a7f --- /dev/null +++ b/bin/run-unittests @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +clojure -M:test --focus unit "$@" diff --git a/build.clj b/build.clj new file mode 100644 index 0000000..1ad7950 --- /dev/null +++ b/build.clj @@ -0,0 +1,76 @@ +(ns build + (:refer-clojure :exclude [test compile]) + (:require [clojure.tools.build.api :as b] + [borkdude.gh-release-artifact :as gh] + [org.corfield.build :as bb]) + (:import (clojure.lang ExceptionInfo))) + +(def lib 'io.replikativ/zufall) +(def version (format "0.2.%s" (b/git-count-revs nil))) +(def current-commit (gh/current-commit)) +(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 + [_] + (b/delete {:path "target"})) + +(defn jar + [opts] + (-> opts + (assoc :class-dir class-dir + :src-pom "./template/pom.xml" + :lib lib + :version version + :basis basis + :jar-file jar-file + :src-dirs ["src"]) + bb/jar)) + +(defn ci "Run the CI pipeline of tests (and build the JAR)." [opts] + (-> opts + (assoc :lib lib :version version) + (bb/clean) + (bb/jar))) + +(defn install "Install the JAR locally." [opts] + (-> opts + jar + bb/install)) + +(defn deploy "Deploy the JAR to Clojars." [opts] + (-> opts + (assoc :lib lib :version version) + (bb/deploy))) + +(defn fib [a b] + (lazy-seq (cons a (fib b (+ a b))))) + +(defn retry-with-fib-backoff [retries exec-fn test-fn] + (loop [idle-times (take retries (fib 1 2))] + (let [result (exec-fn)] + (if (test-fn result) + (when-let [sleep-ms (first idle-times)] + (println "Returned: " result) + (println "Retrying with remaining back-off times (in s): " idle-times) + (Thread/sleep (* 1000 sleep-ms)) + (recur (rest idle-times))) + result)))) + +(defn try-release [] + (try (gh/overwrite-asset {:org "replikativ" + :repo (name lib) + :tag version + :commit current-commit + :file jar-file + :content-type "application/java-archive"}) + (catch ExceptionInfo e + (assoc (ex-data e) :failure? true)))) + +(defn release + [_] + (-> (retry-with-fib-backoff 10 try-release :failure?) + :url + println)) + diff --git a/deps.edn b/deps.edn new file mode 100644 index 0000000..9e82580 --- /dev/null +++ b/deps.edn @@ -0,0 +1,19 @@ +{:deps {org.clojure/clojure {:mvn/version "1.11.1"}} + :aliases {:test {:main-opts ["-m" "kaocha.runner"] + :extra-deps {org.clojure/clojurescript {:mvn/version "1.11.60"} + lambdaisland/kaocha {:mvn/version "1.71.1119"} + lambdaisland/kaocha-cljs {:mvn/version "1.4.130"}} + :extra-paths ["test"]} + :format {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}} + :main-opts ["-m" "cljfmt.main" "check"]} + :build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.8.2" + :git/sha "0ffdb4c"} + borkdude/gh-release-artifact {:git/url "https://github.com/borkdude/gh-release-artifact" + :sha "a83ee8da47d56a80b6380cbb6b4b9274048067bd"} + babashka/babashka.curl {:mvn/version "0.1.1"} + babashka/fs {:mvn/version "0.1.2"} + cheshire/cheshire {:mvn/version "5.10.2"}} + :ns-default build} + :ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.0"}} + :main-opts ["-m" "cljfmt.main" "fix"]}} + :paths ["src"]} diff --git a/project.clj b/project.clj deleted file mode 100644 index 7643761..0000000 --- a/project.clj +++ /dev/null @@ -1,7 +0,0 @@ -(defproject io.replikativ/zufall "0.1.0" - :description "Random name generators" - :url "https://github.com/replikativ/zufall" - :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" - :url "https://www.eclipse.org/legal/epl-2.0/"} - :dependencies [[org.clojure/clojure "1.10.0"]] - :repl-options {:init-ns zufall.core}) diff --git a/tests.edn b/tests.edn new file mode 100644 index 0000000..3ab7ee8 --- /dev/null +++ b/tests.edn @@ -0,0 +1,11 @@ +#kaocha/v1 {:tests [{:id :unit} + {:id :unit-node ;; Throws known kaocha error + :type :kaocha.type/cljs + :cljs/repl-env cljs.repl.node/repl-env + :timeout 30000} + {:id :unit-browser + :type :kaocha.type/cljs + :cljs/repl-env cljs.repl.browser/repl-env + :timeout 30000}] + :bindings {kaocha.type.cljs/*debug* true} + :reporter kaocha.report/documentation}