-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbb.edn
More file actions
73 lines (71 loc) · 4.83 KB
/
Copy pathbb.edn
File metadata and controls
73 lines (71 loc) · 4.83 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
{:paths ["src" "resources"]
:deps {org.babashka/cli {:mvn/version "0.8.61"}
io.github.babashka/instaparse-bb {:git/sha "97ed438f22ccb34e7c3ef0d80eb46c133d4c3092"}
metosin/malli {:mvn/version "0.19.1"}}
:tasks {:init
(do (require '[clojure.string :as str])
(defn server-ip
"Bot VM IP: env BBLEDGER_SERVER, or asking Hetzner (hcloud CLI;
honors HCLOUD_CONTEXT when several contexts exist)."
[]
(or (System/getenv "BBLEDGER_SERVER")
(let [{:keys [exit out]} (shell {:out :string :err :string :continue true}
"hcloud server ip bbledger-bot")]
(when (zero? exit) (str/trim out)))
(throw (ex-info (str "no hcloud context — one-time setup: "
"`hcloud context create bbledger` (paste the "
"Hetzner API token), or set BBLEDGER_SERVER=<ip>")
{}))))
(defn ssh-bot!
"Run a command on the bot VM (key: env BBLEDGER_SSH_KEY or the
project default)."
[cmd]
(shell "ssh" "-i" (or (System/getenv "BBLEDGER_SSH_KEY")
(str (System/getProperty "user.home")
"/.ssh/id_bbledger-telegram-bot"))
(str "root@" (server-ip)) cmd)))
ledger {:doc "Ledger reports. Try: bb ledger bal -f sample.ledger --auto"
:requires ([ledger.cli])
:task (apply ledger.cli/-main *command-line-args*)}
lint {:doc "clj-kondo over src and test (also gates bb test)"
:task (shell "clj-kondo --lint src test")}
test {:doc "Run examples + properties + hledger conformance + bot suite"
:depends [lint]
:extra-paths ["test"]
:requires (clojure.test ledger.examples-test ledger.properties-test ledger.conformance-test
ledger.core-test ledger.bot-test ledger.store-test ledger.integration-test)
:task (let [{:keys [fail error]}
(clojure.test/run-tests 'ledger.examples-test
'ledger.properties-test
'ledger.conformance-test
'ledger.core-test
'ledger.bot-test
'ledger.store-test
'ledger.integration-test)]
(System/exit (if (pos? (+ fail error)) 1 0)))}
bench {:doc "Timing benchmark vs hledger"
:extra-paths ["test"]
:requires ([ledger.bench])
:task (ledger.bench/run)}
server-ip {:doc "Print the bot VM's IP"
:task (println (server-ip))}
logs {:doc "Bot journal on the server; args go to journalctl (e.g. bb logs -f)"
:task (ssh-bot! (str "journalctl -u bbledger-bot --no-pager "
(str/join " " (or (seq *command-line-args*) ["-n" "50"]))))}
restart {:doc "Restart the bot on the server (pulls :latest on start)"
:task (ssh-bot! (str "systemctl restart bbledger-bot"
" && systemctl is-active bbledger-bot"
" && sleep 3"
" && echo running $(docker exec bbledger-bot printenv BBLEDGER_VERSION)"))}
deploy {:doc "Wait for CI + release on origin/main, then restart the bot"
:task (do (shell "git fetch origin main")
(let [sha (str/trim (:out (shell {:out :string} "git rev-parse origin/main")))
id (loop [n 20]
(let [id (str/trim (:out (shell {:out :string}
(str "gh run list --workflow ci --commit " sha
" --json databaseId --jq .[0].databaseId"))))]
(cond (not (str/blank? id)) id
(zero? n) (throw (ex-info "no CI run for origin/main — merged?" {:sha sha}))
:else (do (Thread/sleep 3000) (recur (dec n))))))]
(shell (str "gh run watch " id " --exit-status --interval 15"))
(run 'restart)))}}}