Skip to content

Commit

Permalink
fix: use bundler to manage ruby environment (#15)
Browse files Browse the repository at this point in the history
use bundler to create an isolated environment and install dependencies
into it

then use it to execute bashly within that environment
  • Loading branch information
pcrockett authored Nov 11, 2024
1 parent 19b098a commit a4fffa2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/bashly_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -Eeuo pipefail
current_script_path=${BASH_SOURCE[0]}
bin_dir="$(dirname "${current_script_path}")"
install_dir="$(dirname "${bin_dir}")"
gem_home="${install_dir}/gem_home"
gem_home="${install_dir}/gem"

GEM_HOME="${gem_home}" "${gem_home}/bin/bashly" "${@}"
PATH="${gem_home}/bin:${PATH}" \
BUNDLE_GEMFILE="${install_dir}/Gemfile" \
BUNDLE_PATH="${install_dir}/artifacts" \
bundle exec bashly "${@}"
36 changes: 34 additions & 2 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,47 @@ list_all_versions() {
list_github_tags
}

ensure_bundler() {
if command -v bundle &>/dev/null && bundle --version &>/dev/null; then
return 0
fi

gem install --no-user-install bundler
}

create_bundle() {
local working_dir="${1}"
pushd "${working_dir}" &>/dev/null

ensure_bundler
bundle init
mkdir -p artifacts
bundle config set path artifacts
bundle add bashly --version "= ${version}"

# get rid of warnings at runtime
#
# these deps are in the ruby stdlib, but will soon
# be moved to their own gems. installing them gets
# rid of that warning.
bundle add fiddle
bundle add logger

popd &>/dev/null
}

download_release() {
local version download_dir
version="$1"
download_dir="$2"

local gem_home="${download_dir}/gem_home"
local gem_home="${download_dir}/gem"
mkdir -p "${gem_home}"

GEM_HOME="${gem_home}" gem install "${TOOL_NAME}:${version}"
GEM_HOME="${gem_home}" \
GEM_PATH="${gem_home}" \
PATH="${gem_home}/bin:${PATH}" \
create_bundle "${download_dir}"
}

install_version() {
Expand Down

0 comments on commit a4fffa2

Please sign in to comment.