#!/bin/sh
# In a git/autoconf/automake-enabled project with a NEWS file and a version-
# controlled .prev-version file, automate the procedure by which we record
# the date, release-type and version string in the NEWS file. That commit
# will serve to identify the release, so apply a signed tag to it as well.
VERSION=2010-06-07.07 # UTC
# Note: this is a bash script (could be zsh or dash)
# Copyright (C) 2009-2011 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# Written by Jim Meyering
ME=`basename "$0"`
warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
die() { warn "$*"; exit 1; }
help_version()
{
case $1 in
--help) cat <.
EOF
exit ;;
--version)
year=`echo "$VERSION" | sed 's/[^0-9].*//'`
cat <
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
EOF
exit ;;
*) die "unrecognized option: $1";;
esac
}
case $# in
1) help_version $1; exit 0;;
2) ;;
*) warn "Usage: $ME VERSION TYPE"; exit 1;;
esac
ver=$1
type=$2
# Verify that $ver looks like a version number, and...
echo "$ver"|grep -E '^[0-9][0-9.]*[0-9]$' > /dev/null \
|| die "invalid version: $ver"
prev_ver=$(cat .prev-version) \
|| die 'failed to determine previous version number from .prev-version'
# Verify that $ver is sensible (> .prev-version).
case $(printf "$prev_ver\n$ver\n"|sort -V -u|tr '\n' ':') in
"$prev_ver:$ver:") ;;
*) die "invalid version: $ver";;
esac
case $type in
alpha|beta|stable) ;;
*) die "invalid release type: $type";;
esac
# Extract package name from Makefile.
pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' Makefile) \
|| die 'failed to determine package name from Makefile'
# simple check: no question marks on line 3 of NEWS
noteworthy='* Noteworthy changes in release'
test "$(sed -n 3p NEWS)" = "$noteworthy ?.? (????-??-??) [?]" \
|| die 'line 3 of NEWS looks fishy!'
# No dirt allowed.
case $(git diff-index --name-only HEAD) in
'') ;;
*) die 'this tree is dirty; commit your changes first';;
esac
# update NEWS to have today's date, plus desired version number and $type
perl -MPOSIX -ni -e 'my $today = strftime "%F", localtime time;' \
-e 'my ($type, $ver) = qw('"$type $ver"');' \
-e 'my $pfx = "'"$noteworthy"'";' \
-e 'print $.==3 ? "$pfx $ver ($today) [$type]\n" : $_' \
NEWS || die 'failed to update NEWS'
# Ensure the current branch name is "master":
curr_br=$(git rev-parse --symbolic-full-name HEAD)
test "$curr_br" = refs/heads/master || die not on master
printf "version $ver\n\n* NEWS: Record release date.\n" \
| git commit -F - -a || die 'git commit failed'
git tag -s -m "$pkg $ver" v$ver HEAD || die 'git tag failed'
# Local variables:
# indent-tabs-mode: nil
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "VERSION="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: " # UTC"
# End: