-
Notifications
You must be signed in to change notification settings - Fork 3
/
bb.edn
189 lines (156 loc) · 8.91 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
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
{:tasks
{:requires ([babashka.fs :as fs]
[clojure.string :as str])
:init (do
(def COMMIT-HASH
(-> (shell {:out :string} "git rev-parse --short HEAD")
:out
str/trim))
(def BACKEND-CONFIG {:clojure-defines {'heraldicon.config/is_backend true}})
(def PROD-FRONTEND-DIR "build/prod")
(def PROD-BACKEND-DIR "backend/build/prod")
(def PROD-CONFIG {:closure-defines {'heraldicon.config/stage "prod"
'heraldicon.config/commit COMMIT-HASH}})
(def STAGING-FRONTEND-DIR "build/staging")
(def STAGING-BACKEND-DIR "backend/build/staging")
(def STAGING-CONFIG {:closure-defines {'heraldicon.config/stage "staging"
'heraldicon.config/commit COMMIT-HASH}})
(defn build-frontend-release [build-dir config]
(fs/delete-tree STAGING-FRONTEND-DIR)
(fs/delete-tree PROD-FRONTEND-DIR)
(fs/create-dirs build-dir)
(doseq [file (fs/list-dir "assets")]
(if (fs/directory? file)
(fs/copy-tree file (fs/path build-dir (fs/file-name file)) {:replace-existing true})
(fs/copy file build-dir {:replace-existing true})))
(def output-dir
(str (fs/path build-dir "js/generated")))
(fs/delete-tree output-dir)
(fs/update-file (str (fs/path build-dir "index.html"))
(fn [content]
(str/replace content (re-pattern "__GIT-COMMIT-HASH__") COMMIT-HASH)))
(shell "npx shadow-cljs release frontend --config-merge"
(prn-str (merge config {:output-dir output-dir}))))
(defn create-sentry-release-backend
[build-dir stage]
(let [release-name (str COMMIT-HASH "-" stage)]
(shell (str "npx @sentry/cli releases --org heraldicon "
"new --project heraldicon-backend "
"--url https://github.com/heraldry/heraldicon/commit/" COMMIT-HASH " "
release-name))
(shell (str "npx @sentry/cli releases --org heraldicon "
"files --project heraldicon-backend " release-name " "
"upload-sourcemaps --url-prefix / "
build-dir))))
(defn create-sentry-release-frontend
[build-dir stage]
(let [release-name (str COMMIT-HASH "-" stage)]
(shell (str "npx @sentry/cli releases --org heraldicon "
"new --project heraldicon-frontend "
"--url https://github.com/heraldry/heraldicon/commit/" COMMIT-HASH " "
release-name))
(shell (str "npx @sentry/cli releases --org heraldicon "
"files --project heraldicon-frontend " release-name " "
"upload-sourcemaps --url-prefix / "
build-dir))))
(defn deploy-frontend [build-dir target]
(shell "scripts/sync-with-s3" build-dir target)
(shell (format "aws --profile heraldry-serverless s3 cp --acl public-read
'%s/index.html' 's3://%s/index.html'
--metadata-directive REPLACE
--cache-control max-age=0,no-cache,no-store,must-revalidate
--content-type text/html"
build-dir target))
(shell "scripts/invalidate-distribution" target))
(defn timestamp []
(-> (shell {:out :string} "date" "+%Y-%m-%d_%H-%M-%S")
:out
str/trim))
(defn tag-frontend-deploy []
(shell "git" "tag" (str "deploy-frontend-" (timestamp))))
(defn tag-backend-deploy []
(let [tag (str "deploy-backend-" (timestamp))]
(shell "git" "tag" tag)
(shell {:dir "backend"} "git" "tag" tag))))
check-clj-kondo (shell "clj-kondo --parallel --lint src test backend/src")
check-cljfmt (shell "cljfmt --parallel check src test backend/src")
check-debug-print-frontend (-> (shell {:continue true}
"rg '(println|\\(js/console)' --iglob='!log_appender.cljs' src")
:exit
(= 1)
(or (throw (Exception. "found debug prints in frontend"))))
check-debug-print-backend (-> (shell {:continue true}
"rg '(println|\\(js/console)' backend/src --glob=!backend/src/heraldicon/manage.cljs --glob=!backend/src/heraldicon/backend/server.cljs")
:exit
(= 1)
(or (throw (Exception. "found debug prints in backend"))))
check-json (-> (shell {:out :string} "find locales -iname '*.json'")
(shell {:out :string} "xargs jq ."))
check-dirty-frontend (-> (shell {:continue true} "git diff --quiet")
:exit
(= 0)
(or (throw (Exception. ". is dirty"))))
check-dirty-backend (-> (shell {:continue true
:dir "backend"} "git diff --quiet")
:exit
(= 0)
(or (throw (Exception. "backend is dirty"))))
check-all {:depends [check-clj-kondo
check-cljfmt
check-debug-print-frontend
check-debug-print-backend
check-json]}
dev-local (shell "npx shadow-cljs watch frontend backend test manage")
staging-backend-release (do
(fs/delete-tree STAGING-BACKEND-DIR)
(fs/delete-tree PROD-BACKEND-DIR)
(shell "npx shadow-cljs release backend --config-merge"
(prn-str (merge-with
merge
STAGING-CONFIG
BACKEND-CONFIG
{:output-to (str (fs/path STAGING-BACKEND-DIR "backend.js"))}))))
staging-backend-deploy (do
(run 'staging-backend-release)
(create-sentry-release-backend STAGING-BACKEND-DIR "staging")
(shell {:dir "backend"} "bb staging-deploy"))
staging-frontend-release (build-frontend-release STAGING-FRONTEND-DIR STAGING-CONFIG)
staging-frontend-deploy (do
(run 'staging-frontend-release)
(create-sentry-release-frontend STAGING-FRONTEND-DIR "staging")
(deploy-frontend STAGING-FRONTEND-DIR "cdn.staging.heraldicon.org"))
prod-backend-release (do
(fs/delete-tree STAGING-BACKEND-DIR)
(fs/delete-tree PROD-BACKEND-DIR)
(shell "npx shadow-cljs release backend --config-merge"
(prn-str
(merge-with
merge
PROD-CONFIG
BACKEND-CONFIG
{:output-to (str (fs/path PROD-BACKEND-DIR "backend.js"))}))))
prod-backend-deploy {:depends [check-clj-kondo
check-cljfmt
check-debug-print-frontend
check-debug-print-backend
check-json
check-dirty-frontend
check-dirty-backend]
:task (do
(run 'prod-backend-release)
(create-sentry-release-backend PROD-BACKEND-DIR "prod")
(shell {:dir "backend"} "bb prod-deploy")
(tag-backend-deploy))}
prod-frontend-release (build-frontend-release PROD-FRONTEND-DIR PROD-CONFIG)
prod-frontend-deploy {:depends [check-clj-kondo
check-cljfmt
check-debug-print-frontend
check-json
check-dirty-frontend]
:task (do
(run 'prod-frontend-release)
(deploy-frontend PROD-FRONTEND-DIR "cdn.heraldicon.org")
(tag-frontend-deploy))}
outdated (do
(shell "clojure -Sdeps '{:deps {olical/depot {:mvn/version \"2.2.0\"} rewrite-clj/rewrite-clj {:mvn/version \"0.6.1\"}}}' -M -m depot.outdated.main")
(shell "npm outdated"))}}