-
Notifications
You must be signed in to change notification settings - Fork 0
/
bb.edn
125 lines (97 loc) · 5.19 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
{:min-bb-version
"0.7.8"
:tasks
{:requires ([babashka.fs :as fs]
[babashka.process :as process]
[clojure.string :as str]
[clojure.pprint :as pprint])
:init (do
(defn get-env [s]
(System/getenv s))
(defn get-property [s]
(System/getProperty s))
(defn pretty-print [x]
(binding [pprint/*print-right-margin* 130]
(pprint/pprint x)))
(defn execute [command]
(-> command (process/tokenize) (process/process) :out slurp str/trim-newline))
(def -zone-id (java.time.ZoneId/of "UTC"))
(def -datetime-formatter java.time.format.DateTimeFormatter/ISO_OFFSET_DATE_TIME)
(def -current-timestamp (java.time.ZonedDateTime/now -zone-id))
(def -build-timestamp (str (.format -current-timestamp -datetime-formatter)))
(def -build-number (execute "git rev-list HEAD --count"))
(def -git-url (execute "git config --get remote.origin.url"))
(def -git-branch (execute "git rev-parse --abbrev-ref HEAD"))
(def -git-sha (execute "git rev-parse --short HEAD"))
(def -release? (= "master" -git-branch))
(def -snapshot? (not -release?))
(def -deployable? (contains? #{"master" "develop"} -git-branch))
(def -version-template (execute "cat version.tmpl"))
(def -version (cond-> (str/replace -version-template "{{build-number}}" -build-number)
-snapshot? (str "-SNAPSHOT")))
(def -config
{:version -version
:build-number -build-number
:build-timestamp -build-timestamp
:git-url -git-url
:git-branch -git-branch
:git-sha -git-sha})
(def extra-env
{:TEST_TOKEN "token_12345"})
(defn as-params [params]
(->> params
(seq)
(flatten)
(map (fn [x]
(str/replace (pr-str x) (java.util.regex.Pattern/compile "(\".+\")") "'$1'")))
(str/join \space)))
(defn with-params [command]
(->> -config
(as-params)
(str command " "))))
:enter (let [{:keys [doc print-doc?]
:or {print-doc? true}} (current-task)]
(when (and print-doc? doc)
(println (str "▸ " doc))))
;;;;
;; Tasks
;;;;
version {:doc "[secret-keeper] Show version"
:print-doc? false
:task (print -version)}
config {:doc "[secret-keeper] Show config"
:print-doc? false
:task (pretty-print -config)}
setup {:doc "[secret-keeper] Setup dependencies"
:task (shell "npm ci")}
outdated {:doc "[secret-keeper] Check for outdated dependencies"
:task (do
(clojure (with-params "-T:build outdated"))
(shell "npx ncu"))}
outdated:upgrade {:doc "[secret-keeper] Upgrade outdated dependencies"
:task (do
(clojure (with-params "-T:build outdated:upgrade"))
(shell "npx ncu -u && npm i"))}
clean {:doc "[secret-keeper] Cleanup"
:task (clojure (with-params "-T:build clean"))}
lint {:doc "[secret-keeper] Run linters"
:task (do
(shell "cljstyle check src")
(shell "clj-kondo --lint src"))}
lint:fix {:doc "[secret-keeper] Run linters & fix"
:task (shell "cljstyle fix src")}
repl {:doc "[secret-keeper] Run REPL"
:depends [clean]
:task (shell {:extra-env extra-env} (with-params "clojure -T:build repl"))}
test {:doc "[secret-keeper] Run tests"
:depends [clean]
:task (shell {:extra-env extra-env} (with-params "clojure -T:build test"))}
jar {:doc "[secret-keeper] Run build jar"
:depends [clean]
:task (clojure (with-params "-T:build jar"))}
install {:doc "[secret-keeper] Install the jar locally"
:task (clojure (with-params "-T:build install"))}
deploy {:doc "[secret-keeper] Deploy the jar to clojars"
:task (if -deployable?
(clojure (with-params "-T:build deploy"))
(println "Skip deploy..."))}}}