-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.clj
82 lines (73 loc) · 2.75 KB
/
build.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(ns build
(:require [build-shared :as shared]
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]))
(def lib 'org.cljdoc/cljdoc-exerciser)
(def version (let [version-template (-> "version.edn" slurp edn/read-string)
patch (b/git-count-revs nil)]
(str (:major version-template) "."
(:minor version-template) "."
patch
(when (:qualifier version-template) (str "-")))))
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "target/%s.jar" (name lib)))
(def built-jar-version-file "target/built-jar-version.txt")
(defn jar
"Build library jar file.
We use the optional :version-suffix to distinguish local installs from production releases.
For example, when preview for cljdoc, we use the suffix: cjdoc-preview."
[{:keys [version-suffix]}]
(b/delete {:path class-dir})
(b/delete {:path jar-file})
(let [version (if version-suffix (format "%s-%s" version version-suffix)
version)]
(b/write-pom {:class-dir class-dir
:lib lib
:version version
:scm {:tag (format "v%s" 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})
(spit built-jar-version-file version)))
(defn- built-version* []
(when (not (.exists (io/file built-jar-version-file)))
(throw (ex-info (str "Built jar version file not found: " built-jar-version-file) {})))
(slurp built-jar-version-file))
(defn built-version
;; NOTE: Used by release script and github workflow
"Spit out version of jar built (with no trailing newline).
A separate task because I don't know what build.tools might spit to stdout."
[_]
(print (built-version*))
(flush))
(defn install
"Install built jar to local maven repo"
[_]
(let [version (built-version*)]
(b/install {:class-dir class-dir
:lib lib
:version version
:basis basis
:jar-file jar-file})
(println "Installed version" lib version)))
(defn project-lib
"Returns project groupid/artifactid"
[_]
(println lib))
;;
;; GitHub Actions deploy support, called from action only
;;
(defn ci-deploy [_]
(if (shared/ci-release?)
(do
(println "Releasing to clojars...")
(dd/deploy {:installer :remote
:artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}))
(throw (ex-info "Must be run from CI service" {}))))