deploy 1.18 KB
#!/usr/bin/env bash

set -euo pipefail

poll() {
	local OPTIND
	declare interval=1 count check n=0

	while getopts ":t:n:i:" opt; do
		case "${opt}" in
			t)
				check="${OPTARG}"
				;;
			n)
				count="${OPTARG}"
				;;
			i)
				interval="${OPTARG}"
				;;
			:)
				echo "Option: -${OPTARG} requires an argument" 1>&2
				return 1
				;;
			*)
				echo "Options: -inc" 1>&2
				return 1
		esac
	done

	if [ -z "${check}" ] || [ -z "${count}" ]; then
		echo "-t and -n required" 1>&2
		return 1
	fi

	echo "Running ${check} ${count} times at ${interval} second intervals"

	while [ "${n}" -lt "${count}" ]; do
		if "${check}" ; then
			echo "${check} passed"
			return 0
		fi

		n="$(( n + 1 ))"
		sleep "${interval}"
	done

	echo "Check timed-out: ${check}" 1>&2
	return 1
}

test_cloudformation_status() {
	bin/blog status | egrep -q "UPDATE_COMPLETE|CREATE_COMPLETE"
}

make clean dist

poll -t test_cloudformation_status -n 20 -i 5

bin/blog deploy

poll -t test_cloudformation_status -n 100 -i 5

declare url sentinel
url="$(bin/blog url)"
sentinel="$(git rev-parse --short HEAD)"

test_publish() {
	curl -s "${url}/_sentinel/${sentinel}.txt" > /dev/null
}

bin/blog publish

poll -t test_publish -n 120