forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbb.edn
More file actions
312 lines (285 loc) · 17.2 KB
/
bb.edn
File metadata and controls
312 lines (285 loc) · 17.2 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
{:min-bb-version "1.12.208"
;; we put path as bin, and everything is in the ./mage subdirectory,
;; so the namespaces are mage.cli, mage.format, etc.
:paths ["mage/src" "mage/test" "bin/lint-migrations-file/src"]
:deps {org.babashka/json {:mvn/version "0.1.6"}
metosin/malli {:mvn/version "0.17.0"}
table/table {:mvn/version "0.5.0"}
mvxcvi/puget {:mvn/version "1.3.4"}}
:tasks
{:requires [[mage.cli :as cli]
[mage.color :as c]]
:init (do (defmacro task! "Binds the parsed command line arguments to `parsed`."
[& body]
;; Can't use ` in this file because it is strictly edn!
(list 'let
(vector 'parsed (list 'cli/parse! (list 'current-task)))
(cons 'do body))))
alias
{:doc "Installs 'mage' alias and autocomplete"
:examples [["./bin/mage alias" "Prints instructions to install the 'mage' alias and autocomplete"]
["./bin/mage alias zsh" "Prints shell script to put into .zshrc for zsh users"]]
:requires [[mage.alias :as alias]]
:arg-schema [:or
[:tuple]
[:tuple [:enum "bash" "zsh" "fish"]]]
:task (task! (alias/instructions parsed))}
cljfmt-staged
{:doc "Runs cljfmt on staged files"
:requires [[mage.format :as format]]
:examples [["./bin/mage cljfmt-staged" "Format staged files"]
["./bin/mage cljfmt-staged -c" "Check staged files"]]
:options [["-c" "--force-check" "Check staged files"]]
:task (task! (format/staged parsed))}
cljfmt-files
{:doc "Runs cljfmt on the given files/directories"
:requires [[mage.format :as format]]
:examples [["./bin/mage cljfmt-files src/metabase/events.clj" "Format events.clj"]
["./bin/mage cljfmt-files src" "Format all files in src"]
["./bin/mage cljfmt-files -c src" "Check all files in src"]]
:options [["-c" "--force-check" "Check staged files"]]
:arg-schema [:sequential [:string {:description "Files or directories to format."}]]
:task (task! (format/files parsed))}
cljfmt-all
{:doc "Runs cljfmt on all (clojure) files"
:requires [[mage.format :as format]]
:examples [["./bin/mage cljfmt-all" "Format all files"]]
:options [["-c" "--force-check" "Check staged files"]]
:task (task! (format/all parsed))}
cljfmt-updated
{:doc "Runs cljfmt on all (Clojure) files relative to a git ref (default HEAD)"
:requires [[mage.format :as format]]
:examples [["./bin/mage cljfmt-updated" "Format updated files relative to HEAD"]
["./bin/mage cljfmt-updated master" "Format updated files relative to master"]]
:options [["-c" "--force-check" "Check staged files"]]
:arg-schema [:or [:tuple] [:tuple :string]]
:task (task! (format/updated parsed))}
kondo
{:doc "Runs Kondo against a file, directory, or everything we usually lint"
:examples [["./bin/mage kondo" "run Kondo against everything we usually lint"]
["./bin/mage kondo src/metabase/db.clj" "run Kondo against a file"]
["./bin/mage kondo src/metabase/db.clj src/metabase/config.clj" "run Kondo against 2 files"]
["./bin/mage kondo src/metabase/api/macros" "run Kondo against a directory"]]
:requires [[mage.kondo :as kondo]]
:task (task! (kondo/kondo (:arguments parsed)))}
kondo-updated
{:doc "Runs kondo against files changed compared to a git ref"
:examples [["./bin/mage kondo-updated" "run Kondo on files with changes relative to HEAD"]
["./bin/mage kondo-updated master" "run Kondo on files with changes relative to master"]]
:requires [[mage.kondo :as kondo]]
:task (task! (kondo/kondo-updated (:arguments parsed)))}
check
{:doc "Checks whether we can compile all source files (and finds circular dependencies)"
:examples [["./bin/mage check"]]
:requires [[mage.check]]
:task (task! (mage.check/check (:arguments parsed)))}
start-maildev
{:doc "Start Maildev"
:examples [["./bin/mage start-maildev -h" "print help for start-maildev"]]
:requires [[mage.start-maildev :as start-maildev]]
:task (task! (start-maildev/start-maildev!))}
start-db
{:doc "Start a db on a default port in docker"
:examples [["./bin/mage start-db postgres latest" "start the latest postgres db we support"]
["./bin/mage start-db mysql oldest" "start the oldest mysql db we support"]]
:requires [[mage.start-db :as start-db]]
:arg-schema [:tuple
[:enum :postgres :mysql :mariadb :mongo]
[:enum :oldest :latest]]
:db-info {:postgres {:ports {:oldest 5432 :latest 5433} :eol-url "https://endoflife.date/api/postgres.json"}
:mysql {:ports {:oldest 3308 :latest 3309} :eol-url "https://endoflife.date/api/mysql.json"}
:mariadb {:ports {:oldest 3306 :latest 3307} :eol-url "https://endoflife.date/api/mariadb.json"}
:mongo {:ports {:oldest 27017 :latest 27018} :eol-url "https://endoflife.date/api/mongodb.json"}}
:usage-fn start-db/usage
:task (task!
(let [[db version] (:arguments parsed)]
(start-db/start-db (:db-info (current-task)) db version)))}
nrepl
{:doc "Starts the babashka nrepl: helpful for mage development"
:requires [[babashka.nrepl.server :as nrepl.server]
[mage.color :as c]]
:examples [["./bin/mage nrepl" "Starts the nrepl server"]
["./bin/mage nrepl --port 50506" "Starts the nrepl server"]
["./bin/mage nrepl -p 50506" "Starts the nrepl server"]]
:options [["-p" "--port PORT" "optionally provide a port to run the nrepl server on" :default 1667 :parse-fn Integer/parseInt]]
:task (task!
(let [{:keys [port]} (:options parsed)]
(spit ".nrepl-port" port)
(nrepl.server/start-server! {:port port})
(deref (promise))))}
lint-migrations
{:doc "Lint migrations files"
:requires [[lint-migrations-file]
[babashka.process :as p]]
:examples [["./bin/mage lint-migrations" "Lint all migrations and print report"]]
:task (do (cli/parse! (current-task))
(p/shell "bin/pre-lint-migrations-file.sh")
(lint-migrations-file/-main))}
jar-download
{:doc "Download (and optionally run) jar for a metabase version or branch"
:examples [["./bin/mage jar-download 50" "Download the latest enterprise version of release 50 to ~/path/to/my/metabase/jars"]
["./bin/mage jar-download 1.45.2 -r" "Download and run metabase_1.45.2.jar"]
["./bin/mage jar-download 1.45.2 -d ~/path/to/my/jars" "Download metabase_1.45.2.jar to ~/path/to/my/jars, deleting if it exists"]
["./bin/mage jar-download master --run --port 3001" "Download and run the latest master branch jar on port 3001"]
["JARS=~/my-stuff ./bin/mage jar-download 1.45.2" "Download metabase_1.45.2.jar to ~/my-stuff"]
["./bin/mage jar-download v1.56.0-beta -r" "Download and run metabase_1.56.0-beta.jar"]]
:requires [[mage.jar-download :as jar-download]]
:options [["-r" "--run" "run the new jar after downloading it"]
["-e" "--env-file FILE" "you can optionally provide a lein-env file to specify the environment to use when running the jar."]
["-d" "--delete" "delete the old jar if found, by default does not re-download it"]
["-p" "--port PORT" "you can optionally provide a port to run the jar on, if not, we use a sane port."]]
:arg-schema [:or
[:tuple [:string {:desc "version"}]]
[:tuple [:string {:desc "version"}] [:string {:desc "path"}]]]
:usage-fn (fn [_]
(-> "Version can have the following forms:"
(str "\n -" (c/green "50") " for the latest enterprise version of release 50")
(str "\n -" (c/green "1.45.2") " for a specific version")
(str "\n -" (c/green "master") " for the latest jar created for master")
(str "\n -" (c/green "any-branch-with-a-pr") " for the latest uberjar created for that branch")
(str "\n -" (c/green "1.56.0-beta") " for a specific beta version")
(str "\n\nnote: If you get an error about 'Invalid or corrupt jarfile', run this command again with --delete.")))
:task (task! (jar-download/jar-download parsed))}
setup-stats-repl
{:doc "Connect to the stats repl"
:examples [["./bin/mage connect-stats-repl" "Connects to the stats repl"]]
:requires [[mage.stats-repl :as stats-repl]]
:task (stats-repl/connect (cli/parse! (current-task)))}
notify
{:doc "Send notification for a comment (that already exists)"
:requires [[mage.be-dev :refer [nrepl-eval]]]
:options [["-c" "--comment-id ID" "Notify about this comment id"]
["-p" "--port PORT" "Port to use for the task, defaults to value in .nrepl-port"]]
:task (let [opts (:options (cli/parse! (current-task)))
;; note: no quoting -> expect it to be int
code (format "(notify-comment-id! %d)" (parse-long (:comment-id opts)))]
(if (:port opts)
(nrepl-eval "metabase-enterprise.comments.core" code (:port opts))
(nrepl-eval "metabase-enterprise.comments.core" code)))}
run-tests
{:doc "Run a tests (or a single test) against nrepl server"
:requires [[clojure.string :as str]
[mage.be-dev :refer [nrepl-eval]]]
:arg-schema [:tuple [:string {:name "NS/TEST" :desc "or just NS"}]]
:options [["-p" "--port PORT" "Port to use for the task, defaults to value in .nrepl-port"]]
:task (let [{:keys [options]
[test] :arguments} (cli/parse! (current-task))
test (if (or (str/starts-with? test "test/")
(str/starts-with? test "enterprise/"))
;; paths should come in as strings
(format "\"%s\"" test)
;; ns or var should be a symbol
(str "'" test))
code (format
"(do ((requiring-resolve 'dev.reload/reload!)) (find-and-run-tests-repl {:only %s}))"
test)]
(nrepl-eval "mb.hawk.core" (str code) (:port options)))}
ls {:doc "List all mage public and private tasks"
:examples [["./bin/mage ls" "List all tasks"]]
:requires [[mage.util :as u]]
:task (task! (u/print-tasks parsed))}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Private Tasks:
;; These tasks are more for internal tooling, e.g. for use from git hooks etc.
;; - hidden from `./bin/mage` listing and `bb tasks`, these all - start with a `-`
-token-scan
{:doc "Security token scanner for detecting leaked API keys and secrets"
:examples [["./bin/mage -token-scan deps.edn bb.edn" "Scan specific files"]
["./bin/mage -token-scan -v deps.edn" "Scan with verbose output"]
["./bin/mage -token-scan -a" "Scan all files in the project"]]
:requires [[mage.token-scan :as token-scan]]
:options [["-a" "--all-files" "Scan all files in the project"]
["-v" "--verbose" "Verbose output"]]
:arg-schema [:sequential [:string {:description "Files to scan"}]]
:task (task! (token-scan/run-scan parsed))}
-repl
{:doc "Eval a string of clojure code in the backend dev server"
:requires [[babashka.process :as process]
[mage.color :as c]
[mage.be-dev :refer [nrepl-eval]]]
:examples [["./bin/mage -repl '(+ 1 1)'"
"Eval a form in the backend dev server in the user namespace"]
["./bin/mage -repl --namespace metabase.app-db.connection @application-db-counter"
"Eval a form in the backend dev server in the 'metabase.app-db.connection' namespace"]
["mage -repl --port 59498 --namespace metabase.app-db.connection '(read-string \"::hello\")'"
"Evaluate a keyword inside a namespace"]]
:options [["-n" "--namespace NAMESPACE" "Namespace to use for the task"]
["-p" "--port PORT" "Port to use for the task, defaults to value in .nrepl-port"]]
:task (let [parsed (cli/parse! (current-task))
code (first (:arguments parsed))
port (or (:port (:options parsed))
(slurp ".nrepl-port")
(throw (ex-info (c/red "No port specified, and no .nrepl-port file found.") {:babashka/exit 1})))
nns (or (:namespace (:options parsed)) "user")]
(nrepl-eval nns code port))}
-check-readable
{:doc "Check that code is readable parens a file"
:requires [[mage.readability-check :as readability]]
:arg-schema [:or
[:tuple [:string {:description "File to check"}]]
[:tuple
[:string {:description "File to check"}]
[:int {:description "A line in the file" :min 1}]]]
:examples [["./bin/mage -check-readable dev/src/dev.clj"
"Check file for readability"]
["./bin/mage -check-readable dev/src/dev.clj 300"
"Check top level form containing line 300 for readability"]]
:task (let [{:keys [arguments]} (cli/parse! (current-task))]
(apply readability/check arguments))}
;; Uncomment this if you want to play with the example calculator task:
#_#_
-example-calculator
{;; `:doc` is a short docstring for the task, will be listed in `./bin/mage -h` and other help info.
;; Keep these short, they need to fit on one line in the output from `./bin/mage -h`.
:doc "The example calculator's task docstring"
;; examples get printed out when you pass -h or --help.
:examples [["./bin/mage -example-calculator 1 + 99" "evaluates to 100"]
["./bin/mage -example-calculator 100 - 99" "evaluates to 1"]]
;; The task is the actual code that runs when you run the task.
:task (task!
(println "Parsed input:") (u/pp parsed)
(let [{:keys [arguments data]} parsed
[a op b] arguments]
(println a (name op) b "=" (c/blue (({:+ + :- -} op) a b)))))
;; (optional) `:require` lazily libraries for just your task:
:requires [[mage.color :as c]
[mage.util :as u]]
;; (optional) `:options` are passed to [[clojure.tools.cli/parse-opts]].
;; See: https://clojure.github.io/tools.cli/index.html#clojure.tools.cli/parse-opts
:options [["-n" "--negate" "Negate the result of the calculation"]
["-a" "--also-add N" "Add N to the result of the calculation"]]
;; (optional) `:arg-schema` is a malli schema for the arguments passed to the task, after the options
:arg-schema [:tuple :int [:enum :+ :-] :int]
;; (optional) `:usage-fn` is a function called with the current-task map.
;; Returns a string containing extra-detailed usage information.
:usage-fn (fn [{:keys [doc] :as _task}]
(str "Optional extra usage information, for explicit callouts.\n"
"Reversed docstring: '" (c/green (apply str (reverse doc))) "'"))
;; (optional) Any other keys are completely allowed. Put things to lookup or that you want to be easy to change
;; here. These will be returned from `(current-task)`. See: start-db for an example of using `:ports` to define a
;; top-level map of ports. If something should be easily accessible in the task, put it here.
:data {:a [:b :c] :b [:d]}}
-test {:doc "run all mage tests"
:requires [[mage.core-test]
[clojure.test :refer [run-tests]]]
:task (run-tests 'mage.core-test)}
-test-examples
{:doc "Runs every example and checks that it exits with 0"
:requires [[mage.examples-test :as examples-test]]
:task (System/exit (if (= :ok (examples-test/run-tests)) 0 1))}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Personal Tasks:
;; These tasks are for personal use, a place for half baked tasks.
;; Feel free to add your own tasks here, but don't expect them to be run by anyone else, or be listed in the
;; `./bin/mage` listing.
-escherize-pr-summary
{:doc "Print a day's PR summary for the metabase/metabase repo"
:requires [[mage.escherize.pr-summary :as eps]]
:examples [["./bin/mage -escherize-pr-summary | pbcopy" "Copy your daily"]]
:task (task! (eps/summarize-prs parsed))}
-escherize-fix-whitespace
{:doc "Removes all lines like '^<space>+$' from files in glob pattern."
:requires [[mage.escherize.fix-whitespace :as fix-whitespace]]
:examples [["mage -escherize-fix-whitespace '**/*.clj'" "Removes all lines like ' ' from all clj files"]]
:arg-schema [:sequential [:string {:description "Glob pattern to match files"}]]
:task (task! (fix-whitespace/run-clean parsed))}}}