#!/bin/bash

VERSION_NUMBER=$1

git config --global user.email "tripleabuilderbot@gmail.com"
git config --global user.name "tripleabuilderbot"

git clone --quiet https://${PUSH_TO_WEBSITE_TOKEN}@github.com/triplea-game/triplea-game.github.io.git website

#Clear directory
rm ./website/_maps/*
#Split the yaml file into multiple files
./.travis/yaml_splitter ./triplea_maps.yaml ./website/_maps/

## do git stuff, check if there is a diff, if so, commit and push it
cd website
if ! git diff-index --quiet HEAD --; then
  git add  --all _maps/
  git commit -m "Bot: update map files after game engine build $VERSION_NUMBER"
  git push -fq origin master
fi

cd ..
rm -rf website
