|
21 | 21 | '[io.aviso.ansi :as ansi]
|
22 | 22 | '[release.version :as version])
|
23 | 23 |
|
| 24 | +(defn shcmd-no-exit |
| 25 | + "Thin wrapper on babashka.process/process that does not exit on error." |
| 26 | + ([cmd] (shcmd-no-exit cmd {})) |
| 27 | + ([cmd opts] |
| 28 | + (status/line :detail (str "Running: " (string/join " " cmd))) |
| 29 | + (shell/command-no-exit cmd opts))) |
| 30 | + |
| 31 | +(defn shcmd |
| 32 | + "Thin wrapper on babashka.process/process that prints error message and exits on error." |
| 33 | + ([cmd] (shcmd cmd {})) |
| 34 | + ([cmd opts] |
| 35 | + (status/line :detail (str "Running: " (string/join " " cmd))) |
| 36 | + (shell/command cmd opts))) |
| 37 | + |
24 | 38 | (defn- install-local [version]
|
25 | 39 | (status/line :info (format "Installing rewrite-clj %s locally" version))
|
26 | 40 | (let [pom-bak-filename "pom.xml.canary.bak"]
|
27 | 41 | (try
|
28 | 42 | (fs/copy "pom.xml" pom-bak-filename {:replace-existing true :copy-attributes true})
|
29 |
| - (shell/command ["clojure" "-X:jar" ":version" (pr-str version)]) |
30 |
| - (shell/command ["clojure" "-X:deploy:local"]) |
| 43 | + (shcmd ["clojure" "-X:jar" ":version" (pr-str version)]) |
| 44 | + (shcmd ["clojure" "-X:deploy:local"]) |
31 | 45 | (finally
|
32 | 46 | (fs/move pom-bak-filename "pom.xml" {:replace-existing true}))))
|
33 | 47 | nil)
|
|
38 | 52 | (io/copy
|
39 | 53 | (:body (curl/get (format release-url-fmt version) {:as :stream}))
|
40 | 54 | (io/file target))
|
41 |
| - (let [zip-root-dir (->> (shell/command ["unzip" "-qql" target] {:out :string}) |
| 55 | + (let [zip-root-dir (->> (shcmd ["unzip" "-qql" target] {:out :string}) |
42 | 56 | :out
|
43 | 57 | string/split-lines
|
44 | 58 | first
|
45 | 59 | (re-matches #" *\d+ +[\d-]+ +[\d:]+ +(.*)")
|
46 | 60 | second)]
|
47 |
| - (shell/command ["unzip" target "-d" target-root-dir]) |
| 61 | + (shcmd ["unzip" target "-d" target-root-dir]) |
48 | 62 | (str (fs/file target-root-dir zip-root-dir)))))
|
49 | 63 |
|
50 | 64 | (defn- deps-tree [{:keys [home-dir]} cmd]
|
51 |
| - (let [{:keys [out err]} (shell/command cmd {:dir home-dir |
| 65 | + (let [{:keys [out err]} (shcmd cmd {:dir home-dir |
52 | 66 | :out :string
|
53 | 67 | :err :string})]
|
54 | 68 | (-> (format "stderr->:\n%s\nstdout->:\n%s" err out)
|
|
65 | 79 | (deps-tree lib ["clojure" "-Stree"]))
|
66 | 80 |
|
67 | 81 | (defn- patch-rewrite-cljc-sources [home-dir]
|
68 |
| - (status/line :detail "Patching sources") |
| 82 | + (status/line :detail "=> Patching sources") |
69 | 83 | (doall (map (fn [f]
|
70 | 84 | (let [f (fs/file f)
|
71 | 85 | content (slurp f)
|
|
77 | 91 | (fs/glob home-dir "**/*.{clj,cljc,cljs}"))))
|
78 | 92 |
|
79 | 93 | (defn- patch-deps [{:keys [filename removals additions]}]
|
80 |
| - (status/line :detail (format "Patching deps in: %s" filename)) |
81 |
| - (shell/command ["clojure" "-X:deps-patcher" |
| 94 | + (status/line :detail (format "=> Patching deps in: %s" filename)) |
| 95 | + (shcmd ["clojure" "-X:deps-patcher" |
82 | 96 | (if (string/ends-with? filename "deps.edn")
|
83 | 97 | "update-deps-deps"
|
84 | 98 | "update-project-deps")
|
|
127 | 141 | ;; mranderson
|
128 | 142 | ;;
|
129 | 143 | (defn- mranderson-patch [{:keys [home-dir rewrite-clj-version]}]
|
130 |
| - (status/line :detail "Patching deps") |
| 144 | + (status/line :detail "=> Patching deps") |
131 | 145 | (let [p (str (fs/file home-dir "project.clj"))]
|
132 | 146 | (-> p
|
133 | 147 | slurp
|
|
143 | 157 | ;;
|
144 | 158 |
|
145 | 159 | (defn- refactor-nrepl-prep [{:keys [home-dir]}]
|
146 |
| - (status/line :detail "Inlining deps") |
147 |
| - (shell/command ["lein" "inline-deps"] {:dir home-dir})) |
| 160 | + (status/line :detail "=> Inlining deps") |
| 161 | + (shcmd ["lein" "inline-deps"] {:dir home-dir})) |
148 | 162 |
|
149 | 163 | (defn- refactor-nrepl-patch [{:keys [home-dir rewrite-clj-version]}]
|
150 |
| - (status/line :detail "Patching deps") |
| 164 | + (status/line :detail "=> Patching deps") |
151 | 165 | (let [p (str (fs/file home-dir "project.clj"))]
|
152 | 166 | (-> p
|
153 | 167 | slurp
|
|
178 | 192 | :additions {'rewrite-clj/rewrite-clj {:mvn/version rewrite-clj-version}}}))
|
179 | 193 |
|
180 | 194 | (defn- update-leiningen-dependencies-skill-prep [{:keys [home-dir]}]
|
181 |
| - (status/line :detail "Installing node deps") |
182 |
| - (shell/command ["npm" "ci"] {:dir home-dir})) |
| 195 | + (status/line :detail "=> Installing node deps") |
| 196 | + (shcmd ["npm" "ci"] {:dir home-dir})) |
183 | 197 |
|
184 | 198 | ;;
|
185 | 199 | ;; zprint
|
|
190 | 204 | :removals #{'rewrite-clj 'rewrite-cljs}
|
191 | 205 | :additions [['rewrite-clj rewrite-clj-version]]})
|
192 | 206 |
|
193 |
| - (status/line :detail "Hacking lift-ns to compensate for rewrite-clj v0->v1 change in sexpr on nsmap keys") |
194 |
| - (status/line :detail "- note the word 'hacking' - hacked for to get test passing nly") |
| 207 | + (status/line :detail "=> Hacking lift-ns to compensate for rewrite-clj v0->v1 change in sexpr on nsmap keys") |
| 208 | + (status/line :detail "- note the word 'hacking' - hacked for to get test passing only") |
195 | 209 | (let [src-filename (str (fs/file home-dir "src/zprint/zutil.cljc"))
|
196 | 210 | orig-filename (str src-filename ".orig")
|
197 | 211 | content (slurp src-filename)
|
|
205 | 219 | replace-str
|
206 | 220 | (subs content (+ ndx (count find-str)))))
|
207 | 221 | (throw (ex-info "hacking zprint failed" {})))
|
208 |
| - (status/line :detail (format "here's the diff for %s" src-filename)) |
209 |
| - (shell/command-no-exit ["git" "--no-pager" "diff" "--no-index" orig-filename src-filename]))) |
| 222 | + (status/line :detail (format "-> here's the diff for %s" src-filename)) |
| 223 | + (shcmd-no-exit ["git" "--no-pager" "diff" "--no-index" orig-filename src-filename]))) |
210 | 224 |
|
211 | 225 | (defn- zprint-prep [{:keys [target-root-dir home-dir]}]
|
212 |
| - (status/line :detail "Installing not-yet-released expectations/cljc-test") |
| 226 | + (status/line :detail "=> Installing not-yet-released expectations/cljc-test") |
213 | 227 | (let [clone-to-dir (str (fs/file target-root-dir "clojure-test"))]
|
214 |
| - (shell/command ["git" "clone" "--branch" "enhancements" |
| 228 | + (shcmd ["git" "clone" "--branch" "enhancements" |
215 | 229 | "https://github.com/kkinnear/clojure-test.git" clone-to-dir])
|
216 |
| - (run! #(shell/command % {:dir clone-to-dir}) |
| 230 | + (run! #(shcmd % {:dir clone-to-dir}) |
217 | 231 | [["git" "reset" "--hard" "a6c3be067ab06f677d3b1703ee4092d25db2bb60"]
|
218 | 232 | ["clojure" "-M:jar"]
|
219 | 233 | ["mvn" "install:install-file" "-Dfile=expectations.jar" "-DpomFile=pom.xml"]]))
|
220 |
| - (status/line :detail "Building uberjar for uberjar tests") |
221 |
| - (shell/command ["lein" "uberjar"] {:dir home-dir})) |
| 234 | + |
| 235 | + (status/line :detail "=> Building uberjar for uberjar tests") |
| 236 | + (shcmd ["lein" "uberjar"] {:dir home-dir}) |
| 237 | + |
| 238 | + (status/line :detail "=> Installing zprint locally for ClojureScript tests") |
| 239 | + (shcmd ["lein" "install"] {:dir home-dir})) |
222 | 240 |
|
223 | 241 | ;;
|
224 | 242 | ;; lib defs
|
225 | 243 | ;;
|
226 | 244 |
|
227 | 245 | (def libs [{:name "antq"
|
228 | 246 | :version "0.11.2"
|
| 247 | + :platforms [:clj] |
229 | 248 | :release-url-fmt "https://github.com/liquidz/antq/archive/%s.zip"
|
230 | 249 | :patch-fn antq-patch
|
231 | 250 | :show-deps-fn cli-deps-tree
|
232 |
| - :test-cmd ["clojure" "-M:dev:test"]} |
| 251 | + :test-cmds [["clojure" "-M:dev:test"]]} |
233 | 252 | {:name "carve"
|
234 | 253 | :version "0.0.2"
|
| 254 | + :platforms [:clj] |
235 | 255 | :release-url-fmt "https://github.com/borkdude/carve/archive/v%s.zip"
|
236 | 256 | :patch-fn carve-patch
|
237 | 257 | :show-deps-fn cli-deps-tree
|
238 |
| - :test-cmd ["clojure" "-M:test"]} |
| 258 | + :test-cmds [["clojure" "-M:test"]]} |
239 | 259 | {:name "cljfmt"
|
240 | 260 | :version "0.7.0"
|
| 261 | + :platforms [:clj :cljs] |
241 | 262 | :root "cljfmt"
|
242 | 263 | :release-url-fmt "https://github.com/weavejester/cljfmt/archive/%s.zip"
|
243 | 264 | :patch-fn cljfmt-patch
|
244 | 265 | :show-deps-fn lein-deps-tree
|
245 |
| - :test-cmd ["lein" "test"]} |
| 266 | + :test-cmds [["lein" "test"]]} |
246 | 267 | {:name "clojure-lsp"
|
| 268 | + :platforms [:clj] |
247 | 269 | :version "2021.03.01-19.18.54"
|
248 | 270 | :release-url-fmt "https://github.com/clojure-lsp/clojure-lsp/archive/%s.zip"
|
249 | 271 | :patch-fn clojure-lsp-patch
|
250 | 272 | :show-deps-fn lein-deps-tree
|
251 |
| - :test-cmd ["lein" "test"]} |
| 273 | + :test-cmds [["lein" "test"]]} |
252 | 274 | {:name "mranderson"
|
253 | 275 | :version "0.5.3"
|
| 276 | + :platforms [:clj] |
254 | 277 | :release-url-fmt "https://github.com/benedekfazekas/mranderson/archive/v%s.zip"
|
255 | 278 | :patch-fn mranderson-patch
|
256 | 279 | :show-deps-fn lein-deps-tree
|
257 |
| - :test-cmd ["lein" "test"]} |
| 280 | + :test-cmds [["lein" "test"]]} |
258 | 281 | {:name "rewrite-edn"
|
259 | 282 | :version "665f61cf273c79b44baacb0897d72c2157e27b09"
|
| 283 | + :platforms [:clj] |
260 | 284 | :release-url-fmt "https://github.com/borkdude/rewrite-edn/zipball/%s"
|
261 | 285 | :patch-fn rewrite-edn-patch
|
262 | 286 | :show-deps-fn cli-deps-tree
|
263 |
| - :test-cmd ["clojure" "-M:test"]} |
| 287 | + :test-cmds [["clojure" "-M:test"]]} |
264 | 288 | {:name "refactor-nrepl"
|
265 | 289 | :version "2.5.1"
|
| 290 | + :platforms [:clj] |
266 | 291 | :release-url-fmt "https://github.com/clojure-emacs/refactor-nrepl/archive/v%s.zip"
|
267 | 292 | :patch-fn refactor-nrepl-patch
|
268 | 293 | :show-deps-fn lein-deps-tree
|
269 | 294 | :prep-fn refactor-nrepl-prep
|
270 |
| - :test-cmd ["lein" "with-profile" "+1.10,+plugin.mranderson/config" "test"]} |
| 295 | + :test-cmds [["lein" "with-profile" "+1.10,+plugin.mranderson/config" "test"]]} |
271 | 296 | {:name "update-leiningen-dependencies-skill"
|
272 | 297 | :version "21c7ce794c83d6eed9c2a27e2fdd527b5da8ebb3"
|
| 298 | + :platforms [:cljs] |
273 | 299 | :release-url-fmt "https://github.com/atomist-skills/update-leiningen-dependencies-skill/zipball/%s"
|
274 | 300 | :patch-fn update-leiningen-dependencies-skill-patch
|
275 | 301 | :prep-fn update-leiningen-dependencies-skill-prep
|
276 | 302 | :show-deps-fn cli-deps-tree
|
277 |
| - :test-cmd ["npm" "run" "test"]} |
| 303 | + :test-cmds [["npm" "run" "test"]]} |
278 | 304 | {:name "zprint"
|
279 | 305 | :version "1.1.1"
|
| 306 | + :platforms [:clj :cljs] |
280 | 307 | :note "zprint src hacked to pass with rewrite-clj v1"
|
281 |
| - :release-url-fmt "https://github.com/kkinnear/zprint/archive/%s.zip" |
| 308 | + :release-url-fmt "https://github.com/kkinnear/zprint/archive/%s.zip" |
282 | 309 | :patch-fn zprint-patch
|
283 |
| - :show-deps-fn lein-deps-tree |
284 | 310 | :prep-fn zprint-prep
|
285 |
| - :test-cmd ["lein" "with-profile" "expectations" "test"]}]) |
| 311 | + :show-deps-fn (fn [lib] |
| 312 | + (status/line :detail "=> Deps for Clojure run:") |
| 313 | + (lein-deps-tree lib) |
| 314 | + (status/line :detail "=> Deps Clojurescript run:") |
| 315 | + (cli-deps-tree lib)) |
| 316 | + :test-cmds [["lein" "with-profile" "expectations" "test"] |
| 317 | + ["clj" "-M:cljs-runner"]]}]) |
286 | 318 |
|
287 | 319 | (defn- header [text]
|
288 | 320 | (let [dashes (apply str (repeat 80 "-"))]
|
289 | 321 | (status/line :info (str dashes "\n"
|
290 | 322 | text "\n"
|
291 | 323 | dashes))))
|
292 | 324 |
|
293 |
| -(defn- test-lib [{:keys [name root patch-fn prep-fn show-deps-fn test-cmd] :as lib}] |
| 325 | +(defn- test-lib [{:keys [name root patch-fn prep-fn show-deps-fn test-cmds] :as lib}] |
294 | 326 | (header name)
|
295 | 327 | (let [home-dir (do
|
296 | 328 | (status/line :info (format "%s: Fetching" name))
|
|
307 | 339 | (throw (ex-info (format "missing show-deps-fn for %s" name) {})))
|
308 | 340 | (status/line :info (format "%s: Deps report" name))
|
309 | 341 | (show-deps-fn lib)
|
310 |
| - (when-not test-cmd |
311 |
| - (throw (ex-info (format "missing test-cmd for %s" name) {}))) |
| 342 | + (when-not test-cmds |
| 343 | + (throw (ex-info (format "missing test-cmds for %s" name) {}))) |
312 | 344 | (status/line :info (format "%s: Running tests" name))
|
313 |
| - (let [{:keys [exit]} (shell/command-no-exit test-cmd {:dir home-dir})] |
314 |
| - (status/line :detail "\n") |
315 |
| - (if (zero? exit) |
316 |
| - (status/line :detail (format "%s: TESTS PASSED" name)) |
317 |
| - (status/line :warn (format "%s: TESTS FAILED" name))) |
318 |
| - (assoc lib :exit-code exit)))) |
| 345 | + (let [exit-codes (into [] (map-indexed (fn [ndx cmd] |
| 346 | + (let [{:keys [exit]} (shcmd-no-exit cmd {:dir home-dir})] |
| 347 | + (if (zero? exit) |
| 348 | + (status/line :detail (format "=> %s: TESTS %d of %d PASSED\n" name (inc ndx) (count test-cmds))) |
| 349 | + (status/line :warn (format "=> %s: TESTS %d of %d FAILED" name (inc ndx) (count test-cmds)))) |
| 350 | + exit)) |
| 351 | + test-cmds))] |
| 352 | + (assoc lib :exit-codes exit-codes)))) |
319 | 353 |
|
320 | 354 | (defn main [args]
|
321 | 355 | ;; no args = test all libs
|
|
333 | 367 | target-root-dir "target/libs-test"
|
334 | 368 | _ (when (fs/exists? target-root-dir) (fs/delete-tree target-root-dir))
|
335 | 369 | rewrite-clj-version (str (version/calc) "-canary")]
|
336 |
| - (status/line :detail (format "requested libs: %s" (into [] (map :name requested-libs)))) |
| 370 | + (status/line :detail (format "Requested libs: %s" (into [] (map :name requested-libs)))) |
337 | 371 | (install-local rewrite-clj-version)
|
338 | 372 | (let [results (doall (map #(test-lib (assoc %
|
339 | 373 | :target-root-dir target-root-dir
|
340 | 374 | :rewrite-clj-version rewrite-clj-version))
|
341 | 375 | requested-libs))]
|
342 | 376 | (status/line :info "Summary")
|
343 |
| - (println (doric/table [:name :version :note :exit-code] results)) |
344 |
| - (System/exit (if (every? #(zero? (:exit-code %)) results) 0 1)))) |
| 377 | + (println (doric/table [:name :version :platforms :note :exit-codes] results)) |
| 378 | + (System/exit (if (->> results |
| 379 | + (map :exit-codes) |
| 380 | + flatten |
| 381 | + (every? zero?)) |
| 382 | + 0 1)))) |
345 | 383 | nil)
|
346 | 384 |
|
347 | 385 | (main *command-line-args*)
|
348 |
| - |
|
0 commit comments