#!/bin/sh
set -e
git submodule init
git submodule update
rm -f Gemfile.lock
bundle install --path "${HOME}/bundles/${JOB_NAME}"
bundle exec rake
bundle exec rake publish_gem

#!/bin/sh
set -e

# Checkout master as we are currently have an individual commit checked out on
# a detached tree. This means when we commit later it will be on a branch
git checkout master
git reset --hard origin/master

# Init the submodule and checkout the revision pinned in `.gitmodules`
git submodule update --init

# The version of the toolkit defined by the pinned submodule
PINNED_SUBMODULE_VERSION=`cat app/assets/VERSION.txt`

# Force the submodule to pull the latest and checkout origin/master
git submodule foreach git pull origin master

# The version of the toolkit defined in the submodules master branch
NEW_SUBMODULE_VERSION=`cat app/assets/VERSION.txt`

# Install gem dependencies, run tests, publish gem
rm -f Gemfile.lock
bundle install --path "${HOME}/bundles/${JOB_NAME}"
bundle exec rake

# If the submodule has a new version string
if [ "$PINNED_SUBMODULE_VERSION" != "$NEW_SUBMODULE_VERSION" ]; then
  # Commit the updated submodule and push it to origin
  git commit -am "Bump to version $PINNED_SUBMODULE_VERSION"
  git push origin master
fi

# Publish the new gem
bundle exec rake publish_gem

Update submodule and commit after gem publish
Update submodule and commit after gem publish

This lets us set the jenkins job for this repo as a post commit hook to
the govuk_frontend_toolkit repo. It will ensure the gem is always up to
date with that repository.

Bumping the gem will then be a fully automatic process controlled by the
govuk_frontend_toolkit repo.
