|
| 1 | +(ns build |
| 2 | + (:require [clojure.edn :as edn] |
| 3 | + [clojure.java.io :as io] |
| 4 | + [clojure.tools.build.api :as b] |
| 5 | + [deps-deploy.deps-deploy :as dd])) |
| 6 | + |
| 7 | +(def lib 'org.cljdoc/cljdoc-exerciser) |
| 8 | +(def version (let [version-template (-> "version.edn" slurp edn/read-string) |
| 9 | + patch (b/git-count-revs nil)] |
| 10 | + (str (:major version-template) "." |
| 11 | + (:minor version-template) "." |
| 12 | + patch |
| 13 | + (when (:qualifier version-template) (str "-"))))) |
| 14 | +(def class-dir "target/classes") |
| 15 | +(def basis (b/create-basis {:project "deps.edn"})) |
| 16 | +(def jar-file (format "target/%s.jar" (name lib))) |
| 17 | +(def built-jar-version-file "target/built-jar-version.txt") |
| 18 | + |
| 19 | +(defn jar |
| 20 | + "Build library jar file. |
| 21 | + We use the optional :version-suffix to distinguish local installs from production releases. |
| 22 | + For example, when preview for cljdoc, we use the suffix: cjdoc-preview." |
| 23 | + [{:keys [version-suffix]}] |
| 24 | + (b/delete {:path class-dir}) |
| 25 | + (b/delete {:path jar-file}) |
| 26 | + (let [version (if version-suffix (format "%s-%s" version version-suffix) |
| 27 | + version)] |
| 28 | + (b/write-pom {:class-dir class-dir |
| 29 | + :lib lib |
| 30 | + :version version |
| 31 | + :scm {:tag (format "v%s" version)} |
| 32 | + :basis basis |
| 33 | + :src-dirs ["src"]}) |
| 34 | + (b/copy-dir {:src-dirs ["src" "resources"] |
| 35 | + :target-dir class-dir}) |
| 36 | + (b/jar {:class-dir class-dir |
| 37 | + :jar-file jar-file}) |
| 38 | + (spit built-jar-version-file version))) |
| 39 | + |
| 40 | +(defn- built-version* [] |
| 41 | + (when (not (.exists (io/file built-jar-version-file))) |
| 42 | + (throw (ex-info (str "Built jar version file not found: " built-jar-version-file) {}))) |
| 43 | + (slurp built-jar-version-file)) |
| 44 | + |
| 45 | +(defn built-version |
| 46 | + ;; NOTE: Used by release script and github workflow |
| 47 | + "Spit out version of jar built (with no trailing newline). |
| 48 | + A separate task because I don't know what build.tools might spit to stdout." |
| 49 | + [_] |
| 50 | + (print (built-version*)) |
| 51 | + (flush)) |
| 52 | + |
| 53 | + |
| 54 | +(defn install |
| 55 | + "Install built jar to local maven repo" |
| 56 | + [_] |
| 57 | + (b/install {:class-dir class-dir |
| 58 | + :lib lib |
| 59 | + :version (built-version*) |
| 60 | + :basis basis |
| 61 | + :jar-file jar-file})) |
| 62 | + |
| 63 | +(defn project-lib |
| 64 | + "Returns project groupid/artifactid" |
| 65 | + [_] |
| 66 | + (println lib)) |
| 67 | + |
| 68 | +;; |
| 69 | +;; GitHub Actions deploy support, called from action only |
| 70 | +;; |
| 71 | + |
| 72 | +;; a request to release is done by tagging with "latest" |
| 73 | +(defn ci-release? [] |
| 74 | + (and (= "tag" (System/getenv "GITHUB_REF_TYPE")) |
| 75 | + (= "latest" (System/getenv "GITHUB_REF_NAME")))) |
| 76 | + |
| 77 | +(defn ci-deploy [_] |
| 78 | + (if (ci-release?) |
| 79 | + (do |
| 80 | + (println "Releasing to clojars...") |
| 81 | + (dd/deploy {:installer :remote |
| 82 | + :artifact jar-file |
| 83 | + :pom-file (b/pom-path {:lib lib :class-dir class-dir})})) |
| 84 | + (println "Not on CI service, skipping deploy"))) |
| 85 | + |
| 86 | +(defn ci-version-tag [_] |
| 87 | + (if (ci-release?) |
| 88 | + (let [tag-version (built-version*)] |
| 89 | + (b/git-process {:git-args (format "git tag -a %s -m Release %s" tag-version tag-version)}) |
| 90 | + (b/git-process {:git-args (format "git push origin %s" tag-version)})) |
| 91 | + (println "Not on CI service, skipping version tagging"))) |
0 commit comments