Files
releases/tools/functions
Jeremy Stanley 2f7c26545c Comply with Policy for AI Generated Content
While probably not meeting most people's definition of artificial
intelligence these scripts do create patches. The OpenInfra Policy
for AI Generated Content recommends to:

> Add a "Generated-By:" label to the commit message, and explain in
> comments or the commit message any prompts or background context
> the reviewers might need to fully understand the change and how
> much of the change was generated by the tool.

Even though it also has a carve-out for these sorts of scripts:

> The exception to the rule is that we do allow submissions from
> well documented automated processes, such as release tooling or
> for internationalization updates.

https://openinfra.org/legal/ai-policy

Nevertheless, documenting within the commit message the location of
the script which was used to generate that contribution is helpful
for a number of obvious reasons. Let's do it anyway, even though
it's not technically required.

Change-Id: Id798bba638543cf8e9573c10e85495e7cc436237
2025-05-23 15:33:37 +00:00

145 lines
3.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 title {
echo
if [ -t 1 ]; then
echo "$(tput bold)$(tput setaf 1)[ $1 ]$(tput sgr0)"
else
echo "[ $1 ]"
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 ${ref} >/dev/null 2>&1; then
echo ""
else
git describe --abbrev=0 ${ref}
fi
}
function update_gitreview {
typeset branch="$1"
title "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 -s -m "Update .gitreview for $branch" \
--trailer="Generated-By:openstack/releases:tools/functions"
git show
local shortbranch=$(basename $branch)
git review -t "create-${shortbranch}"
}
function update_upper_constraints {
typeset branch="$1"
typeset uc_server='git.openstack.org'
typeset uc_path='cgit/openstack/requirements/plain/upper-constraints.txt'
typeset uc_url="https://${uc_server}/${uc_path}?h=${branch}"
title "Updating tox.ini for upper-constraints"
git checkout $branch
sed -i~ -e "s,-c.*{\(env:UPPER_CONSTRAINTS_FILE\)[^ ]*},-c{\1:$uc_url}," tox.ini
if ! git diff --exit-code >/dev/null 2>&1 ; then
git add tox.ini
git commit -s -m "Update UPPER_CONSTRAINTS_FILE for $branch" \
--trailer="Generated-By:openstack/releases:tools/functions"
git show
local shortbranch=$(basename $branch)
git review -t "create-${shortbranch}"
fi
}
_functions_bindir=$(realpath $(dirname $0))
function clone_repo {
typeset repo="$1"
typeset branch="$2"
if [ -z "$branch" ]; then
branch="master"
fi
output=$($_functions_bindir/clone_repo.sh --branch "$branch" $repo 2>&1)
_retval=$?
if [ $_retval -ne 0 ] ; then
echo "$output"
fi
return $_retval
}
function series_to_branch {
typeset series="$1"
typeset default=$(python -c 'from openstack_releases import defaults; print(defaults.RELEASE)')
typeset branch_name=$(python -c "from openstack_releases import gitutils; print(gitutils.get_stable_branch_id(\"$series\"))")
if [ "$series" = "$default" ]; then
echo "master"
else
echo "stable/$branch_name"
fi
}
function enable_tox_venv {
# Set up and activate the virtualenv that contains the
# edit-deliverable command.
if [ ! -d .tox/venv ]; then
tox -e venv --notest
fi
source .tox/venv/bin/activate
}