#!/usr/bin/env bash
# Run script/sync-data and push changes.

set -e

echo "===> Syncing data"
script/sync-data

git diff --quiet || {
  echo "===> Committing and pushing changes"
  git commit -am "Sync data"

  REPO=`git config remote.origin.url`

  # If GH_TOKEN environment variable is present, use that to push.
  if [[ -n "$GH_TOKEN" ]]; then
    REPO=${REPO/https:\/\//https://${GH_TOKEN}@}
  fi

  git push $REPO HEAD:master
}
