-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb.edn
146 lines (122 loc) · 5.3 KB
/
bb.edn
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{:min-bb-version "1.12.194"
:deps {babashka/fs {:mvn/version "0.5.22"}}
:tasks
{:requires ([babashka.fs :as fs]
[babashka.process :as process]
[clojure.pprint :as pprint]
[clojure.string :as str])
:init (do
(def -zone-id (java.time.ZoneId/of "UTC"))
(def -formatter java.time.format.DateTimeFormatter/ISO_OFFSET_DATE_TIME)
(def -timestamp (.format (java.time.ZonedDateTime/now -zone-id) -formatter))
(defn execute
[cmd]
(some->> cmd
(process/tokenize)
(process/process)
:out
(slurp)
(str/trim-newline)))
(defn pretty-print
([x]
(pretty-print x {}))
([x {:keys [right-margin]
:or {right-margin 80}}]
(binding [*print-namespace-maps* false
pprint/*print-right-margin* right-margin]
(pprint/pprint x))))
(def -organization "lazy-cat-io")
(def -repository "tenet")
(def -lib "io.lazy-cat/tenet")
(def -branch (-> (execute "git rev-parse --abbrev-ref HEAD") (str/lower-case)))
(def -commit (-> (execute "git rev-parse --short HEAD") (str/lower-case)))
(def -git-count-revs (-> (execute "git rev-list HEAD --count")))
(def -deployable?
(= "main" -branch))
(def -version
(-> "version.tmpl"
(slurp)
(str/trim-newline)
(str/replace "{{ git-count-revs }}" -git-count-revs)))
(def -meta
{:organization -organization
:repository -repository
:branch -branch
:commit -commit
:version -version
:timestamp -timestamp}))
:enter (let [{:keys [doc print-doc?]
:or {print-doc? true}} (current-task)]
(when (and print-doc? doc)
(println (format "\n▸ [%s v%s] %s" -lib -version doc))))
;;
;; Tasks
;;
version {:doc "Show version"
:print-doc? false
:override-builtin true
:task (println -version)}
setup {:doc "Setup dependencies"
:task (shell "npm ci")}
outdated {:doc "Check for outdated dependencies"
:task (case (some-> *command-line-args* first str/lower-case)
"upgrade" (shell "clojure -M:nop:outdated --main antq.core --upgrade --force")
(shell "clojure -M:nop:outdated --main antq.core"))}
clean {:doc "Run cleanup"
:task (doseq [dir ["target" "coverage" "out" ".cljs_node_repl"]]
(println (format "Removing %s..." dir))
(fs/delete-tree dir))}
lint {:doc "Run linters"
:task (case (some-> *command-line-args* first str/lower-case)
"fix" (shell "cljfmt fix src")
(do
(shell "cljfmt check src")
(shell "clj-kondo --lint src")))}
repl {:doc "Run nREPL"
:override-builtin true
:depends [clean -build:meta]
:task (shell "clj -M:bench:test:develop --main nrepl.cmdline --interactive --middleware '[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]'")}
-test:bb {:doc "Run babashka tests"
:task (shell "./src/test/bb/runner.clj")}
-test:clj {:doc "Run clojure tests"
:task (shell "clojure -M:nop:test --main kaocha.runner --focus :clojure")}
-test:cljs {:doc "Run clojurescript tests"
:task (shell "clojure -M:nop:test --main kaocha.runner --focus :clojurescript")}
-test:all {:task (do
(shell "clojure -M:nop:test --main kaocha.runner")
(run '-test:bb))}
test {:doc "Run tests"
:depends [clean]
:task (case (some-> *command-line-args* first str/lower-case)
"all" (run '-test:all)
"bb" (run 'test:bb)
"clj" (run 'test:clj)
"cljs" (run 'test:cljs)
(shell (str/join \space (into ["clojure -M:nop:test --main kaocha.runner"] *command-line-args*))))}
-build:meta {:doc "Build metadata"
:task (do
(fs/create-dirs "src/main/resources/io/lazy-cat/tenet")
(->> -meta
(pretty-print)
(with-out-str)
(spit "src/main/resources/io/lazy-cat/tenet/meta.edn")))}
-build:jar {:doc "Build jar"
:depends [clean -build:meta]
:task (shell (format "clojure -T:build jar :version '\"%s\"'" -version))}
build {:doc "Run build"
:print-doc? false
:task (case (some-> *command-line-args* first str/lower-case)
"meta" (run '-build:meta)
"jar" (run '-build:jar)
(run '-build:jar))}
install {:doc "Install jar"
:depends [-build:jar]
:task (shell "clojure -T:build install")}
deploy {:doc "Deploy jar"
:task (if-not -deployable?
(do
(println "Allowed branches: main, develop")
(println (format "Current branch: %s" -branch)))
(do
(run '-build:jar)
(shell "clojure -T:build deploy")))}}}