From d831d6e5154989bd05594597e000bc9cbc6c7743 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 30 Sep 2016 11:52:35 +0200 Subject: [PATCH] Add a release script to generate the announce email Copied from Xorg/util/modular, the license should not be an issue here. Signed-off-by: Benjamin Tissoires --- release.sh | 606 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 606 insertions(+) create mode 100755 release.sh diff --git a/release.sh b/release.sh new file mode 100755 index 00000000..fc97f506 --- /dev/null +++ b/release.sh @@ -0,0 +1,606 @@ +#!/bin/bash +# +# Generate the announce template +# +# Completely copy/paste of Xorg/util/modular/release.sh: +# +# Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +export LC_ALL=C + +#------------------------------------------------------------------------------ +# Function: check_local_changes +#------------------------------------------------------------------------------ +# +check_local_changes() { + git diff --quiet HEAD > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "" + echo "Uncommitted changes found. Did you forget to commit? Aborting." + echo "" + echo "You can perform a 'git stash' to save your local changes and" + echo "a 'git stash apply' to recover them after the tarball release." + echo "Make sure to rebuild and run 'make distcheck' again." + echo "" + echo "Alternatively, you can clone the module in another directory" + echo "and run ./configure. No need to build if testing was finished." + echo "" + return 1 + fi + return 0 +} + +#------------------------------------------------------------------------------ +# Function: check_option_args +#------------------------------------------------------------------------------ +# +# perform sanity checks on cmdline args which require arguments +# arguments: +# $1 - the option being examined +# $2 - the argument to the option +# returns: +# if it returns, everything is good +# otherwise it exit's +check_option_args() { + option=$1 + arg=$2 + + # check for an argument + if [ x"$arg" = x ]; then + echo "" + echo "Error: the '$option' option is missing its required argument." + echo "" + usage + exit 1 + fi + + # does the argument look like an option? + echo $arg | $GREP "^-" > /dev/null + if [ $? -eq 0 ]; then + echo "" + echo "Error: the argument '$arg' of option '$option' looks like an option itself." + echo "" + usage + exit 1 + fi +} + +#------------------------------------------------------------------------------ +# Function: check_modules_specification +#------------------------------------------------------------------------------ +# +check_modules_specification() { + +if [ x"$MODFILE" = x ]; then + if [ x"${INPUT_MODULES}" = x ]; then + echo "" + echo "Error: no modules specified (blank command line)." + usage + exit 1 + fi +fi + +} + +#------------------------------------------------------------------------------ +# Function: generate_announce +#------------------------------------------------------------------------------ +# +generate_announce() +{ + cat < /dev/null + if [ $? -ne 0 ]; then + echo "Error: \"$MAKE $MAKEFLAGS $MAKE_DIST_CMD\" failed." + cd $top_src + return 1 + fi + + # Find out the tarname from the makefile + pkg_name=`$GREP '^PACKAGE = ' Makefile | sed 's|PACKAGE = ||'` + pkg_version=`$GREP '^VERSION = ' Makefile | sed 's|VERSION = ||'` + tar_name="$pkg_name-$pkg_version" + targz=$tar_name.tar.gz + tag_name=$(echo "v$pkg_version" | sed 's|.0$||') + + # Now get the tarballs from github directly to compute their checksum + remote_targz_url=$remote_url_root/$tag_name/$targz + echo "downloading the tarbal from $remote_targz_url" + curl $remote_targz_url > $targz + + # Obtain the top commit SHA which should be the version bump + # It should not have been tagged yet (the script will do it later) + local_top_commit_sha=`git rev-list --max-count=1 HEAD` + if [ $? -ne 0 ]; then + echo "Error: unable to obtain the local top commit id." + cd $top_src + return 1 + fi + + # Check that the top commit looks like a version bump + git diff --unified=0 HEAD^ | $GREP -F $pkg_version >/dev/null 2>&1 + if [ $? -ne 0 ]; then + # Wayland repos use m4_define([wayland_major_version], [0]) + git diff --unified=0 HEAD^ | $GREP -E "(major|minor|micro)_version" >/dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "Error: the local top commit does not look like a version bump." + echo " the diff does not contain the string \"$pkg_version\"." + local_top_commit_descr=`git log --oneline --max-count=1 $local_top_commit_sha` + echo " the local top commit is: \"$local_top_commit_descr\"" + cd $top_src + return 1 + fi + fi + + # Check that the top commit has been pushed to remote + remote_top_commit_sha=`git rev-list --max-count=1 $remote_name/$remote_branch` + if [ $? -ne 0 ]; then + echo "Error: unable to obtain top commit from the remote repository." + cd $top_src + return 1 + fi + if [ x"$remote_top_commit_sha" != x"$local_top_commit_sha" ]; then + echo "Error: the local top commit has not been pushed to the remote." + local_top_commit_descr=`git log --oneline --max-count=1 $local_top_commit_sha` + echo " the local top commit is: \"$local_top_commit_descr\"" + cd $top_src + return 1 + fi + + # If a tag exists with the the tar name, ensure it is tagging the top commit + # It may happen if the version set in configure.ac has been previously released + tagged_commit_sha=`git rev-list --max-count=1 $tag_name 2>/dev/null` + if [ $? -eq 0 ]; then + # Check if the tag is pointing to the top commit + if [ x"$tagged_commit_sha" != x"$remote_top_commit_sha" ]; then + echo "Error: the \"$tag_name\" already exists." + echo " this tag is not tagging the top commit." + remote_top_commit_descr=`git log --oneline --max-count=1 $remote_top_commit_sha` + echo " the top commit is: \"$remote_top_commit_descr\"" + local_tag_commit_descr=`git log --oneline --max-count=1 $tagged_commit_sha` + echo " tag \"$tag_name\" is tagging some other commit: \"$local_tag_commit_descr\"" + cd $top_src + return 1 + else + echo "Info: module already tagged with \"$tag_name\"." + fi + else + # Tag the top commit with the tar name + if [ x"$DRY_RUN" = x ]; then + git tag -s -m $tag_name $tag_name + if [ $? -ne 0 ]; then + echo "Error: unable to tag module with \"$tag_name\"." + cd $top_src + return 1 + else + echo "Info: module tagged with \"$tag_name\"." + fi + else + echo "Info: skipping the commit tagging in dry-run mode." + fi + fi + + # Mailing lists where to post the all [Announce] e-mails + list_to="input-tools@lists.freedesktop.org" + + # Pushing the top commit tag to the remote repository + if [ x$DRY_RUN = x ]; then + echo "Info: pushing tag \"$tag_name\" to remote \"$remote_name\":" + git push $remote_name $tag_name + if [ $? -ne 0 ]; then + echo "Error: unable to push tag \"$tag_name\" to the remote repository." + echo " it is recommended you fix this manually and not run the script again" + cd $top_src + return 1 + fi + else + echo "Info: skipped pushing tag \"$tag_name\" to the remote repository in dry-run mode." + fi + + # --------- Generate the announce e-mail ------------------ + # Failing to generate the announce is not considered a fatal error + + # Git-describe returns only "the most recent tag", it may not be the expected one + # However, we only use it for the commit history which will be the same anyway. + tag_previous=`git describe --abbrev=0 HEAD^ 2>/dev/null` + # Git fails with rc=128 if no tags can be found prior to HEAD^ + if [ $? -ne 0 ]; then + if [ $? -ne 0 ]; then + echo "Warning: unable to find a previous tag." + echo " perhaps a first release on this branch." + echo " Please check the commit history in the announce." + fi + fi + if [ x"$tag_previous" != x ]; then + # The top commit may not have been tagged in dry-run mode. Use commit. + tag_range=$tag_previous..$local_top_commit_sha + else + tag_range=$tag_name + fi + generate_announce > "$tar_name.announce" + echo "Info: [ANNOUNCE] template generated in \"$tar_name.announce\" file." + echo " Please pgp sign and send it." + + # --------- Successful completion -------------------------- + cd $top_src + return 0 + +} + +#------------------------------------------------------------------------------ +# Function: usage +#------------------------------------------------------------------------------ +# Displays the script usage and exits successfully +# +usage() { + basename="`expr "//$0" : '.*/\([^/]*\)'`" + cat <