Skip to content

Commit

Permalink
ci: switch to replikativ workflow (#24)
Browse files Browse the repository at this point in the history
Close #22
Close #23
  • Loading branch information
TimoKramer committed May 23, 2023
1 parent d7609c8 commit fad8985
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 83 deletions.
32 changes: 13 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,36 @@ workflows:
- tools/setup:
context: dockerhub-deploy
setup_cljs: false
- tools/format:
- tools/build:
context: dockerhub-deploy
build_cljs: false
requires:
- tools/setup
- tools/integrationtest-postgresql-mysql-mssql:
- tools/format:
context: dockerhub-deploy
requires:
- tools/setup
- tools/build:
jarname: "datahike-jdbc"
- tools/integrationtest-postgresql-mysql-mssql:
context: dockerhub-deploy
requires:
- tools/setup
- tools/deploy-snapshot:
jarname: "datahike-jdbc"
- tools/format
- tools/build
- tools/deploy:
context:
- clojars-deploy
- dockerhub-deploy
filters:
branches:
only: development
only: main
requires:
- tools/setup
- tools/format
- tools/integrationtest-postgresql-mysql-mssql
- tools/build
- tools/deploy-release:
jarname: "datahike-jdbc"
- tools/release:
context:
- clojars-deploy
- github-token
- dockerhub-deploy
filters:
branches:
only: master
only: main
requires:
- tools/setup
- tools/format
- tools/integrationtest-postgresql-mysql-mssql
- tools/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
26 changes: 4 additions & 22 deletions bin/run-integrationtests
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,18 @@ set -o pipefail

trap teardown EXIT

function setup_PG() {
function setup() {
if [ -z ${CIRCLECI} ]; then
echo $(docker run --detach --publish 5432:5432 --env POSTGRES_DB=config-test --env POSTGRES_USER=alice --env POSTGRES_PASSWORD=foo docker.io/postgres:15)
fi
}

function setup_MYSQL() {
if [ -z ${CIRCLECI} ]; then
echo $(docker run --detach --publish 3306:3306 --env MYSQL_RANDOM_ROOT_PASSWORD=true --env MYSQL_DATABASE=config-test --env MYSQL_USER=alice --env MYSQL_PASSWORD=foo docker.io/mysql:8)
fi
}

function setup_MSSQL() {
if [ -z ${CIRCLECI} ]; then
echo $(docker run --detach --publish 1433:1433 --env ACCEPT_EULA=Y --env SA_PASSWORD=passwordA1! --env MSSQL_PID=Developer --env MSSQL_TCP_PORT=1433 mcr.microsoft.com/mssql/server:2019-latest)
echo $(docker-compose -f ./docker-compose.yml up --detach)
fi
}

function teardown() {
if [ -z ${CIRCLECI} ]; then
docker rm -f ${PG_NAME}
docker rm -f ${MYSQL_NAME}
docker rm -f ${MSSQL_NAME}
docker-compose -f ./docker-compose.yml down
fi
}

PG_NAME=$(setup_PG)
MYSQL_NAME=$(setup_MYSQL)
MSSQL_NAME=$(setup_MSSQL)

sleep 5
setup

TIMBRE_LEVEL=':warn' DATAHIKE_STORE_BACKEND=jdbc DATAHIKE_STORE_CONFIG='{:dbtype "h2" :dbname "datahike"}' clojure -M:test
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/datahike-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}))

38 changes: 15 additions & 23 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
{:deps {org.clojure/clojure {:mvn/version "1.11.1" :scope "provided"}
io.replikativ/konserve-jdbc {:mvn/version "0.1.1"}}
{:deps {org.clojure/clojure {:mvn/version "1.11.1" :scope "provided"}
io.replikativ/konserve-jdbc {:mvn/version "0.1.79"}}
:paths ["src"]
:aliases {:test {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.60.977"}
io.replikativ/datahike {:mvn/version "RELEASE"}}
:extra-deps {lambdaisland/kaocha {:mvn/version "1.84.1335"}
io.replikativ/datahike {:mvn/version "0.6.1541"}}
:main-opts ["-m" "kaocha.runner"]}

:repl {:extra-deps {cider/cider-nrepl {:mvn/version "0.27.4"}
nrepl/nrepl {:mvn/version "0.9.0"}
org.clojure/tools.namespace {:mvn/version "1.2.0"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

:jar {:extra-deps {com.github.seancorfield/depstar {:mvn/version "1.1.136"}}
:main-opts ["-m" "hf.depstar.jar" "replikativ-konserve-jdbc.jar"]}

:deploy {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.0"}}
:main-opts ["-m" "deps-deploy.deps-deploy" "deploy" "replikativ-datahike-jdbc.jar"]}

:install {:extra-deps {slipset/deps-deploy {:mvn/version "0.2.0"}}
:exec-fn deps-deploy.deps-deploy/deploy
:exec-args {:installer :local
:artifact "replikativ-datahike-jdbc.jar"}}

:format {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:format {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}}
:main-opts ["-m" "cljfmt.main" "check"]}

:ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
:main-opts ["-m" "cljfmt.main" "fix"]}}}
:ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}}
: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}}}
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.3'

services:
mysql:
image: docker.io/mysql:8
restart: always
command: --max_allowed_packet=32505856
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: config-test
MYSQL_USER: alice
MYSQL_PASSWORD: foo
ports:
- 3306:3306

postgres:
image: docker.io/postgres:14
restart: always
environment:
POSTGRES_DB: config-test
POSTGRES_USER: alice
POSTGRES_PASSWORD: foo
ports:
- "5432:5432"

mssql:
image: mcr.microsoft.com/mssql/server:2019-latest
restart: always
environment:
ACCEPT_EULA: Y
SA_PASSWORD: passwordA1!
MSSQL_PID: Developer
MSSQL_TCP_PORT: 1433
ports:
- 1433:1433
20 changes: 1 addition & 19 deletions pom.xml → template/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.replikativ</groupId>
<groupId>org.clojars.timokramer</groupId>
<artifactId>datahike-jdbc</artifactId>
<packaging>jar</packaging>
<name>datahike-jdbc</name>
<description>A JDBC backend for Datahike</description>
<version>0.1.2</version>
<url>https://datahike.io</url>
<licenses>
<license>
Expand All @@ -19,23 +18,6 @@
<developerConnection>scm:git:[email protected]/replikativ/datahike-jdbc.git</developerConnection>
<url>https://github.com/replikativ/datahike-jdbc</url>
</scm>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.10.3</version>
</dependency>
<dependency>
<groupId>io.replikativ</groupId>
<artifactId>konserve-jdbc</artifactId>
<version>0.1.1</version>
</dependency>
<dependency>
<groupId>io.replikativ</groupId>
<artifactId>superv.async</artifactId>
<version>0.2.11</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
</build>
Expand Down

0 comments on commit fad8985

Please sign in to comment.