summaryrefslogtreecommitdiff
path: root/script/deploy
blob: 1e71b2487e63931abcb9025e95468b89e1b3eabb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#! /bin/sh

# Deploy the static website.
#
# Re-generates the static website from source and asserts a clean working tree
# before uploading the website to the server.
#
# Submits the sitemap URL to Google and Bing.

set -o errexit
set -o nounset

RSYNC="$( command -v openrsync || command -v rsync )"

ask_proceed() {
  printf 'Proceed? (y/N): '
  read -r REPLY
  case "$REPLY" in
    y|yes|Y|YES) return 0 ;;
    *) return 1 ;;
  esac
}

# Git root directory
root="$( git rev-parse --show-toplevel )"

# Source directory with a trailing slash for rsync
src="${root}/_site/"

# Git revision
rev="$( git rev-parse --verify HEAD )"

# ISO 8601 timestamp
now="$( date -u "+%Y-%m-%dT%H:%M:%SZ" )"

# Archive file name
archive="./${now}-${rev}.tar.gz"

echo "Re-generating static website from source ..."
( cd "${root}" \
  && cabal v2-run exe:site -- clean >/dev/null 2>&1 \
  && cabal v2-run exe:site -- build >/dev/null 2>&1 )

echo "Running checks ..."
( cd "${root}" && ./script/check ) || {
  ( >&2 echo "error: check failed" )
  ask_proceed
}

[ -z "$( git status --porcelain )" ] || {
  ( >&2 echo "error: dirty working tree" )
  ask_proceed
}

"$RSYNC" --rsync-path=openrsync --archive --delete --verbose \
  "${src}" "engine.skreutz.com:/var/www/htdocs/www.skreutz.com"

tar -czf "${archive}" "${src}"
scp "${archive}" engine.skreutz.com:archive/www/
rm "${archive}"

curl \
  --silent \
  --output /dev/null \
  http://www.google.com/ping?sitemap=https://www.skreutz.com/sitemap.xml \
  || ( >&2 echo "error: failed to submit live sitemap to google.com" )

curl \
  --silent \
  --output /dev/null \
  http://www.bing.com/ping?sitemap=https%3A%2F%2Fwww.skreutz.com/sitemap.xml \
  || ( >&2 echo "error: failed to submit live sitemap to bing.com" )
Generated by cgit. See skreutz.com for my tech blog and contact information.