#!/bin/sh
set -e
log() { echo -e "\033[36m$@\033[39m"; }

# Special treatment for the "master" branch to deploy to /documentation instead
# of /master
target="${CI_BRANCH}"
if [ "${CI_BRANCH}" = "master" ]; then
	target="documentation"
fi

# Where do we want to generate the site at?
destination="/site/$target"
if [ "${destination}" != "/site/" ]; then
	rm -rf "${destination}" && mkdir -p "${destination}"
fi

# Jet release notes and current version
jet_source="/site/.jet"
if [ -f "_data/jet.yml" ]; then
	sed -i'' -e "s|^version:.*|version: $(cat ${jet_source}/version)|" "_data/jet.yml"
fi
if [ -f "_posts/docker/jet/2015-07-16-release-notes.md" ]; then
	cat "${jet_source}/release-notes" >> "_posts/docker/jet/2015-07-16-release-notes.md"
fi
rm -rf "${jet_source}"

# Compile the site
log "Building with base URL /${target}"
sed -i'' -e "s|^baseurl:.*|baseurl: /${target}|" _config.yml
bundle exec jekyll build --destination "${destination}"

#!/bin/sh
set -e
log() { echo -e "\033[36m$@\033[39m"; }

# Special treatment for the "master" branch to deploy to /documentation instead
# of /master
target="${CI_BRANCH}"
if [ "${CI_BRANCH}" = "master" ]; then
	target="documentation"
fi

# Where do we want to generate the site at?
destination="/site/$target"
if [ "${destination}" != "/site/" ]; then
	rm -rf "${destination}" && mkdir -p "${destination}"
fi

# Jet release notes and current version
jet_source="/site/.jet"
if [ -f "_data/jet.yml" ]; then
	sed -i'' -e "s|^version:.*|version: $(cat ${jet_source}/version)|" "_data/jet.yml"
fi
if [ -f "_posts/docker/jet/2015-07-16-release-notes.md" ]; then
	cat "${jet_source}/release-notes" >> "_posts/docker/jet/2015-07-16-release-notes.md"
fi
rm -rf "${jet_source}"

if [ "${CI_BRANCH}" = "master" ]; then
	log "Preparing for move to documentation.codeship.com"
	log "Building with base URL /"
	sed -i'' -e "s|^baseurl:.*|baseurl: /|" _config.yml
	bundle exec jekyll build --destination "/site/"
fi

# Compile the site
log "Building with base URL /${target}"
sed -i'' -e "s|^baseurl:.*|baseurl: /${target}|" _config.yml
bundle exec jekyll build --destination "${destination}"

Deploy the master branch to the bucket root too
Deploy the master branch to the bucket root too

For the `master` branch, generate the site twice, once at the root of the destination
folder and once in the `/documentation` subfolder.

This is a preparatory step for moving the documentation from
http://codeship.com/documentation to http://documentation.codeship.com. In a further PR
we will need to update the `robots.txt` to allow robots access directly via the bucket and
the S3 website configuration to redirect switch redirects to the new location.
