tag_release: support branches, add a branch tracking manifest

To make branches easier to use this splits the branch manifest into two:
build-????.xml is now only pins revisions of projects that do not have a
corresponding branch (yet) while release.xml pins all revisions. Unlike
before the script can now be used to tag branched releases.

The step to switch any particular project to a branch is still manual
but that will be a simple future expansion. First this will be migrated
to Go though, this script has hit the limit of sophistication that
should be attempted with mixing XML and bash. ;-)
This commit is contained in:
Michael Marineau 2016-05-15 17:49:43 -07:00
parent f60d2762c2
commit 31a479553b

View File

@ -9,9 +9,19 @@ SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
DEFAULT_MAJOR=${TODAYS_VERSION} DEFAULT_MAJOR=${TODAYS_VERSION}
DEFAULT_MINOR=0 DEFAULT_MINOR=0
DEFAULT_BRANCH=${FLAGS_FALSE}
# Increment $MINOR if we already are on a version from today
CURRENT_VERSION=( ${COREOS_VERSION_ID//./ } ) CURRENT_VERSION=( ${COREOS_VERSION_ID//./ } )
# Detect if we are on a branch or still tracking master.
DEFAULT_MANIFEST=$(readlink "${REPO_MANIFESTS_DIR}/default.xml") \
|| die "Failed to read default manifest link"
if [[ "${DEFAULT_MANIFEST}" != master.xml ]]; then
DEFAULT_MAJOR=${CURRENT_VERSION[0]}
DEFAULT_BRANCH=${FLAGS_TRUE}
fi
# Increment $MINOR if we already made a major release.
if [[ ${DEFAULT_MAJOR} -eq ${CURRENT_VERSION[0]} ]]; then if [[ ${DEFAULT_MAJOR} -eq ${CURRENT_VERSION[0]} ]]; then
DEFAULT_MINOR=$((${CURRENT_VERSION[1]} + 1)) DEFAULT_MINOR=$((${CURRENT_VERSION[1]} + 1))
fi fi
@ -21,6 +31,7 @@ DEFINE_integer minor ${DEFAULT_MINOR} "Branch revision or minor version"
DEFINE_integer patch 0 "Branch patch id, normally 0" DEFINE_integer patch 0 "Branch patch id, normally 0"
DEFINE_string sdk_version "${COREOS_VERSION_ID}" \ DEFINE_string sdk_version "${COREOS_VERSION_ID}" \
"Set the SDK version to use. (current: ${COREOS_SDK_VERSION})" "Set the SDK version to use. (current: ${COREOS_SDK_VERSION})"
DEFINE_boolean branch ${DEFAULT_BRANCH} "Release branch, diverge from master"
DEFINE_boolean push ${FLAGS_FALSE} "Push to public manifest repository." DEFINE_boolean push ${FLAGS_FALSE} "Push to public manifest repository."
DEFINE_string remote "origin" "Remote name or URL to push to." DEFINE_string remote "origin" "Remote name or URL to push to."
@ -29,6 +40,16 @@ FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}" eval set -- "${FLAGS_ARGV}"
switch_to_strict_mode switch_to_strict_mode
# Easy to mix up versions when tagging a branch, so double check.
if [[ ${FLAGS_branch} -eq ${FLAGS_TRUE} ]]; then
if [[ ${FLAGS_major} -ne ${CURRENT_VERSION[0]} ]]; then
die_notrace "Branch major should be ${CURRENT_VERSION[0]}"
fi
if [[ ${FLAGS_minor} -le ${CURRENT_VERSION[1]} ]]; then
die_notrace "Branch minor should be greater than ${CURRENT_VERSION[1]}"
fi
fi
BRANCH_NAME="build-${FLAGS_major}" BRANCH_NAME="build-${FLAGS_major}"
BRANCH_VERSION="${FLAGS_major}.${FLAGS_minor}.${FLAGS_patch}" BRANCH_VERSION="${FLAGS_major}.${FLAGS_minor}.${FLAGS_patch}"
TAG_NAME="v${BRANCH_VERSION}" TAG_NAME="v${BRANCH_VERSION}"
@ -55,24 +76,47 @@ if [[ -n "${OLD_BRANCHES}" ]]; then
git rm -f ${OLD_BRANCHES} git rm -f ${OLD_BRANCHES}
fi fi
repo manifest -o "${BRANCH_NAME}.xml" -r # transitional, now a file but used to be a symlink.
if [[ -L release.xml ]]; then
rm release.xml
fi
# Generate a release manifest with all revisions pinned
repo manifest -o release.xml -r
# double check because repo may not exit with non-zero on failure
[[ -s release.xml ]] || die "repo failed to generate release.xml"
git add release.xml
# Generate a branch manifest, unpinning any branched projects.
# OW! Don't hit me! I'll write this for real in Go soon I swear!
sed -e "s%revision=.*upstream=\"refs/heads/${BRANCH_NAME}\"%revision=\"refs/heads/${BRANCH_NAME}\"%" release.xml > "${BRANCH_NAME}.xml"
git add "${BRANCH_NAME}.xml"
if [[ ${FLAGS_branch} -eq ${FLAGS_TRUE} ]]; then
ln -sf "${BRANCH_NAME}.xml" default.xml
git add default.xml
fi
tee version.txt <<EOF tee version.txt <<EOF
COREOS_VERSION=${BRANCH_VERSION} COREOS_VERSION=${BRANCH_VERSION}
COREOS_VERSION_ID=${BRANCH_VERSION} COREOS_VERSION_ID=${BRANCH_VERSION}
COREOS_BUILD_ID="" COREOS_BUILD_ID=""
COREOS_SDK_VERSION=${FLAGS_sdk_version} COREOS_SDK_VERSION=${FLAGS_sdk_version}
EOF EOF
ln -sf "${BRANCH_NAME}.xml" release.xml git add version.txt
git add "${BRANCH_NAME}.xml" release.xml version.txt
info "Creating ${BRANCH_NAME} and tag ${TAG_NAME}" info "Creating ${BRANCH_NAME} and tag ${TAG_NAME}"
git commit -m "add(${BRANCH_NAME}): Add manifest for ${TAG_NAME}" git commit -m "${BRANCH_NAME}: release ${TAG_NAME}"
git branch -f "${BRANCH_NAME}" git branch -f "${BRANCH_NAME}"
git tag -m "CoreOS ${TAG_NAME}" "${TAG_NAME}" git tag -m "CoreOS ${TAG_NAME}" "${TAG_NAME}"
if [[ ${FLAGS_push} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_push} -eq ${FLAGS_TRUE} ]]; then
git push "${FLAGS_remote}" \ master="HEAD:refs/heads/master"
"HEAD:refs/heads/master" \ if [[ ${FLAGS_branch} -eq ${FLAGS_TRUE} ]]; then
master=""
fi
git push "${FLAGS_remote}" $master \
"refs/heads/${BRANCH_NAME}" \ "refs/heads/${BRANCH_NAME}" \
"refs/tags/${TAG_NAME}" "refs/tags/${TAG_NAME}"
fi fi