<commit_before>#!/bin/sh

# Automatable release steps.  All are optional but default to enabled.
#
# 1. Build source packages.
# 2. Build Windows packages.
# 3. Generate announce email from NEWS file.
# 4. Build HTML and PDF documentation and upload to web site.
# 5. Create new release directory and upload packages to directory.
#
# After a release:
# * Need to update sourceforge for recommended package to give to each 
#   OS.
# * send announcement email using Mutt or similar (mutt -H sox-RELEASE.email).
# * Update front page of web site to point to latest files and give
#   latest news.
#
# TODO: Can't be used for pre-releases right now.
# TODO: Make sure releases are tagged in cvs/git and no files remain
# uncommitted to make sure release is reproducable.

build_files=yes
update_web=yes
release_files=yes

# configure must have been ran to get release #.
[ ! -x configure ] && autoreconf -i 
[ ! -f Makefile ] && ./configure

release_num=`grep Version: sox.pc | cut -d ' ' -f 2`

osx_zip="sox-${release_num}-macosx.zip"
win_zip="sox-${release_num}-win32.zip"
win_exe="sox-${release_num}-win32.exe"
src_gz="sox-${release_num}.tar.gz"
src_bz2="sox-${release_num}.tar.bz2"
release_list="$src_gz $src_bz2 $win_exe $win_zip $osx_zip"

email_list="<EMAIL>,<EMAIL>"
email_file="sox-${release_num}.email"

username="${USER},sox"
hostname="shell.sourceforge.net"
release_path="/home/frs/project/s/so/sox/sox"
release_force="no"
web_path="/home/project-web/sox/htdocs"

build()
{
    echo "Creating source packages..."
    ! make -s distcheck && echo "distcheck failed" && exit 1
    ! make -s dist-bzip2 && echo "dist-bzip2 failed" && exit 1

    echo "Creating Windows packages..."
    make -s distclean
    rm -f $win_zip
    rm -f $win_exe
    ./mingwbuild 

    if [ $update_web = "yes" ]; then
	echo "Creating HTML documentation for web site..."
	! make -s html && echo "html failed" && exit 1

	echo "Creating PDF documentation for web site..."
	! make -s pdf && echo "pdf failed" && exit 1
    fi
}

create_email()
{
    cat<<EMAIL_HEADER
Subject: [ANNOUNCE] SoX ${release_num} Released
To: ${email_list}

EMAIL_HEADER

cat NEWS
}

case $release_num in
    *cvs|*git)
	echo "Aborting.  Should not release untracked version number."
	exit 1
	;;
    *rc*)
	echo "TODO: Upload path for RC's is different.  Aborting."
	exit 1;
	;;
esac

if [ ! -f $osx_zip ]; then
    echo "$osx_zip files not found.  Place those in base directory and try again."
    exit 1
fi


if [ $build_files = "yes" ]; then
    build
fi

if [ ! -f $src_gz -o ! -f $src_bz2 ]; then
    echo "$src_gz or $src_bz2 not found.  Rebuild and try again"
    exit 1
fi

if [ ! -f $win_zip -o ! -f $win_exe ]; then
    echo "$win_zip or $win_exe not found.  Rebuild and try again"
    exit 1
fi

create_email > $email_file

if [ $update_web = "yes" -o $release_files = "yes" ]; then
    echo "Creating shell on sourceforge for $username"
    ssh ${username}@${hostname}  create
    sleep 30
fi

if [ $update_web = "yes" ]; then
    echo "Updating web pages..."
    # Delete only PNG filenames which have random PID #'s in them.
    ssh ${username}@${hostname} rm -rf ${web_path}/soxpng
    scp -pr *.pdf *.html soxpng ${username}@${hostname}:${web_path}
    scp -p Docs.Features ${username}@${hostname}:${web_path/wiki.d}
fi

if [ $release_files = "yes" ]; then
    echo "Checking for an existing release..."
    if ssh ${username}@${hostname} ls ${release_path}/${release_num}/$src_gz >/dev/null 2>&1; then
	if [ "$release_force" != "yes" ]; then
	    echo "error: file already exists!"
	    exit 1
	fi
    fi
    ssh ${username}@${hostname} mkdir -p ${release_path}/${release_num}
    scp -p $release_list ${username}@${hostname}:${release_path}/${release_num}
    scp -p NEWS ${username}@${hostname}:${release_path}/${release_num}/README
