Doug Hellmann 881f3cc666 update tag-release git command to fall back to master
The release tagging script relied on the zuul-cloner behavior of falling
back to master if the requested branch did not exist. Add logic to the
shell command replacement to do the same thing, with a warning.

I tested this locally on the Oslo releases today, and it worked. Before
the change release.sh failed because it could not check out the
stable/newton branch of openstack/requirements to submit the patch to
update the constraints list.

Change-Id: Ib29a68edbb5bfea64625128da35ddad61098dd9c
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2016-08-02 14:12:16 -04:00

108 lines
2.7 KiB
Bash

#!/bin/bash
#
# Shared functions for shell scripts
#
# Make sure custom grep options don't get in the way
unset GREP_OPTIONS
function lp_project_to_repo {
typeset proj="$1"
if [[ $proj == python-*client* ]]; then
echo $proj
elif [[ $proj == glance-store ]]; then
echo glance_store
elif [[ $proj == django-openstack-auth ]]; then
echo django_openstack_auth
else
# Some of the repository names don't match the launchpad names, e.g.
# python-stevedore and python-cliff.
echo $proj | sed -e 's|^python-||'
fi
}
function _cleanup_tmp {
rm -rf $MYTMPDIR
return 0
}
function setup_temp_space {
MYTMPDIR=`mktemp -d _tmp-${1}-XXX`
mkdir -p "$MYTMPDIR"
trap _cleanup_tmp EXIT
cd "$MYTMPDIR"
# NOTE(dhellmann): On some platforms mktemp returns a short name
# instead of a full path, so expand the full path by looking at
# where we ended up after the cd operation.
MYTMPDIR="$(pwd)"
}
function get_last_tag {
# Print the most recent tag for a ref. If no ref is specified, the
# currently checked out branch is examined.
local ref="$1"
if ! git describe --abbrev=0 --first-parent ${ref} >/dev/null 2>&1; then
echo ""
else
git describe --abbrev=0 --first-parent ${ref}
fi
}
function update_gitreview {
typeset branch="$1"
echo "Updating .gitreview"
git checkout $branch
# Remove a trailing newline, if present, to ensure consistent
# formatting when we add the defaultbranch line next.
typeset grcontents="$(echo -n "$(cat .gitreview | grep -v defaultbranch)")
defaultbranch=$branch"
echo "$grcontents" > .gitreview
git add .gitreview
git commit -m "Update .gitreview for $branch"
git show
local shortbranch=$(basename $branch)
git review -t "create-${shortbranch}"
}
function clone_repo {
typeset repo="$1"
typeset branch="$2"
set -e
# Create the parent directory in case it doesn't already exist.
mkdir -p $(dirname $repo)
# Clone into openstack/foo instead of just foo.
git clone git://git.openstack.org/$repo $repo
# Configure git-review so we can propose patches to the repo if
# needed.
(cd $repo && git review -s)
# Make sure we have all of the existing tags so we can refer to
# them for building the release notes.
(cd $repo && git fetch -v --tags)
# Make sure the active branch is set correctly, if the branch
# exists.
if [ ! -z "$branch" ]; then
if git show origin/$branch; then
(cd $repo && git checkout $branch)
else
echo "Branch $branch does not exist, using master."
fi
fi
return 0
}