Merge pull request #3302 from mkllnk/74-bundler-version

Add script to install required bundler version
This commit is contained in:
Maikel
2019-01-15 09:36:18 +11:00
committed by GitHub
2 changed files with 43 additions and 1 deletions

42
script/install-bundler Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/sh
# This shell script looks for the last used Bundler version in Gemfile.lock and
# installs exactly that version, removing all other versions.
# Command line arguments are passed on to `gem install`. So you can call this
# script with with arguments:
#
# ./script/install-bundler --no-ri --no-rdoc
# This script is used by ofn-install and can by handy in your development
# environment.
# Fail if a single command fails.
set -e
# `grep -m 1`: find the first occurrence of "BUNDLED WITH"
# `-A`: print the next line after "BUNDLED WITH" as well
# `-x -F`: find exactly that string without interpreting regex
# `tail -n 1`: take the last line, the version line
# `tr -d`: delete all spaces, the indent before the version
version="$(grep -m 1 -A 1 -x -F "BUNDLED WITH" Gemfile.lock | tail -n 1 | tr -d '[:space:]')"
# if the length of $version is zero
if [ -z "$version" ]; then
echo >&2 "No bundler version in Gemfile.lock."
exit 1
fi
# Get the currently used bundler version.
# We ignore all errors with `2>/dev/null || true` in case there is no bundler
# or only an orphaned shim installed.
current="$(bundler --version 2>/dev/null || true)"
if [ "$current" = "Bundler version $version" ]; then
echo >&2 "Already up-to-date: $current"
exit 0
fi
# Passing on all arguments of this script with "$@".
gem install bundler -v "$version" "$@"
gem uninstall bundler -v "!= $version" 2>/dev/null || true

View File

@@ -33,7 +33,7 @@ fi
# Set up Ruby dependencies via Bundler
if ! command -v bundle > /dev/null; then
gem install bundler
./script/install-bundler
fi
# Install all dependencies