push-site.sh 1.1 KB
Newer Older
1
#! /usr/bin/env bash
Kenton Varda's avatar
Kenton Varda committed
2 3

set -eu
4
shopt -s extglob
Kenton Varda's avatar
Kenton Varda committed
5

Kenton Varda's avatar
Kenton Varda committed
6 7 8 9 10
if grep 'localhost:4000' *.md _posts/*.md; then
  echo "ERROR: Your content has links to localhost:4000!" >&2
  exit 1
fi

Kenton Varda's avatar
Kenton Varda committed
11
if [ "x$(git status --porcelain)" != "x" ]; then
12 13 14 15 16 17
  echo -n "git repo has uncommited changes.  Continue anyway? (y/N) " >&2
  read -n 1 YESNO
  echo >&2
  if [ "x$YESNO" != xy ]; then
    exit 1
  fi
Kenton Varda's avatar
Kenton Varda committed
18 19
fi

20 21 22 23 24 25
case $(git rev-parse --abbrev-ref HEAD) in
  master )
    echo "On master branch.  Will generate to /next."
    CONFIG=_config_next.yml
    PREFIX=/next
    LABEL="preview site"
26
    FUTURE=--future
27 28 29 30 31 32 33
    ;;

  release-* )
    echo "On release branch.  Will generate to /."
    CONFIG=_config.yml
    PREFIX=
    LABEL="site"
34
    FUTURE=
35 36 37 38 39 40 41 42
    ;;

  * )
    echo "Unrecognized branch." >&2
    exit 1
    ;;
esac

Kenton Varda's avatar
Kenton Varda committed
43
echo "Regenerating site..."
Kenton Varda's avatar
Kenton Varda committed
44

45
rm -rf _site _site.tar.gz
Kenton Varda's avatar
Kenton Varda committed
46

47
jekyll build --safe $FUTURE --config $CONFIG
Kenton Varda's avatar
Kenton Varda committed
48 49 50 51 52

echo -n "Push now? (y/N)"
read -n 1 YESNO
echo

53
if [ "x$YESNO" == "xy" ]; then
54
  echo "Pushing..."
55
  tar cz --xform='s,_site/,,' _site/* | gce-ss ssh fe --command "cd /var/www/capnproto.org$PREFIX && tar xz"
Kenton Varda's avatar
Kenton Varda committed
56
else
57
  echo "Push CANCELED"
Kenton Varda's avatar
Kenton Varda committed
58
fi