ca89bdc9db705a6e54f52c52d3ab6160853d7a72
[gnulib.git] / build-aux / do-release-commit-and-tag
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.
6 VERSION=2010-06-07.07 # UTC
7
8 # Note: this is a bash script (could be zsh or dash)
9
10 # Copyright (C) 2009-2011 Free Software Foundation, Inc.
11
12 # This program is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
16
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21
22 # You should have received a copy of the GNU General Public License
23 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
25 # Written by Jim Meyering
26
27 ME=`basename "$0"`
28 warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
29 die() { warn "$*"; exit 1; }
30
31 help_version()
32 {
33   case $1 in
34     --help) cat <<EOF
35 Usage: $ME VERSION RELEASE_TYPE
36
37 Run this script to perform the final pre-release NEWS update
38 in which the date, release-type and version string are recorded.
39 Commit that result with a log entry marking the release, and apply
40 a signed tag.  Run it from your project's top-level directory.
41
42 Requirements:
43 - you use git for version-control
44 - a NEWS file, with line 3 identical to this:
45 * Noteworthy changes in release ?.? (????-??-??) [?]
46 - a version-controlled .prev-version file
47
48 Options:
49   --help     print this help, then exit
50   --version  print version number, then exit
51
52 EXAMPLE:
53 To update NEWS and tag the beta 8.1 release of coreutils, I would run this:
54
55   $ME 8.1 beta
56
57 Report bugs and patches to <bug-gnulib@gnu.org>.
58 EOF
59       exit ;;
60
61     --version)
62       year=`echo "$VERSION" | sed 's/[^0-9].*//'`
63       cat <<EOF
64 $ME $VERSION
65 Copyright (C) $year Free Software Foundation, Inc,
66 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
67 This is free software: you are free to change and redistribute it.
68 There is NO WARRANTY, to the extent permitted by law.
69 EOF
70       exit ;;
71
72   *) die "unrecognized option: $1";;
73   esac
74 }
75
76 case $# in
77   1) help_version $1; exit 0;;
78   2) ;;
79   *) warn "Usage: $ME VERSION TYPE"; exit 1;;
80 esac
81
82 ver=$1
83 type=$2
84
85 # Verify that $ver looks like a version number, and...
86 echo "$ver"|grep -E '^[0-9][0-9.]*[0-9]$' > /dev/null \
87   || die "invalid version: $ver"
88 prev_ver=$(cat .prev-version) \
89   || die 'failed to determine previous version number from .prev-version'
90
91 # Verify that $ver is sensible (> .prev-version).
92 case $(printf "$prev_ver\n$ver\n"|sort -V -u|tr '\n' ':') in
93   "$prev_ver:$ver:") ;;
94   *) die "invalid version: $ver";;
95 esac
96
97 case $type in
98   alpha|beta|stable) ;;
99   *) die "invalid release type: $type";;
100 esac
101
102 # Extract package name from Makefile.
103 pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' Makefile) \
104   || die 'failed to determine package name from Makefile'
105
106 # simple check: no question marks on line 3 of NEWS
107 noteworthy='* Noteworthy changes in release'
108 test "$(sed -n 3p NEWS)" = "$noteworthy ?.? (????-??-??) [?]" \
109   || die 'line 3 of NEWS looks fishy!'
110
111 # No dirt allowed.
112 case $(git diff-index --name-only HEAD) in
113   '') ;;
114   *) die 'this tree is dirty; commit your changes first';;
115 esac
116
117 # update NEWS to have today's date, plus desired version number and $type
118 perl -MPOSIX -ni -e 'my $today = strftime "%F", localtime time;' \
119  -e 'my ($type, $ver) = qw('"$type $ver"');' \
120  -e 'my $pfx = "'"$noteworthy"'";' \
121  -e 'print $.==3 ? "$pfx $ver ($today) [$type]\n" : $_' \
122      NEWS || die 'failed to update NEWS'
123
124 # Ensure the current branch name is "master":
125 curr_br=$(git rev-parse --symbolic-full-name HEAD)
126 test "$curr_br" = refs/heads/master || die not on master
127
128 printf "version $ver\n\n* NEWS: Record release date.\n" \
129     | git commit -F -  -a || die 'git commit failed'
130 git tag -s -m "$pkg $ver" v$ver HEAD || die 'git tag failed'
131
132 # Local variables:
133 # indent-tabs-mode: nil
134 # eval: (add-hook 'write-file-hooks 'time-stamp)
135 # time-stamp-start: "VERSION="
136 # time-stamp-format: "%:y-%02m-%02d.%02H"
137 # time-stamp-time-zone: "UTC"
138 # time-stamp-end: " # UTC"
139 # End: