This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-13
Channels
- # adventofcode (37)
- # announcements (11)
- # babashka (46)
- # beginners (35)
- # biff (1)
- # clojure (44)
- # clojure-austin (1)
- # clojure-europe (23)
- # clojure-nl (2)
- # clojure-norway (8)
- # clojure-uk (5)
- # conjure (3)
- # cursive (22)
- # data-science (13)
- # docker (11)
- # events (8)
- # hyperfiddle (7)
- # joyride (1)
- # juxt (9)
- # malli (7)
- # matrix (4)
- # pedestal (3)
- # podcasts-discuss (1)
- # portal (1)
- # re-frame (62)
- # reitit (2)
- # releases (1)
- # schema (3)
- # sql (14)
- # squint (3)
- # xtdb (6)
- # yamlscript (4)
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?Looks like theres some relevant discussion https://github.com/babashka/babashka/discussions/869 and https://clojureverse.org/t/help-utilizing-babashka-tasks-globally/8026/2 . Still reading to see what I'm missing.
cat $(which bbthingy)
#!/usr/bin/env bash
set -euo pipefail
bb --config "${UTIL_REPO_ROOT}/bb.edn" --deps-root "${UTIL_REPO_ROOT}" $@
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) 🙂
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
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
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
~/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 PATHand 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))
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 ...}
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.
Bb.edn would remain data, it being executable would just mean you wouldn’t have to provide a script wrapper
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 🙂
Github actions doesn’t support aarch64 but you can release bb programs as self contained binaries for every platform using GitHub actions
thanks!
I've been trying out BuildJet as an alternative runner for GHA - it supports ARM https://buildjet.com/for-github-actions
For bb I'm using cirrusCI for aarch64 mac and circleci for aarch64 linux and all other stuff, except windows which runs on appveyor
about self-contained bins: https://github.com/babashka/babashka/wiki/Self-contained-executable#uberjar
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?
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
ohhhhh
slick
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 😄
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
(nm I think I can set it in the workflow permissions)
WOO HOO! Good enough, I’m going on holiday for the rest of the year. Thanks again ⛄ https://github.com/smith/esql-tools/releases
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.
About to go on paternity leave. If the kid behaves, I might have some time on my hands 😅
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.
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)
$ bb -e '(pmap #(babashka.process/shell "echo" %) (range 10)) (shutdown-agents)'
3
2
6
...