345 lines
12 KiB
Bash
Executable file
345 lines
12 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
version=0.10
|
|
program=${0##*/}
|
|
progdir=${0%/*}
|
|
if [ "$progdir" = "$program" ]; then progdir="."; fi
|
|
PATH="$PATH:$progdir"
|
|
|
|
# ----------------------------------------------------------------------
|
|
function usage() {
|
|
cat <<EOF
|
|
NAME
|
|
$program - Make a release
|
|
|
|
SYNOPSIS
|
|
$program [OPTIONS] VERSION
|
|
|
|
DESCRIPTION
|
|
|
|
Do the sequence of actions necessary to properly produce a release
|
|
branch. This includes updating the project version and committing that
|
|
to the repository, creating a release tag and a release branch if
|
|
needed, and updating the project version again to indicate that any
|
|
further commits are development work. Requires 1 argument: the VERSION
|
|
number (e.g., 1.23).
|
|
|
|
The script uses svn info to retrieve information about the repository
|
|
and path of the current directory, and inspects that to determine
|
|
exactly what to do. If the current path relative to the repository root
|
|
starts with 'trunk', then a new branch is created named
|
|
branch/\$VERSION. If the current path starts with something else
|
|
than 'trunk', it is assumed to be a working branch, and no new branch is
|
|
created. In either case, a copy of the current working copy is created
|
|
in tags/\$VERSION.
|
|
|
|
EOF
|
|
echo -e "OPTIONS"
|
|
if [ "$(uname)" = "Linux" ]; then
|
|
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/'
|
|
else
|
|
egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | sed 's/\|.*\$2[^#]*#/ /'| sed -E 's/\|.*\)[^#]*#/ /'
|
|
fi
|
|
cat <<EOF
|
|
|
|
AUTHOR
|
|
Written by Henrik Levkowetz, <henrik@levkowetz.com>
|
|
|
|
COPYRIGHT
|
|
Copyright 2007 The IETF Trust.
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
# ----------------------------------------------------------------------
|
|
function die() {
|
|
echo -e "\n$program: error: $*" > /dev/stderr
|
|
exit 1
|
|
}
|
|
|
|
function say() {
|
|
if [ -n "$VERBOSE" ]; then echo -e "$*"; fi
|
|
}
|
|
|
|
function note() {
|
|
if [ -n "$VERBOSE" ]; then echo -e "\n$*"; fi
|
|
}
|
|
|
|
function check() {
|
|
[ "$(which $1)" ] || die "could not find the '$1' command. $2"
|
|
}
|
|
|
|
# ----------------------------------------------------------------------
|
|
function version() {
|
|
echo -e "$program $version"
|
|
}
|
|
|
|
# ----------------------------------------------------------------------
|
|
trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
# Option parsing
|
|
|
|
# Options
|
|
shortopts=hmnipvV
|
|
longopts=help,message,dry-run,ignore-resources,permit-migr-mix,verbose,version
|
|
|
|
# Default values
|
|
MSG=""
|
|
PROJ=ietfdb
|
|
VERFILE=ietf/__init__.py
|
|
SETTINGS=ietf/settings.py
|
|
PERMIT_MIGR_MIX=""
|
|
IGNORE_RESOURCES=""
|
|
do=""
|
|
|
|
if [ "$(uname)" = "Linux" ]; then
|
|
args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@")
|
|
if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi
|
|
eval set -- "$args"
|
|
sed="sed -r"
|
|
else
|
|
# Darwin, BSDs
|
|
args=$(getopt -o$shortopts $SV $*)
|
|
if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi
|
|
set -- $args
|
|
sed="sed -E"
|
|
fi
|
|
|
|
while true ; do
|
|
case "$1" in
|
|
-h| --help) usage; exit;; # Show this help, then exit
|
|
-m| --message) MSG=$2; shift;; # Specify a commit message
|
|
-n| --dry-run) do="echo ==>";; # Show what would be done
|
|
-i| --ignore-resources) IGNORE_RESOURCES=1;; # Don't try to update resources
|
|
-p| --permit-migr-mix) PERMIT_MIGR_MIX=1;; # Permit mixed schema and data migrations
|
|
-v| --verbose) VERBOSE=1;; # Be more talkative
|
|
-V| --version) version; exit;; # Show program version, then exit
|
|
--) shift; break;;
|
|
*) die "Internal error, inconsistent option specification: '$1'";;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# ----------------------------------------------------------------------
|
|
# Check some requirements
|
|
|
|
check bower "It is required to update web resources. Install with npm."
|
|
|
|
# ----------------------------------------------------------------------
|
|
# The program itself
|
|
|
|
ARGMIN=1
|
|
|
|
if [ $# -lt $ARGMIN ]; then
|
|
usage
|
|
die "$# arguments found, $ARGMIN required"
|
|
fi
|
|
|
|
by=$(getent passwd $(whoami) | cut -d ':' -f 5 | tr -d ',')
|
|
[ -z "$by" ] && die "Can't determine the real name of the user running this script"
|
|
|
|
VER=$1
|
|
|
|
REPO=$(svn info | grep "^Repository Root:" | awk '{ print $3 }')
|
|
RDATE=$(svn info | grep "^Last Changed Date:" | awk '{ print $4 "T" $5 $6 }')
|
|
RURL=$(svn info | grep "^URL:" | awk '{ print $2 }')
|
|
RDIR=${RURL#$REPO}
|
|
|
|
DIR=${RDIR#/}
|
|
if [ -z "$DIR" ]; then
|
|
die "Couldn't find anything to release here"
|
|
elif [ "${DIR%%/*}" = "trunk" ]; then
|
|
SRC="trunk"
|
|
elif [ "${DIR%%/*}" = "branch" ]; then
|
|
tmp=${DIR#*/} # get rid of 'branch/'
|
|
SRC="branch/${tmp%%/*}" # keep first subdir under branch/
|
|
fi
|
|
|
|
|
|
note "Releasing from $SRC"
|
|
|
|
note "Locating the root of the working copy ..."
|
|
while [ "${#DIR}" -gt "${#SRC}" ]; do
|
|
[ "$DIR" = "$prev" ] && die "Internal error"
|
|
cd ..
|
|
#note " now at $PWD"
|
|
prev=$DIR
|
|
DIR=${DIR%/*}
|
|
done
|
|
if [ "$DIR" != "$SRC" ]; then
|
|
die "Couldn't find the root of your '$SRC' working copy"
|
|
fi
|
|
say " $DIR"
|
|
|
|
REPO=${REPO%/} # remove trailing slash
|
|
SRC=${SRC#/} # remove leading slash
|
|
|
|
MAJOR=${VER%%.*}
|
|
REST=${VER#*.}
|
|
MINOR=${REST%%.*}
|
|
MAINT=${REST#*.}
|
|
VER="$(printf %d.%d.%d $MAJOR $MINOR $MAINT)"
|
|
NEXT=$(( $MAINT + 1 ))
|
|
DEV="$(printf %d.%d.%d.dev0 $MAJOR $MINOR $NEXT)"
|
|
|
|
#cd $DIR ??
|
|
|
|
note "Checking that changelog information is available ..."
|
|
changes=$( sed -n "/^$PROJ ($VER.*)/,/^ -- /p" changelog )
|
|
[ "$changes" ] || die "No changelog information for $VER found"
|
|
#note "$changes"
|
|
|
|
note "Checking for migrations not in SVN"
|
|
$do svn st | grep "^[?] .*/migrations/[0-9].*\.py$" && die "There seems to be new migrations which aren't in SVN"
|
|
|
|
if [ -z "$PERMIT_MIGR_MIX" ]; then
|
|
note "Checking that we don't have both schema and data migrations ..."
|
|
cur=$(svn info | awk '/^Revision:/ { print $2 }')
|
|
migrations=$(svn log $PWD -v -r HEAD:$((cur-100)) | sed -n -e '1,/^Set version info and settings back to development mode/p' | grep '^...A /.*/migrations/0.*.py' | cut -c6- | awk '{ print $1 }' | sed -re 's|/trunk/||')
|
|
if [ -n "$migrations" ]; then
|
|
datamigr=$(for m in "$migrations"; do egrep -sl 'migrations\.RunPython' $m; done || true)
|
|
schemamigr=$(for m in "$migrations"; do egrep -sl 'migrations\.(Add|Alter|Create|Delete|Remove|Rename)(Field|Model|UniqueTogether)' $m; done || true)
|
|
if [ -n "$datamigr" -a -n "$schemamigr" ]; then
|
|
echo -e "\n Schema migrations:"
|
|
for m in $schemamigr; do
|
|
echo " $m"
|
|
done
|
|
echo -e "\n Data migrations:"
|
|
for m in $datamigr; do
|
|
echo " $m"
|
|
done
|
|
die "\n Found both data migrations and schema migrations in this release.\n This is likely to cause delay between schema changes and deployment,\n which means the old code will run on the new schema longer than necessary."
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ -z "$IGNORE_RESOURCES" ]; then
|
|
note "Updating bower assets ..."
|
|
$do ietf/manage.py bower_install > .mkrelease-bower-install.log
|
|
$do rm .mkrelease-bower-install.log # This happens at once unless the previous command returns error
|
|
$do svn st ietf/externals/static | grep -v '^\?' || true
|
|
$do svn commit ietf/externals/static -m "Updated bower-managed static web assets"
|
|
# Get rid of bower-installed files which we don't use:
|
|
$do rm -rf ietf/externals/static/datatracker/
|
|
$do rm -rf ietf/externals/static/jquery.cookie/
|
|
$do rm -f $(svn st ietf/externals/ | grep '^\?' | awk '{print $2}')
|
|
fi
|
|
|
|
note "Collecting static files ..."
|
|
$do ietf/manage.py collectstatic --noinput --ignore=bower.json --ignore='README.*' --ignore=rev | grep -v "Found another file with the destination path"
|
|
$do svn commit static/lib/ -m "Updated static files under static/lib/"
|
|
|
|
# note "Checking that there's a recent test-crawler log"
|
|
# touch -d $RDATE .svn/.latest-commit
|
|
# TCLOG=$(ls -t ../test-crawl-*.log | head -n 1)
|
|
# [ $TCLOG -nt .svn/.latest-commit ] || die "Looked for ../test-crawl-*.log, but didn't find one newer than the latest repository commit ($RDATE)"
|
|
|
|
note "Upgrading the python library modules before checking migrations and running tests ..."
|
|
$do pip install --upgrade -r requirements.txt
|
|
$do pip check
|
|
|
|
note "Checking that all model changes have been captured in migrations ..."
|
|
$do ietf/manage.py makemigrations | tee /dev/stderr | $do grep -q "^No changes detected$" || die "Model changes without migrations found."
|
|
|
|
note "Making sure all migrations have been run ..."
|
|
$do ietf/manage.py migrate
|
|
|
|
note "Running the tests suite and writing release coverage data ..."
|
|
$do ietf/manage.py test --settings=ietf.settings_releasetest --save-version-coverage=$VER ${PERMIT_MIGR_MIX:+"--permit-mixed-migrations"}
|
|
|
|
note "Committing the release coverage data ..."
|
|
$do svn commit release-coverage.json.gz -m "Code coverage data for release $VER"
|
|
|
|
if [ -d ../coverage ]; then
|
|
cp .coverage ../coverage/$VER.coverage
|
|
rsync -a static/coverage/ ../coverage/$VER/
|
|
fi
|
|
|
|
contributors=$(echo "$changes" | gawk '/^ \* Merged in \[[0-9]+\] from [^: ]+/ {sub(":",""); print $6;}' | sort | uniq)
|
|
note "Contributors:
|
|
$contributors"
|
|
|
|
note "Setting the current time on the release notes in the changelog file ..."
|
|
$do sed -r -i -e "1,/^ -- /s/([A-Za-z-]+ <[a-z0-9.-]+@[a-z0-9.-]+> ).*$/\1$(TZ=UTC date +'%d %b %Y %H:%M:%S %z')/" changelog
|
|
say " $(grep -m1 "^ -- " changelog)"
|
|
|
|
note "Verifying that version $VER doesn't already exist ..."
|
|
$do svn info $REPO/tags/$VER 2>&1 | $do egrep -q "(Not a valid URL|URL .* non-existent)" || die "The tag '$VER' already exists (or there was an error testing for it)."
|
|
say " Ok"
|
|
|
|
note "Committing the changelog ..."
|
|
$do svn commit changelog -m "Changelog entry for $VER"
|
|
|
|
note "Verifying there's no uncommitted changes ..."
|
|
$do svn st | grep "^[AMGRD] " && die "There seems to be uncommitted changes in this working copy"
|
|
|
|
note "Updating the version info in $VERFILE and making sure'\$Rev\$' is Ok ..."
|
|
$do sed -i -r -e "/^__version__/s/\"[.0-9]+(dev[0-9]+)?\"/\"$VER\"/" \
|
|
-e "/^__rev__/s/\".*\"/\"\$Rev:\$\"/" \
|
|
$VERFILE
|
|
|
|
note "Updating the deployment settings in settings.py"
|
|
$do sed -i -r -e 's/^DEBUG *= *.*$/DEBUG = False/' \
|
|
-e "s/^SERVER_MODE *= *.*\$/SERVER_MODE = 'production'/" \
|
|
$SETTINGS
|
|
|
|
note "Committing version information for version $VER: $MSG ..."
|
|
$do svn commit $VERFILE $SETTINGS -m "Set version info to release version $VER before branching. $MSG"
|
|
|
|
note "Creating new tag 'tags/$VER' from $SRC ..."
|
|
$do svn cp $REPO/$SRC $REPO/tags/$VER -m "Creating new tag 'tags/$VER' from $SRC"
|
|
|
|
note "Updating version and revision info to indicate that the source and branch aren't releases ..."
|
|
$do sed -i -r -e "/^__version__/s/\"[0-9.]*\"/\"$DEV\"/" \
|
|
-e "/^__rev__/s/\"\\\$Rev: (.*) \\\$\"/\"\$Rev:\$ (dev) Latest release: Rev. \1 \"/" \
|
|
$VERFILE
|
|
|
|
note "Updating the deployment settings in settings.py to development mode ..."
|
|
$do sed -i -r -e 's/^DEBUG *= *.*$/DEBUG = True/' \
|
|
-e "s/^SERVER_MODE *= *.*\$/SERVER_MODE = 'development'/" \
|
|
$SETTINGS
|
|
|
|
note "Committing the updated version and deployment settings ..."
|
|
$do svn commit $VERFILE $SETTINGS -m "Set version info and settings back to development mode"
|
|
|
|
note "Creating new tag 'tags/dev/$DEV' from $SRC ..."
|
|
$do svn cp $REPO/$SRC $REPO/tags/dev/$DEV -m "Creating new tag 'tags/dev/$DEV' from $SRC"
|
|
|
|
$do svn update -q
|
|
|
|
[ -d ~/src/db/mail ] || mkdir -p ~/src/db/mail
|
|
echo "
|
|
Hi,
|
|
|
|
This is an automatic notification about a new datatracker release,
|
|
v$VER, generated when running the mkrelease script.
|
|
|
|
Release notes:
|
|
|
|
$changes
|
|
|
|
The new version is available for installation through SVN checkout, with
|
|
'svn checkout https://svn.tools.ietf.org/svn/tools/$PROJ/tags/$VER'
|
|
|
|
For development, copy the new development version instead:
|
|
'svn copy https://svn.tools.ietf.org/svn/tools/$PROJ/tags/dev/$DEV' <YOURBRANCH>
|
|
|
|
Regards,
|
|
|
|
$by
|
|
(via the mkrelease script)
|
|
" > ~/src/db/mail/release-mail-v$VER.txt
|
|
|
|
cat ~/src/db/mail/release-mail-v$VER.txt | $do mail -s "New datatracker release: v$VER" housley@vigilsec.com rjsparks@nostrum.com jay@ietf.org -c glen@amsl.com -c maddy@amsl.com -c cmorgan@amsl.com -c avezza@amsl.com -c amorris@amsl.com -c smccammon@amsl.com -c kmoreland@amsl.com $contributors
|
|
|
|
cat ~/src/db/mail/release-mail-v$VER.txt | $do mail -s "New datatracker release: v$VER" iesg@ietf.org wgchairs@ietf.org codesprints@ietf.org -b rjsparks@nostrum.com
|
|
|
|
|
|
# Removed at Henrik's suggestion
|
|
#$do toolsfeed control changelog /www/tools.ietf.org/tools/atomfeed.xml
|
|
#$do toolpush /www/tools.ietf.org/tools/atomfeed.xml
|
|
|