Fork me on GitHub
#babashka
<
2023-12-13
>
grzm00:12:59

Hola. So, I have a repo with some utility scripts. One of those scripts packages up a bunch of files. Think

cd ~/pkg-utils
bb pkg --prefix foo relative/path/to/files
# creates foo.pkg
I want to be able to call bb pkg from somewhere outside of the repo with the pkg task but still be able to use paths relative to where I'm calling it from.
cd ~/some/other/project
some-magic-call --prefix foo my/files/are/here
# creates foo.pkg in $PWD, i.e., ~/some/other/project
What does some-magic-call look like? Alternatively how should @grzm be approaching this type of thing because what @grzm is doing just doesn't make any sense because he's being a sillyhead?

grzm01:12:49

Crikey. Thanks, duckie

grzm01:12:10

cat $(which bbthingy)
#!/usr/bin/env bash

set -euo pipefail

bb --config "${UTIL_REPO_ROOT}/bb.edn" --deps-root "${UTIL_REPO_ROOT}" $@

Bob B01:12:35

I was just messing with something similar - I made a script called 'bbt' and used --config $(dirname $0)/tasks.edn with a tasks.edn in that same dir, and then running that script from somewhere else will use the tasks from tasks.edn but will be contextualized to $PWD (because I'm too lazy to set another env var) 🙂

grzm01:12:17

I use direnv to help with env vars.

Bob B01:12:23

with that said, I feel like 'global tasks' can often be a good use case for a script, and then potentially install the script with bbin if desired

grzm01:12:58

At the root of the project where I'm working (not where the bb tasks and source are)

% cat .envrc
dotenv
PATH_add "${PWD}/bin"
% cat .env
UTIL_REPO_ROOT=${HOME}/repos/bb-util

Bob B01:12:01

(using the term 'install' in the loosest possible sense there)

grzm01:12:32

I build up a lot of cljc that I want to be able leverage in other projects without including them as dependencies or installing them in a bunch of different places. bbin might be useful: I'll take a look. It'd be one more thing to learn, though, for me and the team. we already have bash and direnv

borkdude08:12:17

Bb will already respect a script-adjacent bb.edn

borkdude10:12:00

~/pkg-utils/bb.edn # contains pkg task
~/pkg-utils/pkg 
where pkg contains:
#!/usr/bin/env bb
(babashka.tasks/run 'pkg)
this should work when you add pkg to the PATH

borkdude10:12:53

and when you want to make it more dynamic:

~/pkg-utils/mypkg
with:
#!/usr/bin/env bb
(def task (symbol (first *command-line-args*)))
(binding [*command-line-args* (next *command-line-args*)]
(babashka.tasks/run task))

borkdude10:12:11

then:

~/some-project/my-pkg pkg --args 
should work

borkdude10:12:04

Some people have suggested that bb.edn itself should be made executable, that would make this a bit easier. pkg:

#!/usr/bin/env bb
{:tasks ...}

borkdude10:12:14

(this currently is not supported)

grzm15:12:30

Thanks for the feedback. At first blush, I think making bb.edn executable is a move away from simplicity and being data driven. Not likely a feature I would want to take advantage of, and probably find frustrating to debug in practice.

grzm15:12:36

The script-adjacent bb.edn is interesting. I'll play with that in the future.

borkdude17:12:13

Bb.edn would remain data, it being executable would just mean you wouldn’t have to provide a script wrapper

Nathan Smith18:12:24

Are there any examples of babashka programs that use github actions to release for multiple platforms? I see jet uses CircleCI I think. Looking to see if I can make a release for linux/amd64,mac/amd64,mac/aarch64 and I’m too lazy to write it myself 🙂

borkdude19:12:23

Github actions doesn’t support aarch64 but you can release bb programs as self contained binaries for every platform using GitHub actions

👍 1
borkdude19:12:40

Afk right now, search channel for details

lukasz19:12:54

I've been trying out BuildJet as an alternative runner for GHA - it supports ARM https://buildjet.com/for-github-actions

borkdude20:12:14

For bb I'm using cirrusCI for aarch64 mac and circleci for aarch64 linux and all other stuff, except windows which runs on appveyor

Nathan Smith20:12:16

Right so you just need to cat the uberjar out on each platform. I can probably get by at this point without mac/arm. So do these binaries require a JRE to be present?

borkdude20:12:37

No they don’t and you don’t need to do this ON each platform but FOR each platform. You can build for Windows on Linux as long as you download the Windows binary

💡 1
Nathan Smith21:12:33

Thanks so much for the help. BTW it’s for this https://github.com/smith/esql-tools/tree/main/esqshell, which is a fun side project I’m doing to learn but could become part of a real product some day. Hopefully they don’t rewrite it in go 😄

Nathan Smith23:12:24

Do you happen to know what permissions are needed for that release_artifact script to work? I’m getting a 403 https://github.com/smith/esql-tools/actions/runs/7202008837/job/19619297303

Nathan Smith23:12:25

(nm I think I can set it in the workflow permissions)

Nathan Smith23:12:26

WOO HOO! Good enough, I’m going on holiday for the rest of the year. Thanks again https://github.com/smith/esql-tools/releases

👏 3
borkdude06:12:33

I don’t see any release there

leifericf19:12:36

Would it be feasible to write a little tool (using Babashka) to automatically download the correct and latest binary for each platform and do the concatenation? :thinking_face: Essentially automate the process of creating self-executing binaries.

borkdude19:12:16

of course

🔥 1
leifericf19:12:42

Maybe I'll take a stab at that ☺️

leifericf19:12:31

About to go on paternity leave. If the kid behaves, I might have some time on my hands 😅

👍 2
joshuamz23:12:56

Hello. Has anyone tried to run commands in Babashka in parallel, as you would do with GNU parallel in a shell script? The benefit of parallel is that it automatically parallelize commands execution in as many jobs as virtual CPUs available in the host by default. First I tried Claypoole, but it seems to not be supported in Babashka (there are some custom classes provided by the jar). I could give it a try to manually create as many futures as virtual CPUs and manage them but things might get out of control real quick. Thanks.

Bob B00:12:19

most of core.async is available, and for really quick stuff maybe just pmap (but that uses futures, so you might want a shutdown-agents call at the end)

Bob B00:12:01

$ bb -e '(pmap #(babashka.process/shell "echo" %) (range 10)) (shutdown-agents)'
3
2
6
...

joshuamz00:12:52

Thank you Bob for the recommendation. I'll give pmap a try first.

leifericf19:12:36

Would it be feasible to write a little tool (using Babashka) to automatically download the correct and latest binary for each platform and do the concatenation? :thinking_face: Essentially automate the process of creating self-executing binaries.