From 66f8d6e6d005dda8ebcde151b9b39b510cbe74db Mon Sep 17 00:00:00 2001 From: Timo Kramer Date: Thu, 6 Oct 2022 13:23:33 +0200 Subject: [PATCH] fix: corrected the message indentation on slack - added the fib-backoff-functionality for releases - added build step to README - moved release-functionality to orb --- .circleci/config.yml | 15 +++---------- .gitignore | 1 + README.md | 4 ++++ build.clj | 52 +++++++++++++++++++++++++++----------------- deps.edn | 9 ++++---- resources/config.edn | 4 ++-- 6 files changed, 46 insertions(+), 39 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4e66129..d20b46c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,7 +11,7 @@ jobs: at: /home/circleci - run: name: Build - command: clojure -Sthreads 1 -T:build uber + command: clojure -T:build uber no_output_timeout: 5m - persist_to_workspace: root: /home/circleci/ @@ -25,19 +25,10 @@ jobs: - run: name: Deploy to Docker Hub command: | - clojure -Sthreads 1 \ - -T:build deploy-image \ + clojure -T:build deploy-image \ :docker-login ${DOCKER_LOGIN} \ :docker-password ${DOCKER_PASSWORD} \ no_output_timeout: 5m - release: - executor: tools/clojurecli - steps: - - attach_workspace: - at: /home/circleci - - run: - name: Release - command: clojure -Sthreads 1 -T:build release workflows: build-and-deploy: @@ -63,7 +54,7 @@ workflows: - tools/setup - tools/format - build - - release: + - tools/release: context: - dockerhub-deploy - github-token diff --git a/.gitignore b/.gitignore index f117505..1ecfd4f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .cpcache/ target/ .nrepl-port +.lsp/ diff --git a/README.md b/README.md index fd53d26..8245d33 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ Environment variables: - `TWITTER_ACCESS_TOKEN` - `TWITTER_ACCESS_TOKEN_SECRET` +## Building + +After running `clj -T:build uber` you can find the jar in the target-folder. + ## Running Either via container: https://hub.docker.com/r/replikativ/souffleuse diff --git a/build.clj b/build.clj index 3ced4f5..9d7cec2 100644 --- a/build.clj +++ b/build.clj @@ -1,11 +1,11 @@ (ns build (:require [borkdude.gh-release-artifact :as gh] - [clojure.tools.build.api :as b] - [deps-deploy.deps-deploy :as dd]) + [clojure.tools.build.api :as b]) (:import + [clojure.lang ExceptionInfo] [java.nio.file Paths] - [com.google.cloud.tools.jib.api Jib Containerizer RegistryImage TarImage] + [com.google.cloud.tools.jib.api Jib Containerizer RegistryImage] [com.google.cloud.tools.jib.api.buildplan AbsoluteUnixPath Port])) (def lib 'io.replikativ/souffleuse) @@ -13,7 +13,7 @@ (def current-commit (gh/current-commit)) (def class-dir "target/classes") (def basis (b/create-basis {:project "deps.edn"})) -(def jar-path (format "target/%s-%s.jar" (name lib) version)) +(def jar-file (format "target/%s-%s.jar" (name lib) version)) (def uber-file (format "%s-%s-standalone.jar" (name lib) version)) (def uber-path (format "target/%s" uber-file)) (def image (format "docker.io/replikativ/souffleuse:%s" version)) @@ -37,7 +37,7 @@ (b/copy-dir {:src-dirs ["src" "resources"] :target-dir class-dir}) (b/jar {:class-dir class-dir - :jar-file jar-path})) + :jar-file jar-file})) (defn uber [_] @@ -52,22 +52,35 @@ :basis basis :main 'souffleuse.core})) -(defn deploy - "Don't forget to set CLOJARS_USERNAME and CLOJARS_PASSWORD env vars." - [_] - (dd/deploy {:installer :remote :artifact jar-path - :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) + (if-let [sleep-ms (first idle-times)] + (do (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 "Failed deploying artifact.") + (System/exit 1))) + (println "Successfully created release-draft"))))) + +(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 [_] - (-> (gh/overwrite-asset {:org "replikativ" - :repo (name lib) - :tag version - :commit current-commit - :file uber-path - :content-type "application/java-archive"}) - :url - println)) + (retry-with-fib-backoff 10 try-release :failure?)) (defn install [_] @@ -76,7 +89,7 @@ (b/install {:basis (b/create-basis {}) :lib lib :version version - :jar-file jar-path + :jar-file jar-file :class-dir class-dir})) (defn deploy-image @@ -104,6 +117,5 @@ (uber nil) (deploy-image {:docker-login docker-login :docker-password docker-password}) - (deploy nil) (release nil) (install nil)) diff --git a/deps.edn b/deps.edn index 053ab4c..1be2717 100644 --- a/deps.edn +++ b/deps.edn @@ -23,11 +23,10 @@ :main-opts ["-m" "cljfmt.main" "fix"]} :build {:deps {io.github.clojure/tools.build {:git/tag "v0.7.5" :git/sha "2526f58"} - slipset/deps-deploy {:mvn/version "0.2.0"} 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"} + :sha "b3f5b4ddfa7600191da176a752f161a91f0b8f9c"} + babashka/babashka.curl {:mvn/version "0.1.2"} + babashka/fs {:mvn/version "0.1.11"} com.google.cloud.tools/jib-core {:mvn/version "0.20.0"} - cheshire/cheshire {:mvn/version "5.10.2"}} + cheshire/cheshire {:mvn/version "5.11.0"}} :ns-default build}}} diff --git a/resources/config.edn b/resources/config.edn index 7baa941..0b3c1e3 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -5,8 +5,8 @@ :channel "#datahike"} :github {:token #env GITHUB_TOKEN} :scheduler {:announcement "In a quarter hour we will have our weekly open-source meeting - where we are talking about the latest progress on Datahike and - other replikativ libraries. Please join on " + where we are talking about the latest progress on Datahike and + other replikativ libraries. Please join on " :hour 15 :minute 45} :twitter {:announcement "Version %s of %s was just released. Take a look at the changelog over on GitHub: %s"