release-tools/functions

63 lines
1.7 KiB
Bash

#!/bin/bash
#
# Shared functions for shell scripts
#
function lp_project_to_repo {
typeset proj="$1"
if [[ $proj == python-*client* ]]; then
echo $proj
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 title {
echo
echo "$(tput bold)$(tput setaf 1)[ $1 ]$(tput sgr0)"
}
function _cleanup_tmp {
title "Cleaning up"
rm -rf $MYTMPDIR
}
function setup_temp_space {
MYTMPDIR=`mktemp -d ${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 {
# Use git log to show changes on this branch, and add --decorate
# to include the tag names. Then use grep and sed to pull the tag
# name out so that is all we pass to highest_semver.py.
#
# This assumes the local copy of the repo is on the branch from
# which we would want to release.
git log --decorate --oneline \
| egrep '^[0-9a-f]+ \((HEAD, )?tag: ' \
| sed -r 's/^.+tag: ([^ ]+)[,\)].+$/\1/g' \
| ${TOOLSDIR}/highest_semver.py
# Look at *all* tags, sorted by the date they were applied. This
# sometimes predicts the wrong value, especially when we might be
# releasing from a branch other than master.
#
# git for-each-ref --sort=taggerdate --format '%(refname)' refs/tags \
# | sed -e 's|refs/tags/||' \
# | ${TOOLSDIR}/highest_semver.py
}