d06b9aa763
Update branching and tagging tools, used by patching, to do things the 'repo' way. Repo has replaced wrgit. This is complicated by ... 1) Not all repos are under our control, and so can't be branched or tagged by us. The tools now accepts arguments that list 'remotes' or 'projects' to which branches or tags are to be applied 2) The manifest requires an update to reference the new branch or tag as it applies to affected projects. Non-affected projects can optionally be locked down by converting the revision to a sha. The tools must now try to generate that manifest. It might be sub-optimal. i.e. a revision is explicitly added to each project, rather than using the 'default' mechanism. Perhaps something to address in a future update. ORIGINATING_BRANCH=master ORIGINATING_BUILD=20200220T023000Z NEW_BRANCH=r/stx.4.0 STX_REMOTES="starlingx" repo init -u https://opendev.org/starlingx/manifest -b $ORIGINATING_BRANCH repo sync --force-sync curl http://mirror.starlingx.cengn.ca/mirror/starlingx/${ORIGINATING_BRANCH}/centos/${ORIGINATING_BUILD}/outputs/CONTEXT.sh > ${ORIGINATING_BUILD}.context source ${ORIGINATING_BUILD}.context create_branches_and_tags.sh --branch=$NEW_BRANCH --remotes=$STX_REMOTES --manifest --lockdown push_branches_tags.sh --branch=$NEW_BRANCH --remotes=$STX_REMOTES --manifest ORIGINATING_BRANCH=r/stx.4.0 ORIGINATING_BUILD=20200220T023000Z NEW_STX_TAG=4.0.0 NEW_GIT_HUB_TAG=stx.4.0.0 STX_REMOTES="starlingx" GIT_HUB_REMOTES="stx-staging" repo init -u https://opendev.org/starlingx/manifest -b $ORIGINATING_BRANCH repo sync --force-sync curl http://mirror.starlingx.cengn.ca/mirror/starlingx/${ORIGINATING_BRANCH}/centos/${ORIGINATING_BUILD}/outputs/CONTEXT.sh > ${ORIGINATING_BUILD}.context source ${ORIGINATING_BUILD}.context TAG=TEST_19.10_PATCH_0000 create_tags.sh --tag=$NEW_STX_TAG --remotes=$STX_REMOTES,$GIT_HUB_REMOTES --manifest --manifest-prefix=stx. --lock-down create_tags.sh --tag=$NEW_GIT_HUB_TAG --remotes=$GIT_HUB_REMOTES push_tags.sh --tag=$NEW_STX_TAG --remotes=$STX_REMOTES push_tags.sh --tag=$NEW_GIT_HUB_TAG --remotes=$STX_REMOTES cd .repo/manifests git mv $TAG-default.xml stx.$TAG.xml vi stx.$TAG.xml # set revision for all stx-staging projects to refs/tags/stx.4.0.0 <project remote="stx-staging" ... revision="refs/tags/stx.4.0.0" . vi stx.$TAG.xml # set default revision <default remote="starlingx" revision="refs/tags/4.0.0"/> # delete 'revision' for all starlingx projects git add stx.$TAG.xml git commit -s --amend # set title to Locked down manifest for StarlingX $TAG git tag -d $TAG git review git tag -s -m "Tag $TAG" $TAG git push gerrit $TAG Change-Id: I5ac0c3e44ffda262edb416e877d46c9036cd6e92 Signed-off-by: Scott Little <scott.little@windriver.com>
230 lines
5.4 KiB
Bash
230 lines
5.4 KiB
Bash
#!/bin/bash
|
|
|
|
#
|
|
# Copyright (c) 2020 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
#
|
|
# A collection of utilities that stradle the divide between
|
|
# between git and repo.
|
|
#
|
|
# These utilites are often the most reliable to use. They will
|
|
# try to get the answer from repo, and will fall back to git
|
|
# of repo isn't providing a satisfactory answer. A prime example
|
|
# is the repo's manifest, which isn't fully managed by repo,
|
|
# but isn't a fully independent git either.
|
|
#
|
|
|
|
|
|
GIT_REPO_UTILS_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )"
|
|
|
|
source ${GIT_REPO_UTILS_DIR}/repo-utils.sh
|
|
source ${GIT_REPO_UTILS_DIR}/git-utils.sh
|
|
|
|
|
|
#
|
|
# git_repo_rel_dir [<dir>]:
|
|
# Return the relative directory of a git within a repo.
|
|
#
|
|
git_repo_rel_dir () {
|
|
local DIR="${1:-${PWD}}"
|
|
|
|
local GIT_DIR=""
|
|
local REPO_DIR=""
|
|
local GIT_RELATIVE_DIR=""
|
|
|
|
GIT_DIR=$(git_root ${DIR})
|
|
REPO_DIR=$(readlink -f $(repo_root ${DIR}))
|
|
GIT_RELATIVE_DIR=${GIT_DIR#${REPO_DIR}/}
|
|
echo ${GIT_RELATIVE_DIR}
|
|
}
|
|
|
|
#
|
|
# git_repo_project [<dir>]:
|
|
# Return the repo 'project' of a git.
|
|
#
|
|
|
|
git_repo_project() {
|
|
local DIR="${1:-${PWD}}"
|
|
|
|
(
|
|
cd ${DIR}
|
|
|
|
GIT_RELATIVE_DIR=$(git_repo_rel_dir)
|
|
repo forall -c "if [ \$REPO_PATH == ${GIT_RELATIVE_DIR} ]; then echo \$REPO_PROJECT; fi"
|
|
)
|
|
}
|
|
|
|
#
|
|
# git_repo_remote [<dir>]:
|
|
# Return the repo 'remote' of a git.
|
|
#
|
|
|
|
git_repo_remote() {
|
|
local DIR="${1:-${PWD}}"
|
|
|
|
(
|
|
cd ${DIR}
|
|
|
|
GIT_RELATIVE_DIR=$(git_repo_rel_dir)
|
|
repo forall -c "if [ \$REPO_PATH == ${GIT_RELATIVE_DIR} ]; then echo \$REPO_REMOTE; fi"
|
|
)
|
|
}
|
|
|
|
|
|
#
|
|
# git_repo_remote_branch [<dir>]:
|
|
# Return the repo 'remote branch' of a git.
|
|
#
|
|
|
|
git_repo_remote_branch() {
|
|
local DIR="${1:-${PWD}}"
|
|
|
|
(
|
|
cd ${DIR}
|
|
|
|
GIT_RELATIVE_DIR=$(git_repo_rel_dir)
|
|
REF=$(repo forall -c "if [ \$REPO_PATH == ${GIT_RELATIVE_DIR} ]; then echo \$REPO_RREV; fi")
|
|
if git_is_branch ${REF} ; then
|
|
echo ${REF}
|
|
else
|
|
return 1
|
|
fi
|
|
)
|
|
}
|
|
|
|
#
|
|
# git_repo_remote_ref [<dir>]:
|
|
# Return the repo 'remote branch' of a git.
|
|
#
|
|
|
|
git_repo_remote_ref() {
|
|
local DIR="${1:-${PWD}}"
|
|
|
|
(
|
|
cd ${DIR}
|
|
|
|
GIT_RELATIVE_DIR=$(git_repo_rel_dir)
|
|
repo forall -c "if [ \$REPO_PATH == ${GIT_RELATIVE_DIR} ]; then echo \$REPO_RREV; fi"
|
|
)
|
|
}
|
|
|
|
git_repo_remote_url () {
|
|
local remote=""
|
|
remote=$(git_repo_remote) || return 1
|
|
git config remote.$remote.url
|
|
}
|
|
|
|
url_to_host () {
|
|
local URL="${1}"
|
|
|
|
# Strip protocol, path, user/pwd, port
|
|
echo "${URL}" | sed -e 's#^[^:]*://##' -e 's#/.*$##' -e 's#^[^@]*@##' -e 's#:.*$##'
|
|
}
|
|
|
|
host_to_domain () {
|
|
local host="${1}"
|
|
local elements=0
|
|
|
|
elements=$(echo "${host}" | sed 's#[^.]##g' | wc --chars)
|
|
if [ $elements -gt 2 ]; then
|
|
# strip lead element
|
|
echo "${host}" | sed 's#^[^.]*.##'
|
|
else
|
|
echo "${host}"
|
|
fi
|
|
}
|
|
|
|
git_repo_review_method () {
|
|
local DIR="${1:-${PWD}}"
|
|
local GIT_DIR=""
|
|
local remote_url=""
|
|
local review_host=""
|
|
local remote_host=""
|
|
|
|
GIT_DIR=$(git_root ${DIR}) || return 1
|
|
|
|
if [ ! -f ${GIT_DIR}/.gitreview ]; then
|
|
# No .gitreview file
|
|
echo 'default'
|
|
return 0
|
|
fi
|
|
|
|
if ! grep -q '\[gerrit\]' ${GIT_DIR}/.gitreview; then
|
|
# .gitreview file has no gerrit entry
|
|
echo 'default'
|
|
return 0
|
|
fi
|
|
|
|
review_host="$(grep host= ${GIT_DIR}/.gitreview | sed 's#^host=##' | head -n 1)"
|
|
remote_url="$(git_repo_remote_url)" || return 1
|
|
remote_host="$(url_to_host "${remote_url}")"
|
|
if [ "${review_host}" == "{remote_host}" ]; then
|
|
# Will review against same host as we pulled from. All is well
|
|
echo 'gerrit'
|
|
return 0
|
|
else
|
|
review_domain="$(host_to_domain "${review_host}")"
|
|
remote_domain="$(host_to_domain "${remote_host}")"
|
|
if [ "${review_domain}" == "${remote_domain}" ]; then
|
|
# Will review and remote hosts share a commom domain. Close enough
|
|
|
|
echo 'gerrit'
|
|
return 0
|
|
else
|
|
# Domains don't match. Not close enough to say gerrit is safe.
|
|
# Did someone forget to update .gitreview?
|
|
# Are we not pulling from the authoritative source?
|
|
|
|
echo 'default'
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
# Shouldn't get here
|
|
return 1
|
|
}
|
|
|
|
git_repo_review_remote () {
|
|
local method=""
|
|
method=$(git_repo_review_method)
|
|
if [ "${method}" == "gerrit" ]; then
|
|
git config remote.gerrit.url > /dev/null
|
|
if [ $? -ne 0 ]; then
|
|
# Perhaps we need to run git review -s' and try again
|
|
|
|
# echo a blank line into git in case it prompts for a username
|
|
echo | git review -s > /dev/null || return 1
|
|
git config remote.gerrit.url > /dev/null || return 1
|
|
fi
|
|
echo "gerrit"
|
|
else
|
|
git_repo_remote
|
|
fi
|
|
}
|
|
|
|
git_repo_review_url () {
|
|
local DIR="${1:-${PWD}}"
|
|
local GIT_DIR=""
|
|
|
|
GIT_DIR=$(git_root ${DIR})
|
|
|
|
local method=""
|
|
method=$(git_repo_review_method)
|
|
if [ "${method}" == "gerrit" ]; then
|
|
git config remote.gerrit.url
|
|
if [ $? -ne 0 ]; then
|
|
# Perhaps we need to run git review -s' and try again
|
|
|
|
# echo a blank line into git in case it prompts for a username
|
|
echo | git review -s > /dev/null || return 1
|
|
git config remote.gerrit.url || return 1
|
|
fi
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|