fi<commit_msg>Improvements to release.sh script.<commit_after>#!/bin/sh
#
# Before a release:
# * Update configure.ac to match release #. If this is a release candidate,
#   add "rcN" to end of version.
# * Tag files to release using following form: git tag sox-14.4.0rc1
#
# Automatable release steps.   Most are optional but default to enabled.
#
# 1. Verify master git repo matches local git repo.
# 2. Build source packages.
# 3. Build Windows packages.
# 4. Generate announce email from NEWS file.
# 5. Build HTML and PDF documentation and upload to web site.
# 6. Create new release directory and upload packages to directory.
#
# After a release:
# * Need to update sourceforge for recommended package to give to each
#   OS.
# * send announcement email using Mutt or similar (mutt -H sox-RELEASE.email).
# * Update front page of web site to point to latest files and give
#   latest news.
# * Modify configure.ac, increment version # and put "git" at end of #.
#

usage()
{
    cat <<HELP
Usage: `basename $0` [options] <tag_previous> <tag_current>

<tag_previous> can be special value "initial" when ran for first
time.

Options:
  --force       force overwritting an existing release
  --help        this help message
  --ignore-local-changes        don't abort on uncommitted local changes
  --no-build	Skip building executable packages
  --no-release	Skip releasing files.
  --no-short-log Put NEWS content into email instead of autogenerate.
  --remote      git remote where the change should be pushed (default "origin")
  --user <name> username on $hostname
HELP
}

build_files=yes
update_web=yes
release_files=yes
ignore_changes=no
short_log=yes
user=$USER
remote=origin
module="sox"
webpath="sourceforge.net/projects/sox/files"
rcpath=""
email_list="<EMAIL>,<EMAIL>"
hostname="shell.sourceforge.net"
release_path="/home/frs/project/s/so/sox"
release_force="no"
web_path="/home/project-web/sox/htdocs"


while [ $# != 0 ]; do
    case "$1" in
    --force)
        force="yes"
        shift
        ;;
    --help)
        usage
        exit 0
        ;;
    --ignore-local-changes)
        ignore_changes=yes
        shift
        ;;
    --no-build)
	build_files=no
	shift
	;;
    --no-release)
	release_files=no
	shift
	;;
    --no-short-log)
	short_log=no
	shift
	;;
    --remote)
        shift
        remote=$1
        shift
        ;;
    --user)
	shift
	user=$1
	shift
	;;
    --*)
        echo "error: unknown option"
        usage
        exit 1
        ;;
    *)
        tag_previous="$1"
        tag_current="$2"
        shift 2
        if [ $# != 0 ]; then
            echo "error: unknown parameter"
            usage
            exit 1
        fi
        ;;
    esac
done

# configure must have been ran to get release #.
[ ! -x configure ] && autoreconf -i
[ ! -f Makefile ] && ./configure

# Check if the object has been pushed. Do do so
# 1. Check if the current branch has the object. If not, abort.
# 2. Check if the object is on $remote/branchname. If not, abort.
local_sha=`git rev-list -1 $tag_current`
current_branch=`git branch | grep "\*" | sed -e "s/\* //"`
set +e
git rev-list $current_branch | grep $local_sha > /dev/null
if [ $? -eq 1 ]; then
    echo "Cannot find tag '$tag_current' on current branch. Aborting."
    echo "Switch to the correct branch and re-run the script."
    exit 1
fi

revs=`git rev-list $remote/$current_branch..$current_branch | wc -l`
if [ $revs -ne 0 ]; then
    git rev-list $remote/$current_branch..$current_branch | grep $local_sha > /dev/null

    if [ $? -ne 1 ]; then
        echo "$remote/$current_branch doesn't have object $local_sha"
        echo "for tag '$tag_current'. Did you push branch first? Aborting."
        exit 1
    fi
fi
set -e

module="${tag_current%-*}"
if [ "x$module" = "x$tag_current" ]; then
    # release-number-only tag.
    pwd=`pwd`
    module=`basename $pwd`
    release_num="$tag_current"
else
    # module-and-release-number style tag
    release_num="${tag_current##*-}"
fi

detected_module=`grep 'PACKAGE = ' Makefile | sed 's|PACKAGE = ||'`
if [ -f $detected_module-$release_num.tar.bz2 ]; then
    module=$detected_module
fi

osx_zip="$module-${release_num}-macosx.zip"
win_zip="$module-${release_num}-win32.zip"
win_exe="$module-${release_num}-win32.exe"
src_gz="$module-${release_num}.tar.gz"
src_bz2="$module-${release_num}.tar.bz2"
release_list="$src_gz $src_bz2 $win_exe $win_zip $osx_zip"

email_file="${module}-${release_num}.email"

build()
{
    echo "Creating source packages..."
    ! make -s distcheck && echo "distcheck failed" && exit 1
    ! make -s dist-bzip2 && echo "dist-bzip2 failed" && exit 1

    echo "Creating Windows packages..."
    make -s distclean
    rm -f $win_zip
    rm -f $win_exe
    ./mingwbuild

    if [ $update_web = "yes" ]; then
	echo "Creating HTML documentation for web site..."
	! make -s html && echo "html failed" && exit 1

	echo "Creating PDF documentation for web site..."
	! make -s pdf && echo "pdf failed" && exit 1
    fi
}

MD5SUM=`which md5sum || which gmd5sum`
SHA1SUM=`which sha1sum || which gsha1sum`

create_email()
{
    cat<<EMAIL_HEADER
Subject: [ANNOUNCE] SoX ${release_num} Released
To: ${email_list}

EMAIL_HEADER

    if [ $short_log = "yes" ]; then
	case "$tag_previous" in
	    initial)
		range="$tag_current"
		;;
	    *)
		range="$tag_previous".."$tag_current"
		;;
	esac
	echo "git tag: $tag_current"
	echo
	git log --no-merges "$range" | git shortlog
    else
	cat NEWS
    fi

    cat<<EMAIL_FOOTER

