Skip to content

Commit

Permalink
port to deps.edn and common ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmassa committed Mar 8, 2023
1 parent a1f55cf commit 6e865b3
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 7 deletions.
47 changes: 47 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:linters {:clojure-lsp/unused-public-var {:exclude [build]}}}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ pom.xml.asc
/.nrepl-port
.hgignore
.hg/
.cache
.cpcache
node_modules/
package-lock.json
package.json
.cljs_node_repl/
out/
3 changes: 3 additions & 0 deletions bin/kaocha
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

clojure -M:test "$@"
9 changes: 9 additions & 0 deletions bin/run-cljstests
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions bin/run-unittests
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

clojure -M:test --focus unit "$@"
76 changes: 76 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -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))

19 changes: 19 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -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"]}
7 changes: 0 additions & 7 deletions project.clj

This file was deleted.

11 changes: 11 additions & 0 deletions tests.edn
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 6e865b3

Please sign in to comment.