Skip to content

Commit

Permalink
Update build files
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmassa committed Mar 8, 2023
1 parent bf125bf commit 2fd7236
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ package-lock.json
package.json
.cljs_node_repl/
out/
.vscode/
84 changes: 45 additions & 39 deletions build.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
(ns build
(:refer-clojure :exclude [test compile])
(:refer-clojure :exclude [test])
(:require [clojure.tools.build.api :as b]
[borkdude.gh-release-artifact :as gh]
[org.corfield.build :as bb])
(:import (clojure.lang ExceptionInfo)))
[deps-deploy.deps-deploy :as dd])
(:import [clojure.lang ExceptionInfo]))

(def org "replikativ")
(def lib 'io.replikativ/zufall)
(def current-commit (b/git-process {:git-args "rev-parse HEAD"}))
(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))
Expand All @@ -17,32 +18,23 @@
(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))
[_]
(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 "Deploy the JAR to Clojars." [opts]
(-> opts
(assoc :lib lib :version version)
(bb/deploy)))
(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)))))
Expand All @@ -51,26 +43,40 @@
(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)))
(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 "replikativ"
(try (gh/overwrite-asset {:org org
:repo (name lib)
:tag version
:commit current-commit
:file jar-file
:content-type "application/java-archive"})
:content-type "application/java-archive"
:draft false})
(catch ExceptionInfo e
(assoc (ex-data e) :failure? true))))

(defn release
[_]
(-> (retry-with-fib-backoff 10 try-release :failure?)
:url
println))
(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}))
21 changes: 10 additions & 11 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
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"}}
:format {:extra-deps {cljfmt/cljfmt {:mvn/version "0.7.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"]}}
:ffix {:extra-deps {cljfmt/cljfmt {:mvn/version "0.8.0"}}
: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}}
:paths ["src"]}
3 changes: 2 additions & 1 deletion template/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<artifactId>zufall</artifactId>
<packaging>jar</packaging>
<name>zufall</name>
<description>Random name generators</description>
<version>0.0.0</version>
<description>Random name generators</description>
<licenses>
<license>
<name>Eclipse</name>
Expand Down

0 comments on commit 2fd7236

Please sign in to comment.