#!/bin/bash set -eu -o pipefail changelog=$(cat Changes.md) regex='## ([0-9]+\.[0-9]+\.[0-9]+) - ([0-9]{4}-[0-9]{2}-[0-9]{2}) ((.| )*) ' if [[ ! $changelog =~ $regex ]]; then echo "Could not find date line in change log!" exit 1 fi version="${BASH_REMATCH[1]}" date="${BASH_REMATCH[2]}" notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^## [0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')" dist="libmaxminddb-$version.tar.gz" if [[ "$date" != $(date +"%Y-%m-%d") ]]; then echo "$date is not today!" exit 1 fi if [ -n "$(git status --porcelain)" ]; then echo ". is not clean." >&2 exit 1 fi old_version=$(perl -MFile::Slurp=read_file <&2 exit 1 fi index=index.md cat < $index --- layout: default title: libmaxminddb - a library for working with MaxMind DB files version: $version --- EOF cat ../doc/libmaxminddb.md >> $index mmdblookup=mmdblookup.md cat < $mmdblookup --- layout: default title: mmdblookup - a utility to look up an IP address in a MaxMind DB file version: $version --- EOF cat ../doc/mmdblookup.md >> $mmdblookup git commit -m "Updated for $version" -a read -p "Push to origin? (y/n) " should_push if [ "$should_push" != "y" ]; then echo "Aborting" exit 1 fi git push popd git push message="$version $notes" hub release create -a "$dist" -m "$message" "$version"