forked from clj-commons/rewrite-clj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.clj
113 lines (104 loc) · 4.55 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
(ns build
(:require [clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]
[whitespace-linter]))
(def lib 'rewrite-clj/rewrite-clj)
(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
(cond->> (:qualifier version-template)
true (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.
Also writes built version to target/built-jar-version.txt for easy peasy pickup by any interested downstream operation.
We use the optional :version-suffix to distinguish local installs from production releases.
For example, when testing 3rd party libs against rewrite-clj master we use the suffix: canary. "
[{: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"
[_]
(b/install {:class-dir class-dir
:lib lib
:version (built-version*)
:basis basis
:jar-file jar-file}))
(defn deploy
"Deploy built jar to clojars"
[_]
(dd/deploy {:installer :remote
:artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}))
(defn project-lib
"Returns project groupid/artifactid"
[_]
(println lib))
(defn lint-whitespace
"Use camsaul's whitespace-linter"
[_]
(whitespace-linter/lint {:paths [".clj-kondo/config.edn"
".codecov.yml"
".github/"
".gitignore"
"CHANGELOG.adoc"
"CODE_OF_CONDUCT.md"
"CONTRIBUTING.md"
"LICENSE"
"ORIGINATOR"
"README.adoc"
"bb.edn"
"build.clj"
"deps.edn"
"doc/"
"fig.cljs.edn"
"package.json"
"pom.xml"
"resources/"
"script/"
"src/"
"template/"
"test/"
"test-isolated/"
"tests.edn"
"version.edn"]
:include-patterns [#"\.clj.?$" #"\.edn$" #"\.yaml$" #"\.adoc$" #"\.md$"
#"CODEOWNERS$" #"LICENSE$" #"ORIGINATOR$"
#"\.clj-kondo/config.edn"]
:exclude-patterns [;; exclude things generated
#"doc/generated/.*$"
#"src/rewrite_clj/(node|zip)\.cljc$"
#"src/rewrite_clj/node/string\.clj$"
#"src/rewrite_clj/zip/(edit|find|remove|seq)\.clj"]}))