Skip to content

Commit

Permalink
Replace babashka.curl with org.httpkit.client
Browse files Browse the repository at this point in the history
The `babashka.curl` lib wasn't working properly in the GitHub Actions
Windows image. There is no requirement to use `curl` here so using
`org.httpkit.client` means we can fix GitHub Actions and have one less
thing to install on Windows.
  • Loading branch information
rads committed Sep 30, 2022
1 parent ae45016 commit 55f942b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
17 changes: 12 additions & 5 deletions bbin
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fipp/fipp {:mvn/version "0.6.26"},
com.taoensso/timbre {:mvn/version "5.2.1"},
selmer/selmer {:mvn/version "1.12.53"},
io.github.rads/deps-info {:git/tag "v0.0.5", :git/sha "1ec61ff"}}})
io.github.rads/deps-info {:git/tag "v0.0.6", :git/sha "480ab23"}}})

(ns babashka.bbin.meta)
(def min-bb-version "This def was generated by the bbin build script." "0.9.162")
Expand Down Expand Up @@ -159,15 +159,16 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi

(ns babashka.bbin.scripts
(:require [babashka.bbin.util :as util :refer [sh]]
[babashka.curl :as curl]
[babashka.deps :as deps]
[babashka.fs :as fs]
[cheshire.core :as json]
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.pprint :as pprint]
[clojure.string :as str]
[rads.deps-info.infer :as deps-info-infer]
[rads.deps-info.summary :as deps-info-summary]
[org.httpkit.client :as http]
[selmer.filters :as filters]
[selmer.parser :as selmer]
[selmer.util :as selmer-util]))
Expand Down Expand Up @@ -442,7 +443,7 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
header {:coords script-deps}
_ (pprint header cli-opts)
script-name (or (:as cli-opts) (file-path->script-name file-path))
script-contents (-> (slurp (:bbin/url script-deps))
script-contents (-> (slurp file-path)
(insert-script-header header))
script-file (fs/canonicalize (fs/file (util/bin-dir cli-opts) script-name)
{:nofollow-links true})]
Expand All @@ -468,7 +469,7 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
(selmer/render local-jar-template-str template-opts))
script-file (fs/canonicalize (fs/file (util/bin-dir cli-opts) script-name)
{:nofollow-links true})]
(io/copy (:body (curl/get http-url {:as :bytes})) cached-jar-path)
(io/copy (:body @(http/get http-url {:as :byte-array})) cached-jar-path)
(install-script script-file script-contents (:dry-run cli-opts))))

(defn- install-local-jar [cli-opts]
Expand Down Expand Up @@ -500,10 +501,16 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
{:main-opts ["-m" (str top "." name)]
:ns-default (str top "." name)}))

(def ^:private deps-info-client
{:http-get-json #(json/parse-string (:body @(apply http/get %&)) true)})

(defn- deps-info-infer [& {:as opts}]
(deps-info-infer/infer deps-info-client opts))

(defn- install-deps-git-or-local [cli-opts {:keys [procurer] :as _summary}]
(let [script-deps (if (and (#{:local} procurer) (not (:local/root cli-opts)))
{::no-lib {:local/root (str (fs/canonicalize (:script/lib cli-opts) {:nofollow-links true}))}}
(deps-info-infer/infer (assoc cli-opts :lib (:script/lib cli-opts))))
(deps-info-infer (assoc cli-opts :lib (:script/lib cli-opts))))
lib (key (first script-deps))
coords (val (first script-deps))
header (merge {:coords coords} (when-not (#{::no-lib} lib) {:lib lib}))
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
fipp/fipp {:mvn/version "0.6.26"}
com.taoensso/timbre {:mvn/version "5.2.1"}
selmer/selmer {:mvn/version "1.12.53"}
io.github.rads/deps-info {:git/tag "v0.0.5" :git/sha "1ec61ff"}}
io.github.rads/deps-info {:git/tag "v0.0.6" :git/sha "480ab23"}}
:aliases {:neil {:project {:name babashka/bbin
:version "0.1.4-SNAPSHOT"}}}}
15 changes: 11 additions & 4 deletions src/babashka/bbin/scripts.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
(ns babashka.bbin.scripts
(:require [babashka.bbin.util :as util :refer [sh]]
[babashka.curl :as curl]
[babashka.deps :as deps]
[babashka.fs :as fs]
[cheshire.core :as json]
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.pprint :as pprint]
[clojure.string :as str]
[rads.deps-info.infer :as deps-info-infer]
[rads.deps-info.summary :as deps-info-summary]
[org.httpkit.client :as http]
[selmer.filters :as filters]
[selmer.parser :as selmer]
[selmer.util :as selmer-util]))
Expand Down Expand Up @@ -283,7 +284,7 @@
header {:coords script-deps}
_ (pprint header cli-opts)
script-name (or (:as cli-opts) (file-path->script-name file-path))
script-contents (-> (slurp (:bbin/url script-deps))
script-contents (-> (slurp file-path)
(insert-script-header header))
script-file (fs/canonicalize (fs/file (util/bin-dir cli-opts) script-name)
{:nofollow-links true})]
Expand All @@ -309,7 +310,7 @@
(selmer/render local-jar-template-str template-opts))
script-file (fs/canonicalize (fs/file (util/bin-dir cli-opts) script-name)
{:nofollow-links true})]
(io/copy (:body (curl/get http-url {:as :bytes})) cached-jar-path)
(io/copy (:body @(http/get http-url {:as :byte-array})) cached-jar-path)
(install-script script-file script-contents (:dry-run cli-opts))))

(defn- install-local-jar [cli-opts]
Expand Down Expand Up @@ -341,10 +342,16 @@
{:main-opts ["-m" (str top "." name)]
:ns-default (str top "." name)}))

(def ^:private deps-info-client
{:http-get-json #(json/parse-string (:body @(apply http/get %&)) true)})

(defn- deps-info-infer [& {:as opts}]
(deps-info-infer/infer deps-info-client opts))

(defn- install-deps-git-or-local [cli-opts {:keys [procurer] :as _summary}]
(let [script-deps (if (and (#{:local} procurer) (not (:local/root cli-opts)))
{::no-lib {:local/root (str (fs/canonicalize (:script/lib cli-opts) {:nofollow-links true}))}}
(deps-info-infer/infer (assoc cli-opts :lib (:script/lib cli-opts))))
(deps-info-infer (assoc cli-opts :lib (:script/lib cli-opts))))
lib (key (first script-deps))
coords (val (first script-deps))
header (merge {:coords coords} (when-not (#{::no-lib} lib) {:lib lib}))
Expand Down
2 changes: 1 addition & 1 deletion test/babashka/bbin/scripts_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

(defn exec-cmd-line [script-name]
(concat (when util/windows? ["cmd" "/c"])
[(fs/canonicalize (fs/file bin-dir (name script-name)) {:nofollow-links true})]))
[(str (fs/canonicalize (fs/file bin-dir (name script-name)) {:nofollow-links true}))]))

(defn run-bin-script [script-name & script-args]
(let [args (concat (exec-cmd-line script-name) script-args)
Expand Down

0 comments on commit 55f942b

Please sign in to comment.