Skip to content

Commit

Permalink
ci: switch to replikativ workflow (#17)
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
TimoKramer authored May 23, 2023
1 parent 8daba5a commit 0b68d31
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 64 deletions.
77 changes: 19 additions & 58 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <<parameters.build_cljs>>
steps:
- run:
name: compile_cljs
command: npx shadow-cljs compile ci
no_output_timeout: 5m
- persist_to_workspace:
root: /home/circleci/
paths:
- replikativ/replikativ-<<parameters.jarname>>.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

3 changes: 3 additions & 0 deletions .github/FUNDING.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: replikativ
83 changes: 83 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -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}))

13 changes: 8 additions & 5 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}
1 change: 0 additions & 1 deletion pom.xml → template/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<packaging>jar</packaging>
<groupId>io.replikativ</groupId>
<artifactId>konserve-jdbc</artifactId>
<version>0.1.4</version>
<description>A generic JDBC backend for konserve.</description>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down

0 comments on commit 0b68d31

Please sign in to comment.