http://$webpath/${rcpath}${module}/$osx_zip/download
MD5:  `$MD5SUM $osx_zip`
SHA1: `$SHA1SUM $osx_zip`

http://$webpath/${rcpath}${module}/$win_exe/download
MD5:  `$MD5SUM $win_exe`
SHA1: `$SHA1SUM $win_exe`

http://$webpath/${rcpath}${module}/$win_zip/download
MD5:  `$MD5SUM $win_zip`
SHA1: `$SHA1SUM $win_zip`

http://$webpath/${rcpath}${module}/$src_bz2/download
MD5:  `$MD5SUM $src_bz2`
SHA1: `$SHA1SUM $src_bz2`

http://$webpath/${rcpath}${module}/$src_gz/download
MD5:  `$MD5SUM $src_gz`
SHA1: `$SHA1SUM $src_gz`

EMAIL_FOOTER
}

case $release_num in
    *git)
	echo "Aborting.  Should not release untracked version number."
	exit 1
	;;
    *rc?|*rc??)
	echo "Release candidate detected. Disabling web update."
	update_web=no
	rcpath="release_candidates/"
	;;
esac

if [ ! -f $osx_zip ]; then
    echo "$osx_zip files not found.  Place those in base directory and try again."
    exit 1
fi

if [ $build_files = "yes" ]; then
    build
    echo
fi

if [ ! -f $src_gz -o ! -f $src_bz2 ]; then
    echo "$src_gz or $src_bz2 not found.  Rebuild and try again"
    exit 1
fi

if [ ! -f $win_zip -o ! -f $win_exe ]; then
    echo "$win_zip or $win_exe not found.  Rebuild and try again"
    exit 1
fi

# Check for uncommitted/queued changes.
if [ "$ignore_changes" != "yes" ]; then
    set +e
    git diff --exit-code > /dev/null 2>&1
    if [ $? -ne 0 ]; then
	echo "Uncommitted changes found. Did you forget to commit? Aborting."
	echo "Use --ignore-local-changes to skip this check."
	exit 1
    fi
    set -e
fi

create_email > $email_file

username="${user},sox"

if [ $update_web = "yes" -o $release_files = "yes" ]; then
    echo "Creating shell on sourceforge for $username"
    ssh ${username}@${hostname} create
fi

if [ $update_web = "yes" ]; then
    echo "Updating web pages..."
    # Delete only PNG filenames which have random PID #'s in them.
    ssh ${username}@${hostname} rm -rf ${web_path}/soxpng
    scp -pr *.pdf *.html soxpng ${username}@${hostname}:${web_path}
    scp -p Docs.Features ${username}@${hostname}:${web_path/wiki.d}
fi

if [ $release_files = "yes" ]; then
    echo "Checking for an existing release..."
    if ssh ${username}@${hostname} ls ${release_path}/${rcpath}${module}/${release_num}/$src_gz >/dev/null 2>&1; then
	if [ "$release_force" != "yes" ]; then
	    echo "error: file already exists!"
	    exit 1
	fi
    fi
    ssh ${username}@${hostname} mkdir -p ${release_path}/${rcpath}${module}/${release_num}
    scp -p $release_list ${username}@${hostname}:${release_path}/${rcpath}${module}/${release_num}
    scp -p NEWS ${username}@${hostname}:${release_path}/${rcpath}${module}/${release_num}/README
fi
{'fraction_non_alphanumeric': 0.14044191496484768, 'fraction_numerical': 0.00987612989621694, 'mean_word_length': 3.2372340425531916, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5056422', 'n_tokens_mistral': 4332, 'n_tokens_neox': 4158, 'n_words': 1276}