Skip to content

Instantly share code, notes, and snippets.

@tomtaylor
Last active December 25, 2015 20:59
Show Gist options
  • Select an option

  • Save tomtaylor/7039271 to your computer and use it in GitHub Desktop.

Select an option

Save tomtaylor/7039271 to your computer and use it in GitHub Desktop.
Build script for Buildbox.io, which uses parallel-tests to run multiple parallel test processes, and notifies Campfire on start, success and error.
#!/bin/bash
# Exits bash immediately if any command fails
set -e
# Will echo commands as the run
set -x
# Configure these
BUILDBOX_TEAM=""
BUILDBOX_PROJECT=""
CAMPFIRE_KEY=""
CAMPFIRE_SUBDOMAIN=""
CAMPFIRE_ROOM_ID=""
# You probably don't need to configure these
PERMALINK="https://app.buildbox.io/$BUILDBOX_TEAM/$BUILDBOX_PROJECT/builds/$BUILDBOX_BUILD_ID"
CAMPFIRE_POST_URL="https://$CAMPFIRE_SUBDOMAIN.campfirenow.com/room/$CAMPFIRE_ROOM_ID/speak.xml"
GIT_COMMIT=${BUILDBOX_COMMIT:0:6}
announce_success () {
curl -u $CAMPFIRE_KEY:X -H 'Content-Type: application/xml' \
-d "<message><body>:thumbsup: [$BUILDBOX_PROJECT] Built $BUILDBOX_BRANCH @ $GIT_COMMIT by $GIT_AUTHOR successfully. \"$GIT_MESSAGE\"</body></message>" $CAMPFIRE_POST_URL
}
announce_failure () {
curl -u $CAMPFIRE_KEY:X -H 'Content-Type: application/xml' \
-d "<message><body>:thumbsdown: [$BUILDBOX_PROJECT] Failed to build $BUILDBOX_BRANCH @ $GIT_COMMIT by $GIT_AUTHOR. \"$GIT_MESSAGE\" $PERMALINK</body></message>" $CAMPFIRE_POST_URL
}
announce_start () {
curl -u $CAMPFIRE_KEY:X -H 'Content-Type: application/xml' \
-d "<message><body>:punch: [$BUILDBOX_PROJECT] Started build of $BUILDBOX_BRANCH @ $GIT_COMMIT by $GIT_AUTHOR. \"$GIT_MESSAGE\" $PERMALINK</body></message>" $CAMPFIRE_POST_URL
}
trap announce_failure ERR
# If the git repo doesn't exist, let's fetch it.
if [ ! -d ".git" ]; then
git clone "$BUILDBOX_REPO" . -q
fi
# Always start with a clean repo.
git clean -fd
# Fetch the latest commits from origin, and checkout to the commit being tested.
git fetch -q
git checkout -qf "$BUILDBOX_COMMIT"
GIT_MESSAGE=`git log --pretty="%s" -n1 $BUILDBOX_COMMIT`
GIT_AUTHOR=`git log --pretty="%an" -n1 $BUILDBOX_COMMIT`
announce_start
# Workaround path being set by agent's rbenv environment.
RUBY_VERSION=`cat .ruby-version`
export RBENV_VERSION="$RUBY_VERSION"
export PATH="$HOME/.rbenv/shims":$PATH
# Install the Ruby we're looking for, if necessary.
if [ ! -d "$HOME/.rbenv/versions/$RUBY_VERSION" ]; then
rbenv install "$RUBY_VERSION"
rbenv rehash
fi
gem install bundler --no-rdoc --no-ri
# Keep gems local to this project with --deployment.
bundle install --deployment
# Copy the config.yml in.
cp "$HOME/configs/$BUILDBOX_PROJECT_config.yml" "config/config.yml"
# Copy the database.yml and suffix the database name in the yml file with the number of the test worker, to isolate databases for each parallel process
cat "$HOME/configs/$BUILDBOX_PROJECT_database.yml" | sed 's/\(database: .*\)/\1<%= ENV["TEST_ENV_NUMBER"] %>/g' > "config/database.yml"
bundle exec rake "parallel:rake[db:drop:all db:create:all db:structure:load]"
bundle exec rake parallel:test
# Woo!
announce_success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment