|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +version=0.10 |
| 4 | +program=${0##*/} |
| 5 | +progdir=${0%/*} |
| 6 | +if [ "$progdir" = "$program" ]; then progdir="."; fi |
| 7 | + |
| 8 | +# ---------------------------------------------------------------------- |
| 9 | +function usage() { |
| 10 | + cat <<EOF |
| 11 | +NAME |
| 12 | + $program - Make a release |
| 13 | +
|
| 14 | +SYNOPSIS |
| 15 | + $program [OPTIONS] VERSION |
| 16 | +
|
| 17 | +DESCRIPTION |
| 18 | +
|
| 19 | + Do the sequence of actions necesary to properly produce a release |
| 20 | + branch. This includes updating the project version and committing that |
| 21 | + to the repository, creating a release tag and a release branch if |
| 22 | + needed, and updating the project version again to indicate that any |
| 23 | + further commits are development work. Requires 1 argument: the VERSION |
| 24 | + number (e.g., 1.23). |
| 25 | +
|
| 26 | + The script uses svn info to retrieve information about the repository |
| 27 | + and path of the current directory, and inspects that to determine |
| 28 | + exactly what to do. If the current path relative to the repository root |
| 29 | + starts with 'trunk', then a new branch is created named |
| 30 | + branch/\$VERSION. If the current path starts with something else |
| 31 | + than 'trunk', it is assumed to be a working branch, and no new branch is |
| 32 | + created. In either case, a copy of the current working copy is created |
| 33 | + in tags/\$VERSION. |
| 34 | +
|
| 35 | +EOF |
| 36 | + echo -e "OPTIONS" |
| 37 | + if [ "$(uname)" = "Linux" ]; then |
| 38 | + egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | tr -s "\t|" "\t," | sed -r -e 's/\)[ \t]+([A-Z]+)=\$2[^#]*#/=\1\t/' -e 's/\)[^#]*#/\t/' |
| 39 | + else |
| 40 | + egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | sed 's/\|.*\$2[^#]*#/ /'| sed -E 's/\|.*\)[^#]*#/ /' |
| 41 | + fi |
| 42 | + cat <<EOF |
| 43 | +
|
| 44 | +AUTHOR |
| 45 | + Written by Henrik Levkowetz, <henrik@levkowetz.com> |
| 46 | +
|
| 47 | +COPYRIGHT |
| 48 | + Copyright 2007 The IETF Trust. |
| 49 | +
|
| 50 | +EOF |
| 51 | + |
| 52 | +} |
| 53 | + |
| 54 | +# ---------------------------------------------------------------------- |
| 55 | +function die() { |
| 56 | + echo -e "\n$program: error: $*" > /dev/stderr |
| 57 | + exit 1 |
| 58 | +} |
| 59 | + |
| 60 | +function note() { |
| 61 | + if [ -n "$VERBOSE" ]; then echo -e "$*"; fi |
| 62 | +} |
| 63 | + |
| 64 | +# ---------------------------------------------------------------------- |
| 65 | +function version() { |
| 66 | + echo -e "$program $version" |
| 67 | +} |
| 68 | + |
| 69 | +# ---------------------------------------------------------------------- |
| 70 | +trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR |
| 71 | + |
| 72 | + |
| 73 | +# ---------------------------------------------------------------------- |
| 74 | +# Option parsing |
| 75 | + |
| 76 | +# Options |
| 77 | +shortopts=hpvV |
| 78 | +longopts=help,repository,verbose,version |
| 79 | + |
| 80 | +# Default values |
| 81 | +MSG="" |
| 82 | +VERFILE=ietf/__init__.py |
| 83 | + |
| 84 | +if [ "$(uname)" = "Linux" ]; then |
| 85 | + args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@") |
| 86 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 87 | + eval set -- "$args" |
| 88 | + sed="sed -r" |
| 89 | +else |
| 90 | + # Darwin, BSDs |
| 91 | + args=$(getopt -o$shortopts $SV $*) |
| 92 | + if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi |
| 93 | + set -- $args |
| 94 | + sed="sed -E" |
| 95 | +fi |
| 96 | + |
| 97 | +while true ; do |
| 98 | + case "$1" in |
| 99 | + -h| --help) usage; exit;; # Show this help, then exit |
| 100 | + -m| --message) MSG=$2; shift;; # Specify a commit message |
| 101 | + -v| --verbose) VERBOSE=1;; # Be more talkative |
| 102 | + -V| --version) version; exit;; # Show program version, then exit |
| 103 | + --) shift; break;; |
| 104 | + *) die "Internal error, inconsistent option specification: '$1'";; |
| 105 | + esac |
| 106 | + shift |
| 107 | +done |
| 108 | + |
| 109 | +# ---------------------------------------------------------------------- |
| 110 | +# The program itself |
| 111 | + |
| 112 | +ARGMIN=1 |
| 113 | + |
| 114 | +if [ $# -lt $ARGMIN ]; then |
| 115 | + usage |
| 116 | + die "$# arguments found, $ARGMIN required" |
| 117 | +fi |
| 118 | + |
| 119 | +VER=$1 |
| 120 | + |
| 121 | +REPO=$(svn info | grep "^Repository Root:" | awk '{ print $3 }') |
| 122 | +RURL=$(svn info | grep "^URL:" | awk '{ print $2 }') |
| 123 | +RDIR=${RURL#$REPO} |
| 124 | +DIR=${RDIR#/} |
| 125 | +if [ -z "$DIR" ]; then |
| 126 | + die "Couldn't find anything to release here" |
| 127 | +elif [ "${DIR%%/*}" = "trunk" ]; then |
| 128 | + SRC="trunk" |
| 129 | +elif [ "${DIR%%/*}" = "branch" ]; then |
| 130 | + tmp=${DIR#*/} # get rid of 'branch/' |
| 131 | + SRC="branch/${tmp%%/*}" # keep first subdir under branch/ |
| 132 | +fi |
| 133 | + |
| 134 | +while [ "$RDIR" ]; do |
| 135 | + [ "$RDIR" = "$prev" ] && die "Internal error" |
| 136 | + cd .. |
| 137 | + pwd |
| 138 | + prev=$RDIR |
| 139 | + RDIR=${RDIR%/*} |
| 140 | +done |
| 141 | + |
| 142 | +REPO=${REPO%/} # remove trailing slash |
| 143 | +SRC=${SRC#/} # remove leading slash |
| 144 | + |
| 145 | +MAJOR=${VER%.*} |
| 146 | +MINOR=${VER#*.} |
| 147 | +NEXT=$(( $MINOR + 1 )) |
| 148 | +DEV="$(printf %d.%02d-dev $MAJOR $NEXT)" |
| 149 | + |
| 150 | +# update the version and make sure "$Rev$" is Ok |
| 151 | +sed -i -r -e "/^__version__/s/\"[.0-9]+(-dev)?\"/\"$VER\"/" \ |
| 152 | + -e "/^__rev__/s/\".*\"/\"\$Rev:\$\"/" \ |
| 153 | + $SRC/$VERFILE |
| 154 | +cat $SRC/$VERFILE |
| 155 | +svn commit $SRC/$VERFILE -m "Release version $VER. $MSG" |
| 156 | + |
| 157 | +# create a new tag. |
| 158 | +svn info $REPO/tags/$VER 2>&1 | grep -q "Not a valid URL" || die "The tag '$VER' already exists (or there was an error testing for it)." |
| 159 | +svn cp $REPO/$SRC $REPO/tags/$VER |
| 160 | + |
| 161 | +# update version and revision info to indicate that the source and branch aren't releases |
| 162 | +sed -i -r -e "/^__version__/s/\"[0-9.]*\"/\"$DEV\"/" \ |
| 163 | + -e "/^__rev__/s/\"\\\$Rev: (.*) \\\$\"/\"\$Rev:\$ (dev) Latest release: Rev. \1 \"/" \ |
| 164 | + $SRC/$VERFILE |
| 165 | +cat $SRC/$VERFILE |
| 166 | +svn commit $VERFILE -m "Development branch $DEV" |
| 167 | + |
| 168 | +# if SRC is 'trunk', then also create a new branch |
| 169 | +[ $SRC = "trunk" ] && svn info $REPO/branch/$VER 2>&1 | grep -q "Not a valid URL" && svn cp $REPO/$SRC $REPO/branch/$VER |
| 170 | + |
0 commit comments