1#!/bin/sh
2# In a git/autoconf/automake-enabled project with a NEWS file and a version-
3# controlled .prev-version file, automate the procedure by which we record
4# the date, release-type and version string in the NEWS file.  That commit
5# will serve to identify the release, so apply a signed tag to it as well.
6VERSION=2012-08-01.09 # UTC
7
8# Make sure we've evaluated scripts we depend on.
9test -z "$progpath" && . `echo "$0" |${SED-sed} 's|[^/]*$||'`/funclib.sh
10
11# Note: this is a bash script (could be zsh or dash)
12
13# Copyright (C) 2009-2015 Free Software Foundation, Inc.
14
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23# GNU General Public License for more details.
24
25# You should have received a copy of the GNU General Public License
26# along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
28# Written by Jim Meyering
29
30ME=$(basename "$0")
31warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
32die() { warn "$*"; exit 1; }
33
34help()
35{
36  cat <<EOF
37Usage: $ME [OPTION...] VERSION RELEASE_TYPE
38
39Run this script from top_srcdir to perform the final pre-release NEWS
40update in which the date, release-type and version string are
41recorded.  Commit that result with a log entry marking the release,
42and apply a signed tag.  Run it from your project's top-level
43directory.
44
45Requirements:
46- you use git for version-control
47- a version-controlled .prev-version file
48- a NEWS file, with line 3 identical to this:
49$noteworthy_stub
50
51Options:
52  --branch=BRANCH     set release branch (default: $branch)
53  -C, --builddir=DIR  location of (configured) Makefile (default: $builddir)
54  --help              print this help, then exit
55  --version           print version number, then exit
56
57EXAMPLE:
58To update NEWS and tag the beta 8.1 release of coreutils, I would run this:
59
60  $ME 8.1 beta
61
62Report bugs and patches to <bug-gnulib@gnu.org>.
63EOF
64  exit
65}
66
67version()
68{
69  year=$(echo "$VERSION" | sed 's/[^0-9].*//')
70  cat <<EOF
71$ME $VERSION
72Copyright (C) $year Free Software Foundation, Inc,
73License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
74This is free software: you are free to change and redistribute it.
75There is NO WARRANTY, to the extent permitted by law.
76EOF
77  exit
78}
79
80## ------ ##
81## Main.  ##
82## ------ ##
83
84# Constants.
85noteworthy='* Noteworthy changes in release'
86noteworthy_stub="$noteworthy ?.? (????-??-??) [?]"
87
88# Variables.
89branch=$(git branch | sed -ne '/^\* /{s///;p;q;}')
90builddir=.
91
92while test $# != 0
93do
94  # Handle --option=value by splitting apart and putting back on argv.
95  case $1 in
96    --*=*)
97      opt=$(echo "$1" | sed -e 's/=.*//')
98      val=$(echo "$1" | sed -e 's/[^=]*=//')
99      shift
100      set dummy "$opt" "$val" ${1+"$@"}; shift
101      ;;
102  esac
103
104  case $1 in
105    --help|--version) ${1#--};;
106    --branch) shift; branch=$1; shift ;;
107    -C|--builddir) shift; builddir=$1; shift ;;
108    --*) die "unrecognized option: $1";;
109    *) break;;
110  esac
111done
112
113test $# = 2 \
114  || die "Usage: $ME [OPTION...] VERSION TYPE"
115
116ver=$1
117type=$2
118
119
120## ---------------------- ##
121## First, sanity checks.  ##
122## ---------------------- ##
123
124# Verify that $ver looks like a version number, and...
125echo "$ver"|grep -E '^[0-9][0-9.]*[0-9]$' > /dev/null \
126  || die "invalid version: $ver"
127prev_ver=$(cat .prev-version) \
128  || die 'failed to determine previous version number from .prev-version'
129
130# Verify that $ver is sensible (> .prev-version).
131func_lt_ver "$prev_ver" "$ver" \
132  || die "invalid version: $ver (<= $prev_ver)"
133
134case $type in
135  alpha|beta|stable) ;;
136  *) die "invalid release type: $type";;
137esac
138
139# No local modifications allowed.
140case $(git diff-index --name-only HEAD) in
141  '') ;;
142  *) die 'this tree is dirty; commit your changes first';;
143esac
144
145# Ensure the current branch name is correct:
146curr_br=$(git rev-parse --symbolic-full-name HEAD)
147test "$curr_br" = refs/heads/$branch || die not on branch $branch
148
149# Extract package name from Makefile.
150Makefile=$builddir/Makefile
151pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' "$Makefile") \
152  || die "failed to determine package name from $Makefile"
153
154# Check that line 3 of NEWS is the stub line about to be replaced.
155test "$(sed -n 3p NEWS)" = "$noteworthy_stub" \
156  || die "line 3 of NEWS must be exactly '$noteworthy_stub'"
157
158## --------------- ##
159## Then, changes.  ##
160## --------------- ##
161
162# Update NEWS to have today's date, plus desired version number and $type.
163perl -MPOSIX -ni -e 'my $today = strftime "%F", localtime time;' \
164 -e 'my ($type, $ver) = qw('"$type $ver"');' \
165 -e 'my $pfx = "'"$noteworthy"'";' \
166 -e 'print $.==3 ? "$pfx $ver ($today) [$type]\n" : $_' \
167     NEWS || die 'failed to update NEWS'
168
169printf "version $ver\n\n* NEWS: Record release date.\n" \
170    | git commit -F -  -a || die 'git commit failed'
171git tag -s -m "$pkg $ver" v$ver HEAD || die 'git tag failed'
172
173# Local variables:
174# indent-tabs-mode: nil
175# eval: (add-hook 'write-file-hooks 'time-stamp)
176# time-stamp-start: "VERSION="
177# time-stamp-format: "%:y-%02m-%02d.%02H"
178# time-stamp-time-zone: "UTC"
179# time-stamp-end: " # UTC"
180# End:
181