diff --git a/.circleci/config.yml b/.circleci/config.yml index 6bd8ede..671f041 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,81 +3,42 @@ version: 2.1 orbs: tools: replikativ/clj-tools@0 -jobs: - build: - executor: tools/clojurecli - parameters: - build_cljs: - type: boolean - default: false - jarname: - type: string - default: "library" - steps: - - attach_workspace: - at: /home/circleci - - run: - name: Update pom - command: clojure -X:deps mvn-pom - - run: - name: Build - command: clojure -M:jar - no_output_timeout: 5m - - when: - condition: <> - steps: - - run: - name: compile_cljs - command: npx shadow-cljs compile ci - no_output_timeout: 5m - - persist_to_workspace: - root: /home/circleci/ - paths: - - replikativ/replikativ-<>.jar - workflows: build-test-and-deploy: jobs: - tools/setup: - context: dockerhub-deploy + context: docker-deploy setup_cljs: false - - tools/format: - context: dockerhub-deploy + - tools/build: + context: docker-deploy + build_cljs: false requires: - tools/setup - - tools/integrationtest-postgresql-mysql-mssql: - context: dockerhub-deploy + - tools/format: + context: docker-deploy requires: - tools/setup - - build: - jarname: "konserve-jdbc" - build_cljs: false - context: dockerhub-deploy + - tools/integrationtest-postgresql-mysql-mssql: + context: docker-deploy requires: - - tools/setup - - tools/deploy-snapshot: - jarname: "konserve-jdbc" + - tools/format + - tools/build + - tools/deploy: context: - clojars-deploy - - dockerhub-deploy + - docker-deploy filters: branches: - only: development + only: main requires: - - tools/setup - - tools/format - tools/integrationtest-postgresql-mysql-mssql - - build - - tools/deploy-release: - jarname: "konserve-jdbc" + - tools/release: context: - - clojars-deploy - - dockerhub-deploy + - github-token + - docker-deploy filters: branches: - only: master + only: main requires: - - tools/setup - - tools/format - - tools/integrationtest-postgresql-mysql-mssql - - build + - tools/deploy + diff --git a/.github/FUNDING.yaml b/.github/FUNDING.yaml new file mode 100644 index 0000000..bbeb446 --- /dev/null +++ b/.github/FUNDING.yaml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: replikativ diff --git a/build.clj b/build.clj new file mode 100644 index 0000000..1b979e0 --- /dev/null +++ b/build.clj @@ -0,0 +1,83 @@ +(ns build + (:refer-clojure :exclude [test]) + (:require [clojure.tools.build.api :as b] + [borkdude.gh-release-artifact :as gh] + [deps-deploy.deps-deploy :as dd]) + (:import [clojure.lang ExceptionInfo])) + +(def org "replikativ") +(def lib 'io.replikativ/konserve-jdbc) +(def current-commit (b/git-process {:git-args "rev-parse HEAD"})) +(def version (format "0.1.%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 + [_] + (b/delete {:path "target"})) + +(defn jar + [_] + (b/write-pom {:class-dir class-dir + :src-pom "./template/pom.xml" + :lib lib + :version version + :basis basis + :src-dirs ["src"]}) + (b/copy-dir {:src-dirs ["src" "resources"] + :target-dir class-dir}) + (b/jar {:class-dir class-dir + :jar-file jar-file})) + +(defn deploy + "Don't forget to set CLOJARS_USERNAME and CLOJARS_PASSWORD env vars." + [_] + (dd/deploy {:installer :remote :artifact jar-file + :pom-file (b/pom-path {:lib lib :class-dir class-dir})})) + +(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) + (do (println "Returned: " result) + (if-let [sleep-ms (first idle-times)] + (do (println "Retrying with remaining back-off times (in s): " idle-times) + (Thread/sleep (* 1000 sleep-ms)) + (recur (rest idle-times))) + result)) + result)))) + +(defn try-release [] + (try (gh/overwrite-asset {:org org + :repo (name lib) + :tag version + :commit current-commit + :file jar-file + :content-type "application/java-archive" + :draft false}) + (catch ExceptionInfo e + (assoc (ex-data e) :failure? true)))) + +(defn release + [_] + (println "Trying to release artifact...") + (let [ret (retry-with-fib-backoff 10 try-release :failure?)] + (if (:failure? ret) + (do (println "GitHub release failed!") + (System/exit 1)) + (println (:url ret))))) + +(defn install + [_] + (clean nil) + (jar nil) + (b/install {:basis (b/create-basis {}) + :lib lib + :version version + :jar-file jar-file + :class-dir class-dir})) + diff --git a/deps.edn b/deps.edn index c5e4eaa..5bbaa1e 100644 --- a/deps.edn +++ b/deps.edn @@ -14,11 +14,14 @@ com.mchange/c3p0 {:mvn/version"0.9.5.5"}} :aliases {:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.83.1314"}} :extra-paths ["test"]} - :jar {:extra-deps {seancorfield/depstar {:mvn/version "1.1.136"}} - :main-opts ["-m" "hf.depstar.jar" "replikativ-konserve-jdbc.jar"]} - :deploy {:extra-deps {deps-deploy/deps-deploy {:mvn/version "0.0.12"}} - :main-opts ["-m" "deps-deploy.deps-deploy" "deploy" "replikativ-konserve-jdbc.jar"]} :format {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}} :main-opts ["-m" "cljfmt.main" "check"]} :ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}} - :main-opts ["-m" "cljfmt.main" "fix"]}}} + :main-opts ["-m" "cljfmt.main" "fix"]} + :build {:deps {io.github.clojure/tools.build {:mvn/version "0.9.3"} + slipset/deps-deploy {:mvn/version "0.2.0"} + io.github.borkdude/gh-release-artifact {:git/sha "05f8d8659e6805d513c59447ff41dc8497878462"} + babashka/babashka.curl {:mvn/version "0.1.2"} + babashka/fs {:mvn/version "0.1.6"} + cheshire/cheshire {:mvn/version "5.10.2"}} + :ns-default build}}} diff --git a/pom.xml b/template/pom.xml similarity index 96% rename from pom.xml rename to template/pom.xml index e8908cb..e0677eb 100644 --- a/pom.xml +++ b/template/pom.xml @@ -4,7 +4,6 @@ jar io.replikativ konserve-jdbc - 0.1.4 A generic JDBC backend for konserve. src