|
6 | 6 | [babashka.curl :as curl]
|
7 | 7 | [babashka.deps :as deps]
|
8 | 8 | [babashka.fs :as fs]
|
| 9 | + [cheshire.core :as json] |
9 | 10 | [clojure.java.io :as io]
|
10 | 11 | [clojure.string :as string]))
|
11 | 12 |
|
12 | 13 | (deps/add-deps
|
13 | 14 | '{:deps {io.aviso/pretty {:mvn/version "0.1.36"}
|
| 15 | + docopt/docopt {:git/url "https://github.com/nubank/docopt.clj" |
| 16 | + :sha "98814f559d2e50fdf10f43cbe3b7da0ca3cca423"} |
14 | 17 | doric/doric {:mvn/version "0.9.0"}}})
|
15 | 18 |
|
16 | 19 | (cp/add-classpath (.getParent (io/file *file*)))
|
17 | 20 |
|
18 |
| -(require '[doric.core :as doric] |
| 21 | +(require '[docopt.core :as docopt] |
| 22 | + '[docopt.match :as docopt-match] |
| 23 | + '[doric.core :as doric] |
19 | 24 | '[helper.shell :as shell]
|
20 | 25 | '[helper.status :as status]
|
21 | 26 | '[io.aviso.ansi :as ansi]
|
|
46 | 51 | (fs/move pom-bak-filename "pom.xml" {:replace-existing true}))))
|
47 | 52 | nil)
|
48 | 53 |
|
49 |
| -(defn- fetch-lib-release [{:keys [target-root-dir name version release-url-fmt]}] |
50 |
| - (let [target (str (fs/file target-root-dir (format "%s-%s.zip" name version)))] |
| 54 | +(defn- get-current-version |
| 55 | + "Get current available version of lib via GitHub API. |
| 56 | +
|
| 57 | + Note that github API does have rate limiting... so if running this a lot some calls will fail. |
| 58 | +
|
| 59 | + Could get from deps.edn RELEASE technique, but not all libs are on clojars. |
| 60 | + See: https://github.com/babashka/babashka/blob/master/examples/outdated.clj" |
| 61 | + [{:keys [github-release]}] |
| 62 | + (case (:via github-release) |
| 63 | + ;; no official release |
| 64 | + :sha |
| 65 | + (-> (curl/get (format "https://api.github.com/repos/%s/git/refs/heads/master" (:repo github-release))) |
| 66 | + :body |
| 67 | + (json/parse-string true) |
| 68 | + :object |
| 69 | + :sha) |
| 70 | + |
| 71 | + ;; tags can work better than release - sometimes libs have release 1.2 that refs tag 1.1 |
| 72 | + :tag |
| 73 | + (-> (curl/get (format "https://api.github.com/repos/%s/tags" (:repo github-release))) |
| 74 | + :body |
| 75 | + (json/parse-string true) |
| 76 | + first |
| 77 | + :name) |
| 78 | + |
| 79 | + ;; else via release which works better than tags sometimes due to the way tags sort |
| 80 | + (-> (curl/get (format "https://api.github.com/repos/%s/releases" (:repo github-release))) |
| 81 | + :body |
| 82 | + (json/parse-string true) |
| 83 | + first |
| 84 | + :tag_name))) |
| 85 | + |
| 86 | +(defn- fetch-lib-release [{:keys [target-root-dir name version github-release]}] |
| 87 | + (let [target (str (fs/file target-root-dir (format "%s-%s.zip" name version))) |
| 88 | + download-url (if (= :sha (:via github-release)) |
| 89 | + (format "https://github.com/%s/zipball/%s" (:repo github-release) version) |
| 90 | + (format "https://github.com/%s/archive/%s%s.zip" |
| 91 | + (:repo github-release) |
| 92 | + (or (:version-prefix github-release) "") |
| 93 | + version))] |
51 | 94 | (io/make-parents target)
|
52 | 95 | (io/copy
|
53 |
| - (:body (curl/get (format release-url-fmt version) {:as :stream})) |
| 96 | + (:body (curl/get download-url {:as :stream})) |
54 | 97 | (io/file target))
|
55 | 98 | (let [zip-root-dir (->> (shcmd ["unzip" "-qql" target] {:out :string})
|
56 | 99 | :out
|
|
253 | 296 | (def libs [{:name "antq"
|
254 | 297 | :version "0.11.2"
|
255 | 298 | :platforms [:clj]
|
256 |
| - :release-url-fmt "https://github.com/liquidz/antq/archive/%s.zip" |
| 299 | + :github-release {:repo "liquidz/antq"} |
257 | 300 | :patch-fn antq-patch
|
258 | 301 | :show-deps-fn cli-deps-tree
|
259 | 302 | :test-cmds [["clojure" "-M:dev:test"]]}
|
260 | 303 | {:name "carve"
|
261 | 304 | :version "0.0.2"
|
262 | 305 | :platforms [:clj]
|
263 |
| - :release-url-fmt "https://github.com/borkdude/carve/archive/v%s.zip" |
| 306 | + :github-release {:repo "borkdude/carve" |
| 307 | + :version-prefix "v"} |
264 | 308 | :patch-fn carve-patch
|
265 | 309 | :show-deps-fn cli-deps-tree
|
266 | 310 | :test-cmds [["clojure" "-M:test"]]}
|
267 | 311 | {:name "cljfmt"
|
268 | 312 | :version "0.7.0"
|
269 | 313 | :platforms [:clj :cljs]
|
270 | 314 | :root "cljfmt"
|
271 |
| - :release-url-fmt "https://github.com/weavejester/cljfmt/archive/%s.zip" |
| 315 | + :github-release {:repo "weavejester/cljfmt" |
| 316 | + :via :tag} |
272 | 317 | :patch-fn cljfmt-patch
|
273 | 318 | :show-deps-fn lein-deps-tree
|
274 | 319 | :test-cmds [["lein" "test"]]}
|
275 | 320 | {:name "clojure-lsp"
|
276 | 321 | :platforms [:clj]
|
277 | 322 | :version "2021.03.01-19.18.54"
|
278 |
| - :release-url-fmt "https://github.com/clojure-lsp/clojure-lsp/archive/%s.zip" |
| 323 | + :github-release {:repo "clojure-lsp/clojure-lsp" } |
279 | 324 | :patch-fn clojure-lsp-patch
|
280 | 325 | :show-deps-fn lein-deps-tree
|
281 | 326 | :test-cmds [["lein" "test"]]}
|
282 | 327 | {:name "mranderson"
|
283 | 328 | :version "0.5.3"
|
284 | 329 | :platforms [:clj]
|
285 |
| - :release-url-fmt "https://github.com/benedekfazekas/mranderson/archive/v%s.zip" |
| 330 | + :github-release {:repo "benedekfazekas/mranderson" |
| 331 | + :via :tag |
| 332 | + :version-prefix "v"} |
286 | 333 | :patch-fn mranderson-patch
|
287 | 334 | :show-deps-fn lein-deps-tree
|
288 | 335 | :test-cmds [["lein" "test"]]}
|
289 | 336 | {:name "rewrite-edn"
|
290 | 337 | :version "665f61cf273c79b44baacb0897d72c2157e27b09"
|
291 | 338 | :platforms [:clj]
|
292 |
| - :release-url-fmt "https://github.com/borkdude/rewrite-edn/zipball/%s" |
| 339 | + :github-release {:repo "borkdude/rewrite-edn" |
| 340 | + :via :sha} |
293 | 341 | :patch-fn rewrite-edn-patch
|
294 | 342 | :show-deps-fn cli-deps-tree
|
295 | 343 | :test-cmds [["clojure" "-M:test"]]}
|
296 | 344 | {:name "refactor-nrepl"
|
297 | 345 | :version "2.5.1"
|
298 | 346 | :platforms [:clj]
|
299 |
| - :release-url-fmt "https://github.com/clojure-emacs/refactor-nrepl/archive/v%s.zip" |
| 347 | + :github-release {:repo "clojure-emacs/refactor-nrepl" |
| 348 | + :via :tag |
| 349 | + :version-prefix "v"} |
300 | 350 | :patch-fn refactor-nrepl-patch
|
301 | 351 | :show-deps-fn lein-deps-tree
|
302 | 352 | :prep-fn refactor-nrepl-prep
|
303 | 353 | :test-cmds [["lein" "with-profile" "+1.10,+plugin.mranderson/config" "test"]]}
|
304 | 354 | {:name "update-leiningen-dependencies-skill"
|
305 | 355 | :version "21c7ce794c83d6eed9c2a27e2fdd527b5da8ebb3"
|
306 | 356 | :platforms [:cljs]
|
307 |
| - :release-url-fmt "https://github.com/atomist-skills/update-leiningen-dependencies-skill/zipball/%s" |
| 357 | + :github-release {:repo "atomist-skills/update-leiningen-dependencies-skill" |
| 358 | + :via :sha} |
308 | 359 | :patch-fn update-leiningen-dependencies-skill-patch
|
309 | 360 | :prep-fn update-leiningen-dependencies-skill-prep
|
310 | 361 | :show-deps-fn cli-deps-tree
|
|
313 | 364 | :version "1.1.1"
|
314 | 365 | :platforms [:clj :cljs]
|
315 | 366 | :note "zprint src hacked to pass with rewrite-clj v1"
|
316 |
| - :release-url-fmt "https://github.com/kkinnear/zprint/archive/%s.zip" |
| 367 | + :github-release {:repo "kkinnear/zprint"} |
317 | 368 | :patch-fn zprint-patch
|
318 | 369 | :prep-fn zprint-prep
|
319 | 370 | :show-deps-fn (fn [lib]
|
|
367 | 418 | (status/line :detail "git init-ing target to avoid polluting our project git config/hooks with any changes libs under test might effect")
|
368 | 419 | (shcmd ["git" "init"] {:dir target-root-dir}))
|
369 | 420 |
|
370 |
| -(defn main [args] |
371 |
| - ;; no args = test all libs |
372 |
| - ;; or specify which libs, by name, to test (in order specified) |
| 421 | +;; |
| 422 | +;; cmds |
| 423 | +;; |
| 424 | +(defn- report-outdated [requested-libs] |
| 425 | + (status/line :info "Checking for outdated libs") |
| 426 | + (status/line :detail (format "Requested libs: %s" (into [] (map :name requested-libs)))) |
| 427 | + (let [outdated-libs (->> requested-libs |
| 428 | + (map #(assoc % |
| 429 | + :available-version (get-current-version %) |
| 430 | + :version (str (-> % :github-release :version-prefix) (:version %)))) |
| 431 | + (filter #(not= (:available-version %) (:version %))))] |
| 432 | + (if (seq outdated-libs) |
| 433 | + (-> (doric/table [:name :version :available-version] outdated-libs) println) |
| 434 | + (status/line :detail "=> All libs seems up to date")))) |
| 435 | + |
| 436 | +(defn run-tests [requested-libs] |
373 | 437 | (status/line :info "Testing 3rd party libs")
|
374 | 438 | (status/line :detail "Test popular 3rd party libs against current rewrite-clj.")
|
375 |
| - (let [requested-libs (if (zero? (count args)) |
376 |
| - libs |
377 |
| - (reduce (fn [ls a] |
378 |
| - (if-let [l (first (filter #(= a (:name %)) libs))] |
379 |
| - (conj ls l) |
380 |
| - ls)) |
381 |
| - [] |
382 |
| - args)) |
383 |
| - target-root-dir "target/libs-test" |
| 439 | + (let [target-root-dir "target/libs-test" |
384 | 440 | rewrite-clj-version (str (version/calc) "-canary")]
|
385 | 441 | (status/line :detail (format "Requested libs: %s" (into [] (map :name requested-libs))))
|
386 | 442 | (install-local rewrite-clj-version)
|
|
395 | 451 | (map :exit-codes)
|
396 | 452 | flatten
|
397 | 453 | (every? zero?))
|
398 |
| - 0 1)))) |
399 |
| - nil) |
| 454 | + 0 1))))) |
| 455 | + |
| 456 | +(def docopt-usage "Libs Tests |
| 457 | +
|
| 458 | +Usage: |
| 459 | + libs_tests.clj run [<lib-name>...] |
| 460 | + libs_tests.clj outdated [<lib-name>...] |
| 461 | +
|
| 462 | +Options: |
| 463 | + -h --help Show this screen. |
| 464 | + |
| 465 | +Specifying no lib-names selects all libraries.") |
| 466 | + |
| 467 | +(defn main [args] |
| 468 | + (if-let [opts (-> docopt-usage docopt/parse (docopt-match/match-argv args))] |
| 469 | + (let [lib-names (get opts "<lib-name>") |
| 470 | + requested-libs (if (zero? (count lib-names)) |
| 471 | + libs |
| 472 | + (reduce (fn [ls a] |
| 473 | + (if-let [l (first (filter #(= a (:name %)) libs))] |
| 474 | + (conj ls l) |
| 475 | + ls)) |
| 476 | + [] |
| 477 | + lib-names))] |
| 478 | + (cond |
| 479 | + (get opts "outdated") |
| 480 | + (report-outdated requested-libs) |
| 481 | + |
| 482 | + (get opts "run") |
| 483 | + (run-tests requested-libs)) |
| 484 | + |
| 485 | + nil) |
| 486 | + (status/fatal docopt-usage))) |
400 | 487 |
|
401 | 488 | (main *command-line-args*)
|
| 489 | + |
| 490 | + |
| 491 | +#_(-> (curl/get "https://api.github.com/repos/borkdude/rewrite-edn/releases") |
| 492 | + :body |
| 493 | + (json/parse-string true) |
| 494 | + #_#_first |
| 495 | + :tag_name) |
| 496 | + |
| 497 | +#_(-> (curl/get "https://api.github.com/repos/borkdude/rewrite-edn/git/refs/heads/master") |
| 498 | + :body |
| 499 | + (json/parse-string true) |
| 500 | + :object |
| 501 | + :sha) |
| 502 | + |
| 503 | +#_(-> (curl/get "https://api.github.com/repos/weavejester/cljfmt/tags") |
| 504 | + :body |
| 505 | + (json/parse-string true) |
| 506 | + first) |
| 507 | + |
| 508 | +#_(get-current-version (nth libs 5)) |
| 509 | + |
| 510 | + |
| 511 | +#_(docopt/docopt docopt-usage |
| 512 | + *command-line-args* |
| 513 | + (fn [arg-map] arg-map)) |
0 commit comments