#!/bin/sh

set -e
set -x

build_dest=$1

# ensure we are on the master branch before building
git checkout master

PATH=$HOME/.local/bin:$PATH BUILDDIR=${build_dest} make deps build

# build again, this time to /en/dev
dev_build_dest=$1/en/dev
PATH=$HOME/.local/bin:$PATH BUILDDIR=${dev_build_dest} make deps build

# also build each version of the docs out to /en/<tag>
# NOTE(bacongobbler): do not build any pre-release tags
for tag in $(git tag | grep -v -- "-alpha\|-beta\|-rc"); do
  tag_build_dest="$build_dest/en/$tag"
  git checkout $tag
  PATH=$HOME/.local/bin:$PATH BUILDDIR=${tag_build_dest} make deps build
done
