Fork me on GitHub
#babashka
<
2020-03-10
>
mkvlr09:03:50

does someone here have a recommendation for a bash script to download babashka?

mkvlr09:03:06

weโ€™d like to avoid adding it to the repo given the frequency of releases

borkdude09:03:37

@mkvlr There is an install script in the repo

borkdude09:03:09

bash <(curl -s )

borkdude09:03:43

what is "the repo" in your case?

mkvlr09:03:55

was also thinking about pinning the versionโ€ฆ

mkvlr09:03:18

our nextjournal monorepo

borkdude09:03:35

well, either pin the version of update frequently. aren't those two contradicting? ๐Ÿ™‚

borkdude09:03:55

you can just download the binary from github releases to have a pinned version

mkvlr09:03:03

yes, I was thinking of having something in the repo that says BABASHA_VERSION=v0.0.75 and when I update it to 0.0.76 everybody gets the latest version

mkvlr09:03:44

so 1) not have a binary in the repo but only the version string, and 2) having a bash script that checks, do I have this version, if not download it

borkdude09:03:46

@mkvlr

[email protected] /tmp $ export BABASHKA_VERSION=0.0.75
[email protected] /tmp $ curl -sL  -o bb.zip
[email protected] /tmp $ unzip bb.zip
Archive:  bb.zip
  inflating: bb
[email protected] /tmp $ ./bb --version
babashka v0.0.75

mkvlr09:03:54

@borkdude and is having ./bin/bb be a bash script that does that if needed a bad idea?

mkvlr09:03:54

(and unzipping it to "bb-$(BABASHKA_VERSION)" and executing it?

borkdude09:03:42

@mkvlr You could so something like this:

#!/usr/bin/env bb

(require '[clojure.java.shell :refer [sh]]
         '[clojure.string :as str]
         '[babashka.curl :as curl])

(def current-version (str/trim (:out (sh "bb" "--version"))))
(def desired-version (System/getenv "BABASHKA_VERSION"))

(if (str/ends-with? current-version desired-version)
  (println (format "Babashka version %s already installed." desired-version))
  (do (println (format "Downloading babashka version %s..." desired-version))
      (curl/get (str/replace "" "$BABASHKA_VERSION" desired-version)
                {:raw-args ["-o" "bb.zip" "-L"]})
      (sh "unzip" "bb.zip")))

borkdude09:03:02

but you would need at least one version of bb to bootstrap ๐Ÿ™‚

borkdude09:03:28

I don't think the bash script is a bad idea at all.

borkdude09:03:58

you can download bb just the way you want, there is no preferred way. just download the binary, place it on the path and run.

mkvlr10:03:25

alright, thanks for you help!

mkvlr10:03:25

#!/bin/bash
# this scripts downlaods babashka when needed and runs it

name=babashka
version="0.0.75"
install_dir="$(pwd)/.store/$name-$version"

if ! [[ -f "$install_dir/bb" ]]; then
  case "$(uname -s)" in
      Linux*)     platform=linux;;
      Darwin*)    platform=macos;;
  esac

  echo "$name $version not found, installing to $install_dir..."
  download_url=""

  mkdir -p $install_dir
  echo -e "Downloading $download_url."
  curl -o bb.zip -sL "$download_url"
  unzip -qqo "bb.zip" -d $install_dir
  rm "bb.zip"
fi
exec ./.store/$name-$version/bb "[email protected]"

๐Ÿ’ฏ 1
mkvlr10:03:28

this is what I came up with

borkdude10:03:18

makes a lot of sense

borkdude10:03:45

and then you symlink it to the path or something?

borkdude10:03:22

or is this a wrapper around bb?

mkvlr10:03:40

put it in bin/bb

mkvlr10:03:48

and have ./bin in the path in our project

borkdude10:03:56

ah right. I guess that makes sense.

mkvlr10:03:13

and use the vendored bb in our checked in scripts

mkvlr10:03:37

I hope thatโ€™s the last bash script I wrote

๐Ÿ˜„ 2
kommen12:03:42

I have to say, once you write babashka scripts, one never wants to go back to bash ๐Ÿ˜‰

clj 1
babashka 1
๐ŸŽ‰ 1
porkostomus14:03:05

I've noticed that a large number of people using it are not even Clojure people, at least judging by their projects on github. Lots of Go and Python. This I think is a really good thing

๐Ÿ‘€ 2
borkdude15:03:45

@porkostomus cool. where did you see this?

porkostomus15:03:50

Just by snooping on folks who have starred 4bb

teodorlu13:03:35

is 4bb like 4clojure? :thinking_face:

porkostomus17:03:39

Well to be fair, 4clojure is a complete webapp and this is just a script I made to run the problems from the command-line, but yes ๐Ÿค“

porkostomus15:03:37

(very small sample size, but hey ๐Ÿ˜œ)

borkdude15:03:05

still cool ๐Ÿ˜‰

jeroenvandijk20:03:53

I had to verify if there was an issue with Github Actions so I used babashka as an example https://github.com/jeroenvandijk/babashka/runs/498935151?check_suite_focus=true Everything builds ๐Ÿ™‚

jeroenvandijk20:03:07

Here is a pull request https://github.com/borkdude/babashka/pull/291 Feel free to ignore ๐Ÿ™‚

borkdude21:03:47

@jeroenvandijk Thanks. I already had an issue and a branch for Github actions: https://github.com/borkdude/babashka/issues/279 But I'll use yours to study how you did things and borrow a thing or two!

๐Ÿ‘Œ 1