Blame build-aux/do-release-commit-and-tag

Packit 709fb3
#!/bin/sh
Packit 709fb3
# In a git/autoconf/automake-enabled project with a NEWS file and a version-
Packit 709fb3
# controlled .prev-version file, automate the procedure by which we record
Packit 709fb3
# the date, release-type and version string in the NEWS file.  That commit
Packit 709fb3
# will serve to identify the release, so apply a signed tag to it as well.
Packit 709fb3
VERSION=2016-12-31.14 # UTC
Packit 709fb3
Packit 709fb3
# Note: this is a bash script (could be zsh or dash)
Packit 709fb3
Packit 709fb3
# Copyright (C) 2009-2017 Free Software Foundation, Inc.
Packit 709fb3
Packit 709fb3
# This program is free software: you can redistribute it and/or modify
Packit 709fb3
# it under the terms of the GNU General Public License as published by
Packit 709fb3
# the Free Software Foundation, either version 3 of the License, or
Packit 709fb3
# (at your option) any later version.
Packit 709fb3
Packit 709fb3
# This program is distributed in the hope that it will be useful,
Packit 709fb3
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 709fb3
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 709fb3
# GNU General Public License for more details.
Packit 709fb3
Packit 709fb3
# You should have received a copy of the GNU General Public License
Packit 709fb3
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 709fb3
Packit 709fb3
# Written by Jim Meyering
Packit 709fb3
Packit 709fb3
ME=$(basename "$0")
Packit 709fb3
warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
Packit 709fb3
die() { warn "$*"; exit 1; }
Packit 709fb3
Packit 709fb3
help()
Packit 709fb3
{
Packit 709fb3
  cat <
Packit 709fb3
Usage: $ME [OPTION...] VERSION RELEASE_TYPE
Packit 709fb3
Packit 709fb3
Run this script from top_srcdir to perform the final pre-release NEWS
Packit 709fb3
update in which the date, release-type and version string are
Packit 709fb3
recorded.  Commit that result with a log entry marking the release,
Packit 709fb3
and apply a signed tag.  Run it from your project's top-level
Packit 709fb3
directory.
Packit 709fb3
Packit 709fb3
Requirements:
Packit 709fb3
- you use git for version-control
Packit 709fb3
- a version-controlled .prev-version file
Packit 709fb3
- a NEWS file, with line 3 identical to this:
Packit 709fb3
$noteworthy_stub
Packit 709fb3
Packit 709fb3
Options:
Packit 709fb3
  --branch=BRANCH     set release branch (default: $branch)
Packit 709fb3
  -C, --builddir=DIR  location of (configured) Makefile (default: $builddir)
Packit 709fb3
  --help              print this help, then exit
Packit 709fb3
  --version           print version number, then exit
Packit 709fb3
Packit 709fb3
EXAMPLE:
Packit 709fb3
To update NEWS and tag the beta 8.1 release of coreutils, I would run this:
Packit 709fb3
Packit 709fb3
  $ME 8.1 beta
Packit 709fb3
Packit 709fb3
Report bugs and patches to <bug-gnulib@gnu.org>.
Packit 709fb3
EOF
Packit 709fb3
  exit
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
version()
Packit 709fb3
{
Packit 709fb3
  year=$(echo "$VERSION" | sed 's/[^0-9].*//')
Packit 709fb3
  cat <
Packit 709fb3
$ME $VERSION
Packit 709fb3
Copyright (C) $year Free Software Foundation, Inc,
Packit 709fb3
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
Packit 709fb3
This is free software: you are free to change and redistribute it.
Packit 709fb3
There is NO WARRANTY, to the extent permitted by law.
Packit 709fb3
EOF
Packit 709fb3
  exit
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
## ------ ##
Packit 709fb3
## Main.  ##
Packit 709fb3
## ------ ##
Packit 709fb3
Packit 709fb3
# Constants.
Packit 709fb3
noteworthy='* Noteworthy changes in release'
Packit 709fb3
noteworthy_stub="$noteworthy ?.? (????-??-??) [?]"
Packit 709fb3
Packit 709fb3
# Variables.
Packit 709fb3
branch=$(git branch | sed -ne '/^\* /{s///;p;q;}')
Packit 709fb3
builddir=.
Packit 709fb3
Packit 709fb3
while test $# != 0
Packit 709fb3
do
Packit 709fb3
  # Handle --option=value by splitting apart and putting back on argv.
Packit 709fb3
  case $1 in
Packit 709fb3
    --*=*)
Packit 709fb3
      opt=$(echo "$1" | sed -e 's/=.*//')
Packit 709fb3
      val=$(echo "$1" | sed -e 's/[^=]*=//')
Packit 709fb3
      shift
Packit 709fb3
      set dummy "$opt" "$val" "$@"; shift
Packit 709fb3
      ;;
Packit 709fb3
  esac
Packit 709fb3
Packit 709fb3
  case $1 in
Packit 709fb3
    --help|--version) ${1#--};;
Packit 709fb3
    --branch) shift; branch=$1; shift ;;
