Fork me on GitHub
#babashka
<
2022-04-07
>
Daniel Jomphe11:04:22

Have you seen the new GitHub Action https://github.com/DeLaGuardo/setup-clojure/releases/tag/5.0 v5 with bb support? I'm happy, it becomes easy to use most clojure tools.

ā¤ļø 1
borkdude11:04:16

@danieljomphe Hadn't seen that, thanks for sharing :)

šŸ™‚ 1
Daniel Jomphe11:04:42

In some GitHub actions, though, I install https://github.com/borkdude/deps.clj instead of those tools (see thread for how I do it). I then don't need to install Java to power Clojure.

Daniel Jomphe11:04:59

- name: Install deps.clj, posing as clojure
        run: | 
          # bash script below
Bash script to be run:
latest_release="$(curl -sL )"
          download_url=""

echo -e "Downloading $download_url."

curl -o "deps.clj-$latest_release-linux-amd64.zip" -sL ""

unzip -qqo "deps.clj-$latest_release-linux-amd64.zip"

rm "deps.clj-$latest_release-linux-amd64.zip"

sudo mv deps /usr/local/bin/clojure # let it pose as the real Clojure CLI, since later steps will call `clojure` directly!

borkdude11:04:04

If you're also installing babashka in the same build, then you can skip this and use bb clojure instead

borkdude11:04:56

but then you need to install a bash shim for clojure -> bb clojure . I've posted that once in this channel

Daniel Jomphe11:04:11

Thanks for the tip - yes, but no, it's because the Datomic Cloud Ion deployment tool calls directly clojure <args>. šŸ™‚ So I'm quite happy with deps.clj in this action which only needs "clojure" for this single thing.

šŸ‘ 1
Daniel Jomphe11:04:41

Oh, the bash shim would do it, yes! Then I suppose I could compare binary size of deps vs bb but someone might challenge me in asking: does it truly matter, does it make your action setup even 1 second longer? šŸ™‚

borkdude11:04:01

the binary size of deps is way smaller

Daniel Jomphe11:04:51

Yeah, I'd expect deps to be e.g. 20 MB and bb e.g. 80 MB šŸ™‚

borkdude11:04:04

seems right

Cora (she/her)15:04:00

this is very much in the maybe-throw-away-but-interesting idea category but I noticed ruby had gotten a file-backed key-value store as part of its stdlib https://ruby-doc.org/stdlib-3.1.1/libdoc/pstore/rdoc/PStore.html

Cora (she/her)15:04:42

and that seems incredibly useful for a scripting language to have. I've definitely done this myself in a number of different languages in the past

borkdude15:04:02

@corasaurus-hex I think there's lots of stuff in the #nbb world for this: there is keyv with multiple adapters. https://www.npmjs.com/package/keyv - but we could also easily make a pod around something like this probably from the golang side.

Cora (she/her)17:04:43

I was thinking of it in the context of something built-in that was super simple (like just reads/writes edn to a file) but that would have to exist first before it could even be considered for inclusion

Cora (she/her)17:04:36

it might even be a fun little project

ericdallo21:04:36

Dumb issue, trying a task using shell but it's failing: bb.edn

{:min-bb-version "0.4.0"
 :tasks {test (shell "cd server && clojure -M:test")}}
bb test
----- Error --------------------------------------------------------------------
Type:     java.io.IOException
Message:  Cannot run program "cd": error=2, No such file or directory 

ericdallo21:04:54

is cd supported?

Daniel Jomphe21:04:53

Hi Eric, try

{:min-bb-version "0.4.0"
 :tasks {test (shell "cd" "server")}}
splitting cd and server apart first I never can remember how args are expected by shell Once that works, find a way to add back in && clojure ... :)

Daniel Jomphe21:04:15

also, sometimes space characters are required - something is tricky

ericdallo21:04:00

makes sense! but I think I'll use @U04V15CAJā€™s suggestion

(shell {:dir "server"} "clojure -M:test")

Daniel Jomphe21:04:19

oh yes, that's good, but you'll probably need to split clojure from its args too šŸ™‚ I often use this wrapper:

(defn eshell [& args]
            (let [s-args (str/join " " (map str/trimr args))]
              (println s-args)
              (println)
              (apply shell args)))

Daniel Jomphe21:04:04

Incredible to be helping you a bit, you who helps us so much!!! :star-struck:

ericdallo21:04:53

> oh yes, that's good, but you'll probably need to split clojure from its args too Actually I didn't need to split, it worked :thinking_face: Nice wrapper, I think I'll swap to it! > Incredible to be helping you a bit, you who helps us so much!!! šŸ˜„ Thank you!

šŸ™‚ 1
borkdude21:04:10

shell does not need splitting

borkdude21:04:28

the issue was that eric tried to put a bash expression in there, that's not how it works

Daniel Jomphe21:04:35

The master is here now (I didn't remark your answers at the top-level)

ericdallo21:04:33

haha, yeah, I was missing something like that wrapper, where I could run multiple commands easily, I forgot I could create a function at bb.edn

borkdude21:04:37

you can also use babashka.process/tokenize if you want to manually split a "shell" string

borkdude21:04:51

it supports double and single quotes mixed

Daniel Jomphe21:04:39

thanks for explanations; gotta take a look at tokenize in next bb.edn rampage session!

Daniel Jomphe21:04:35

Sorry to notify you, I wanted to bring back in this thread Michiel's answer for future reference in the thread (I added a link to the thread in our code's TODO!) https://clojurians.slack.com/archives/CLX41ASCS/p1649367592881239 https://clojurians.slack.com/archives/CLX41ASCS/p1649367701554329

šŸ‘ 4
Gunnar21:04:34

Don't know how I ended up so far back in the history. Waking up an old thread here: šŸ˜¬ It's a classic mistake that I have made countless times: When using any program that exec's binaries it is so easy to think that it is a shell interpreter. But don't forget that you can get around it by explicitly executing bash with -c parameter, and then provide the entire command as a single parameter following -c. When bash is doing the interpretation then you can use all expressions, job control, conditionals, and importantly, expansion of environment variables!

bb -o '(shell/sh "bash" "-c" "cd /tmp && ls")'
bb -o '(shell/sh "bash" "-c" "echo $BASH_VERSION")'

Gunnar07:04:57

Also, the original IOException error above - "cd" is not an executable program but just a built in command that bash interprets.

borkdude07:04:24

In bb you do this via the :dir option: (shell {:dir "/tmp"} "ls")

āœ… 1
borkdude21:04:52

@ericdallo shell != bash , so cd foo && ... isn't supported, but you can do it like this:

(shell {:dir "server"} "clojure -M:test")
;; or 
(clojure {:dir "server"} "-M:test")

ericdallo21:04:16

I see! the former sounds good, will try

ericdallo21:04:38

it works, thank you!

šŸŽ‰ 2
borkdude21:04:41

@ericdallo it also supports :extra-env {"FOO" "BAR"} - all the options from babaskha.process basically

šŸ’Æ 1
ericdallo22:04:21

is there any built-in integration with tools.build?

ericdallo22:04:38

I'm doing this:

:tasks{
deploy-clojars-server (shell {:dir "server"} "clojure -T:build deploy-clojars")
}

ericdallo22:04:13

I was thinking, maybe there is some function, like (tools/build "deploy-clojars")

ericdallo22:04:30

that sounds awesome, not sure is possible tho, also one more deps to bb

ericdallo22:04:06

I have 6 tasks on my bb.edn doing something like that

ericdallo22:04:24

I can always create a function, but I thought it would be a convenient built-in

borkdude22:04:18

@ericdallo it doesn't have that. There is however, tools.bbuild which allows you to use tools.build natively ;) https://github.com/babashka/tools.bbuild

ericdallo22:04:03

hahah that looks nice, but I would like to keep all build logic on a build.clj still, is that possible?

borkdude22:04:07

There is also https://github.com/babashka/neil which has the neil add build command which installs a default tools.build build.clj file for you

borkdude22:04:27

Yes of course, it doesn't matter where you put that code

ericdallo22:04:03

oh, I can just require it you mean from a local build.clj?

borkdude22:04:27

tools.bbuild is meant to be used with babashka and is considered experimental

ericdallo22:04:28

oh, acutally bb tasks support namespaces

ericdallo22:04:36

will give it a try

borkdude22:04:01

but in general you can just use tools.build on the JVM and use shell or clojure in bb tasks to invoke it

borkdude22:04:19

(clojure "-T:build uberjar")

ericdallo22:04:20

yeah, but if I had bb speed that would be super cool :)

borkdude22:04:31

ok, then tools.bbuild is the thing to try :)

ericdallo22:04:40

yeah, will try and let you know!

ericdallo22:04:55

tools.bbuild is such a good name šŸ˜‚

Daniel Gerson11:05:00

I love that I went looking for bb and tools.build and tools.bbuild already exists partyparrot šŸ™Œ Agree the name is great!