summaryrefslogtreecommitdiff
path: root/scripts/rails-update-bisect
blob: 77a01e2dadc61f988211064b8d61adb801e37041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
GITLAB_DIR="$(dirname "$SCRIPT_DIR")"

# Because this script is intended to be run with `git bisect run`,
# we are returning `-1` status code to alert `git bisect` of failures.
#
# See: https://git-scm.com/docs/git-bisect#_bisect_run
#
abort_bisect () {
  exit -1
}

if [ $# -eq 0 ]; then
  echo "No arguments supplied. Please provide spec file(s) as first argument(s)"
  abort_bisect
fi

[[ -z "${RAILS_FOLDER}" ]] && { echo >&2 "RAILS_FOLDER env variable is not set"; abort_bisect; }

if ! grep -q -E "gem 'rails'.+RAILS_VERSION.+RAILS_FOLDER" $GITLAB_DIR/Gemfile; then
  echo "Gemfile is not modified"
  echo "Please alter the gem 'rails' line in Gemfile with:"
  echo "gem 'rails', ENV['RAILS_VERSION'], path: ENV['RAILS_FOLDER']"
  abort_bisect
fi

export RAILS_VERSION=$(cat $RAILS_FOLDER/RAILS_VERSION)

cd $GITLAB_DIR && \
echo "Updating dependencies... this could take a while." && \
bundle update rails --quiet

test $? -eq 0 || { echo >&2 "bundle update has failed"; abort_bisect; }

# Stop spring if it's installed
command -v spring >/dev/null 2>&1 && spring stop

bin/rspec $@