Packit 709fb3
    -C|--builddir) shift; builddir=$1; shift ;;
Packit 709fb3
    --*) die "unrecognized option: $1";;
Packit 709fb3
    *) break;;
Packit 709fb3
  esac
Packit 709fb3
done
Packit 709fb3
Packit 709fb3
test $# = 2 \
Packit 709fb3
  || die "Usage: $ME [OPTION...] VERSION TYPE"
Packit 709fb3
Packit 709fb3
ver=$1
Packit 709fb3
type=$2
Packit 709fb3
Packit 709fb3
Packit 709fb3
## ---------------------- ##
Packit 709fb3
## First, sanity checks.  ##
Packit 709fb3
## ---------------------- ##
Packit 709fb3
Packit 709fb3
# Verify that $ver looks like a version number, and...
Packit 709fb3
echo "$ver"|grep -E '^[0-9][0-9.]*[0-9]$' > /dev/null \
Packit 709fb3
  || die "invalid version: $ver"
Packit 709fb3
prev_ver=$(cat .prev-version) \
Packit 709fb3
  || die 'failed to determine previous version number from .prev-version'
Packit 709fb3
Packit 709fb3
# Verify that $ver is sensible (> .prev-version).
Packit 709fb3
case $(printf "$prev_ver\n$ver\n"|sort -V -u|tr '\n' ':') in
Packit 709fb3
  "$prev_ver:$ver:") ;;
Packit 709fb3
  *) die "invalid version: $ver (<= $prev_ver)";;
Packit 709fb3
esac
Packit 709fb3
Packit 709fb3
case $type in
Packit 709fb3
  alpha|beta|stable) ;;
Packit 709fb3
  *) die "invalid release type: $type";;
Packit 709fb3
esac
Packit 709fb3
Packit 709fb3
# No local modifications allowed.
Packit 709fb3
case $(git diff-index --name-only HEAD) in
Packit 709fb3
  '') ;;
Packit 709fb3
  *) die 'this tree is dirty; commit your changes first';;
Packit 709fb3
esac
Packit 709fb3
Packit 709fb3
# Ensure the current branch name is correct:
Packit 709fb3
curr_br=$(git rev-parse --symbolic-full-name HEAD)
Packit 709fb3
test "$curr_br" = "refs/heads/$branch" || die not on branch $branch
Packit 709fb3
Packit 709fb3
# Extract package name from Makefile.
Packit 709fb3
Makefile=$builddir/Makefile
Packit 709fb3
pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' "$Makefile") \
Packit 709fb3
  || die "failed to determine package name from $Makefile"
Packit 709fb3
Packit 709fb3
# Check that line 3 of NEWS is the stub line about to be replaced.
Packit 709fb3
test "$(sed -n 3p NEWS)" = "$noteworthy_stub" \
Packit 709fb3
  || die "line 3 of NEWS must be exactly '$noteworthy_stub'"
Packit 709fb3
Packit 709fb3
## --------------- ##
Packit 709fb3
## Then, changes.  ##
Packit 709fb3
## --------------- ##
Packit 709fb3
Packit 709fb3
# Update NEWS to have today's date, plus desired version number and $type.
Packit 709fb3
perl -MPOSIX -ni -e 'my $today = strftime "%F", localtime time;' \
Packit 709fb3
 -e 'my ($type, $ver) = qw('"$type $ver"');' \
Packit 709fb3
 -e 'my $pfx = "'"$noteworthy"'";' \
Packit 709fb3
 -e 'print $.==3 ? "$pfx $ver ($today) [$type]\n" : $_' \
Packit 709fb3
     NEWS || die 'failed to update NEWS'
Packit 709fb3
Packit 709fb3
printf "version $ver\n\n* NEWS: Record release date.\n" \
Packit 709fb3
    | git commit -F -  -a || die 'git commit failed'
Packit 709fb3
git tag -s -m "$pkg $ver" v$ver HEAD || die 'git tag failed'
Packit 709fb3
Packit 709fb3
# Local variables:
Packit 709fb3
# indent-tabs-mode: nil
Packit 709fb3
# eval: (add-hook 'write-file-hooks 'time-stamp)
Packit 709fb3
# time-stamp-start: "VERSION="
Packit 709fb3
# time-stamp-format: "%:y-%02m-%02d.%02H"
Packit 709fb3
# time-stamp-time-zone: "UTC0"
Packit 709fb3
# time-stamp-end: " # UTC"
Packit 709fb3
# End: