branching: Add ability to exclude projects from lock-down

Scripts create_branches_and_tags.sh and create_tags.sh
allow for automated manifest update, and offer lock-down
options to freeze all projects that weren't branched
or tagged on a specific SHA.

Sometimes we might not want to freeze ALL the other
projects.  Rather we need to control which are frozen
and which are not.  Freezing everything else remains
the preferred default behaviour.  Not freezing is an
exception.

This update adds options to exclude projects or remotes
from lock-down.

Closes-Bug: 1952473
Change-Id: I52d4b66ae44d06a6c05f492321fa2ae12fb3fc70
Signed-off-by: Scott Little <scott.little@windriver.com>
This commit is contained in:
Scott Little 2021-11-26 11:40:46 -05:00
parent 29e4952806
commit b2427a1ff7
3 changed files with 89 additions and 34 deletions

View File

@ -26,6 +26,9 @@ source "${CREATE_BRANCHES_AND_TAGS_SH_DIR}/../git-repo-utils.sh"
usage () {
echo "create_branches_and_tags.sh --branch=<branch> [--tag=<tag>] <options>"
echo ""
echo " Create a branch on selected projects, and optionally update the manifest"
echo " to use the the new branch."
echo ""
echo " The branch name must be provided. The tag name can also be provided."
echo " If the tag is omitted, one is automativally generate by adding the"
echo " prefix 'v' to the branch name."
@ -57,6 +60,8 @@ usage () {
echo " new branch for all select remotes and projects."
echo " [ --manifest-file=<file.xml> ]"
echo " Override the manifest file to be updated."
echo " [ --default-revision ]"
echo " Set the default revision of the manifest."
echo " [ --hard-lock-down | --lockdown ]"
echo " All unselected projects get the current HEAD's"
echo " SHA set as the revision."
@ -64,12 +69,15 @@ usage () {
echo " All unselected projects with an revision that"
echo " is unset, or 'master', get the current HEAD's sha"
echo " set as the revision."
echo " [ --default-revision ]"
echo " Set the default revision of the manifest."
echo " [ --lock-down-exclude-remotes=<remotes> ]"
echo " [ --lock-down-exclude-projects=<projects> ]"
echo " Exclude from lock-down these additional projects, and"
echo " all projects hosted by these additional remotes."
echo " Lists are comma separated."
echo ""
}
TEMP=$(getopt -o h --long remotes:,projects:,branch:,tag:,manifest,manifest-file:,lock-down,hard-lock-down,soft-lock-down,default-revision,gitreview-default,gitreview-project,gitreview-host:,gitreview-port:,safe-gerrit-host:,help -n 'create_branches_and_tags.sh' -- "$@")
TEMP=$(getopt -o h --long remotes:,projects:,branch:,tag:,manifest,manifest-file:,lock-down,hard-lock-down,soft-lock-down,default-revision,gitreview-default,gitreview-project,gitreview-host:,gitreview-port:,safe-gerrit-host:,lock-down-exclude-remotes:,lock-down-exclude-projects:,help -n 'create_branches_and_tags.sh' -- "$@")
if [ $? -ne 0 ]; then
usage
exit 1
@ -87,6 +95,8 @@ GITREVIEW_CHANGE=0
SET_DEFAULT_REVISION=0
remotes=""
projects=""
ld_exclude_remotes=""
ld_exclude_projects=""
branch=""
tag=""
manifest=""
@ -99,6 +109,8 @@ while true ; do
-h|--help) HELP=1 ; shift ;;
--remotes) remotes+=$(echo "$2 " | tr ',' ' '); shift 2;;
--projects) projects+=$(echo "$2 " | tr ',' ' '); shift 2;;
--lock-down-exclude-remotes) ld_exclude_remotes+=$(echo "$2 " | tr ',' ' '); shift 2;;
--lock-down-exclude-projects) ld_exclude_projects+=$(echo "$2 " | tr ',' ' '); shift 2;;
--branch) branch=$2; shift 2;;
--tag) tag=$2; shift 2;;
--manifest) MANIFEST=1 ; shift ;;
@ -191,7 +203,7 @@ update_gitreview () {
fi
if [ ${GITREVIEW_PROJECT} -eq 1 ]; then
remote_url=$(git_repo_remote_url)
remote_url=$(git_repo_remote_url || git_remote_url)
pull_url=${remote_url}
path=$(url_path ${pull_url})
project=${path%.git}
@ -271,7 +283,7 @@ if [ $MANIFEST -eq 1 ]; then
fi
fi
for project in $projects; do
for project in $projects $ld_exclude_projects; do
if ! repo_is_project $project; then
echo_stderr "Invalid project: $project"
echo_stderr "Valid projects are: $(repo_project_list | tr '\n' ' ')"
@ -279,7 +291,7 @@ for project in $projects; do
fi
done
for remote in $remotes; do
for remote in $remotes $ld_exclude_remotes; do
if ! repo_is_remote $remote; then
echo_stderr "Invalid remote: $remote"
echo_stderr "Valid remotes are: $(repo_remote_list | tr '\n' ' ')"
@ -292,6 +304,11 @@ if [ "$remotes" != "" ]; then
projects+="$(repo_project_list $remotes | tr '\n' ' ')"
fi
if [ "$ld_exclude_remotes" != "" ]; then
ld_exclude_projects+="$(repo_project_list $ld_exclude_remotes | tr '\n' ' ')"
fi
# If no projects or remotes specified, process ALL projects
if [ "$projects" == "" ] && [ "$remotes" == "" ]; then
projects="$(repo_project_list)"
@ -440,7 +457,7 @@ if [ $MANIFEST -eq 1 ]; then
update_gitreview ${manifest_dir} || exit 1
echo "Creating manifest ${new_manifest_name}"
manifest_set_revision "${manifest}" "${new_manifest}" "$branch" ${LOCK_DOWN} ${SET_DEFAULT_REVISION} $projects || exit 1
manifest_set_revision "${manifest}" "${new_manifest}" "$branch" "${LOCK_DOWN}" "${SET_DEFAULT_REVISION}" "${projects// /,}" "${ld_exclude_projects// /,}" || exit 1
echo "Move manifest ${new_manifest_name}, overwriting ${manifest_name}"
\cp -f "${manifest}" "${manifest}.save"

View File

@ -23,27 +23,46 @@ CREATE_TAGS_SH_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )"
source "${CREATE_TAGS_SH_DIR}/../git-repo-utils.sh"
usage () {
echo "create_tags.sh --tag=<tag> [ --remotes=<remotes> ] [ --projects=<projects> ]"
echo " [ --manifest [ --manifest-file=<manifest.xml> ] [ --manifest-prefix <prefix> ] [ --lock-down | --soft-lock-down ] [ --default-revision ]]"
echo " [ --safe-gerrit-host=<host> ]"
echo " "
echo "Create a git tag in all listed projects, and all projects"
echo "hosted by all listed remotes. Lists are comma separated."
echo "create_tags.sh --tag=<tag> <options>"
echo ""
echo "If a manifest is requested, it will recieve the name '<prefix><tag>.xml' and"
echo "it will specify the tag as the revision for all tagged projects."
echo "If lockdown is requested, all non-tagged projects get the current"
echo "HEAD's sha set as the revision."
echo "If default-revision is selected, then the manifest default revision"
echo "will be set."
echo " Create a tag on selected projects, and optionally update the manifest"
echo " to use the the new branch."
echo ""
echo "--manifest-file may be used to override the manifest file to be updated."
echo "selection options:"
echo " [ --remotes=<remotes> ] [ --projects=<projects> ]"
echo ""
echo " Create a branch and a tag in all listed projects, and all"
echo " projects hosted by all listed remotes. Lists are comma separated."
echo ""
echo "manifest options:"
echo " [ --manifest ]"
echo " Modify the current repo manifest to specify the"
echo " new branch for all select remotes and projects."
echo " [ --manifest-file=<file.xml> ]"
echo " Override the manifest file to be updated."
echo " [ --default-revision ]"
echo " Set the default revision of the manifest."
echo " [ --hard-lock-down | --lockdown ]"
echo " All unselected projects get the current HEAD's"
echo " SHA set as the revision."
echo " [ --soft-lock-down ]"
echo " All unselected projects with an revision that"
echo " is unset, or 'master', get the current HEAD's sha"
echo " set as the revision."
echo " [ --lock-down-exclude-remotes=<remotes> ]"
echo " [ --lock-down-exclude-projects=<projects> ]"
echo " Exclude from lock-down these additional projects, and"
echo " all projects hosted by these additional remotes."
echo " Lists are comma separated."
echo ""
echo "other options:"
echo " [ --safe-gerrit-host=<host> ]"
echo " allows one to specify host names of gerrit"
echo " servers that are safe to push reviews to."
echo ""
echo "--safe-gerrit-host allows one to specify host names of gerrit servers"
echo "that are safe to push reviews to."
}
TEMP=$(getopt -o h --long remotes:,projects:,tag:,manifest,manifest-file:,manifest-prefix:,lock-down,hard-lock-down,soft-lock-down,default-revision,safe-gerrit-host:,help -n 'create_tags.sh' -- "$@")
TEMP=$(getopt -o h --long remotes:,projects:,tag:,manifest,manifest-file:,manifest-prefix:,lock-down,hard-lock-down,soft-lock-down,default-revision,safe-gerrit-host:,lock-down-exclude-remotes:,lock-down-exclude-projects:,help -n 'create_tags.sh' -- "$@")
if [ $? -ne 0 ]; then
usage
exit 1
@ -56,6 +75,8 @@ LOCK_DOWN=0
SET_DEFAULT_REVISION=0
remotes=""
projects=""
ld_exclude_remotes=""
ld_exclude_projects=""
tag=""
manifest=""
new_manifest=""
@ -68,6 +89,8 @@ while true ; do
-h|--help) HELP=1 ; shift ;;
--remotes) remotes+=$(echo "$2 " | tr ',' ' '); shift 2;;
--projects) projects+=$(echo "$2 " | tr ',' ' '); shift 2;;
--lock-down-exclude-remotes) ld_exclude_remotes+=$(echo "$2 " | tr ',' ' '); shift 2;;
--lock-down-exclude-projects) ld_exclude_projects+=$(echo "$2 " | tr ',' ' '); shift 2;;
--tag) tag=$2; shift 2;;
--manifest) MANIFEST=1 ; shift ;;
--manifest-file) repo_set_manifest_file "$2"; shift 2;;
@ -119,7 +142,7 @@ if [ $MANIFEST -eq 1 ]; then
fi
fi
for project in $projects; do
for project in $projects $ld_exclude_projects; do
if ! repo_is_project $project; then
echo_stderr "Invalid project: $project"
echo_stderr "Valid projects are: $(repo_project_list | tr '\n' ' ')"
@ -127,7 +150,7 @@ for project in $projects; do
fi
done
for remote in $remotes; do
for remote in $remotes $ld_exclude_remotes; do
if ! repo_is_remote $remote; then
echo_stderr "Invalid remote: $remote"
echo_stderr "Valid remotes are: $(repo_remote_list | tr '\n' ' ')"
@ -140,6 +163,10 @@ if [ "$remotes" != "" ]; then
projects+="$(repo_project_list $remotes | tr '\n' ' ')"
fi
if [ "$ld_exclude_remotes" != "" ]; then
ld_exclude_projects+="$(repo_project_list $ld_exclude_remotes | tr '\n' ' ')"
fi
# If no projects or remotes specified, process ALL projects
if [ "$projects" == "" ] && [ "$remotes" == "" ]; then
projects="$(repo_project_list)"
@ -235,7 +262,7 @@ if [ $MANIFEST -eq 1 ]; then
fi
echo "Creating manifest ${new_manifest_name}"
manifest_set_revision "${manifest}" "${new_manifest}" "refs/tags/$tag" ${LOCK_DOWN} ${SET_DEFAULT_REVISION} $projects || exit 1
manifest_set_revision "${manifest}" "${new_manifest}" "refs/tags/$tag" "${LOCK_DOWN}" "${SET_DEFAULT_REVISION}" "${projects// /,}" "${ld_exclude_projects// /,}" || exit 1
echo "Committing ${new_manifest_name} in ${new_manifest_dir}"
git add ${new_manifest_name} || exit 1

View File

@ -195,11 +195,11 @@ manifest_get_revision_of_project () {
manifest_get_default_revision () {
local manifest="${1}"
grep '<default' $manifest |sed -e 's#.*revision=\([^ ]*\).*#\1#' -e 's#"##g' -e "s#'##g"
grep '<default' $manifest |sed -e 's#.*revision=\([^ /]*\).*#\1#' -e 's#"##g' -e "s#'##g"
}
#
# manifest_set_revision <old_manifest> <new_manifest> <revision> <lock_down> <project-list>
# manifest_set_revision <old_manifest> <new_manifest> <revision> <lock_down> <project-list> <excluded_project_list>
#
# old_manifest = Path to original manifest.
# new_manifest = Path to modified manifest. It will not overwrite an
@ -211,9 +211,11 @@ manifest_get_default_revision () {
# projects to equal the SHA of the current git head.
# If 1, similar to 2, but only if the project doesn't have
# some other form of revision specified.
# project-list = A space seperated list of projects. Listed projects
# project-list = A comma seperated list of projects. Listed projects
# will have their revision set to the provided revision
# value.
# excluded_project-list = A comma seperated list of projects. Listed
# projects will not be subject to lock-down.
#
manifest_set_revision () {
local old_manifest="${1}"
@ -221,8 +223,8 @@ manifest_set_revision () {
local revision="${3}"
local lock_down="${4}"
local set_default="${5}"
shift 5
local projects="${@}"
local projects="${6//,/ }"
local ld_exclude_projects="${7//,/ }"
local old_default_revision=""
local repo_root_dir=""
@ -293,21 +295,30 @@ manifest_set_revision () {
fi
done
LD_EXCLUDE_FOUND=0
for project in ${ld_exclude_projects}; do
echo "${line}" | grep -q 'name="'${project}'"'
if [ $? -eq 0 ]; then
LD_EXCLUDE_FOUND=1
break
fi
done
rev=${revision}
old_rev=$(echo "${line}" | grep 'revision=' | sed -e 's#.*revision=\([^ ]*\).*#\1#' -e 's#"##g' -e "s#'##g")
if [ $FOUND -eq 0 ]; then
# A non-selected project
if [ ${lock_down} -eq 2 ]; then
if [ ${lock_down} -eq 2 ] && [ $LD_EXCLUDE_FOUND -eq 0 ]; then
# Hard lock-down
# Set the revision to current HEAD SHA.
path="${repo_root_dir}/$(echo "${line}" | sed 's#.*path="\([^"]*\)".*#\1#')"
rev=$(cd "${path}"; git rev-parse HEAD)
elif [ ${lock_down} -eq 1 ] && [ "${old_rev}" == "" ]; then
elif [ ${lock_down} -eq 1 ] && [ $LD_EXCLUDE_FOUND -eq 0 ] && [ "${old_rev}" == "" ]; then
# Soft lock-down but no revision is currently set on the project.
# Set the revision to current HEAD SHA.
path="${repo_root_dir}/$(echo "${line}" | sed 's#.*path="\([^"]*\)".*#\1#')"
rev=$(cd "${path}"; git rev-parse HEAD)
elif [ ${lock_down} -eq 1 ] && [ "${old_rev}" == "master" ]; then
elif [ ${lock_down} -eq 1 ] && [ $LD_EXCLUDE_FOUND -eq 0 ] && [ "${old_rev}" == "master" ]; then
# Soft lock-down and project has revision set to 'master' which is definitly unstable.
# Set the revision to current HEAD SHA.
path="${repo_root_dir}/$(echo "${line}" | sed 's#.*path="\([^"]*\)".*#\1#')"